Anonymous user
Parsing/Shunting-yard algorithm: Difference between revisions
→{{header|OCaml}}: simplifiy implementation slightly by using list instead of queue, functions instead of hashtable
m (Change header from →{{header|XOJO}}: to →{{header|Xojo}}) |
(→{{header|OCaml}}: simplifiy implementation slightly by using list instead of queue, functions instead of hashtable) |
||
Line 2,149:
let
match op with
| "^" -> 4
| "*" -> 3
|
|
|
| _ -> -1;;
; ("-", 2, Left) ]▼
let assoc op =
match op with
| "^" -> Right
let split_while p =
let rec go ls xs =
Line 2,170 ⟶ 2,173:
let rec intercalate sep xs =
match xs with
Line 2,183 ⟶ 2,180:
let shunting_yard
let
match tkns with
| [] -> List.rev
| "("::tkns' -> pusher
| ")"::tkns' ->
let mv, "("::stack' = split_while ((<>) "(") stack in
| t::tkns' when prec
|
let mv, stack' = split_while mv_to_queue
▲ in
▲ pusher tkns' (t::stack')
▲ in pusher tkns [];;
|