let rec arrange n stack rtokens = match stack with | top::rest when n <= top -> arrange n rest (RBRACE::rtokens) | _ -> (stack, rtokens)