17 lines
486 B
OCaml
17 lines
486 B
OCaml
(* File calc.ml *)
|
|
let rec ast_to_string ast = match ast with
|
|
| Ast.Leaf s -> s
|
|
| Ast.Node ls -> "[" ^ String.concat " " (List.map ast_to_string ls) ^ "]"
|
|
;;
|
|
|
|
let _ =
|
|
try
|
|
let lexbuf = Lexing.from_channel stdin in
|
|
while true do
|
|
let result = Parser.main Lexer.token lexbuf in
|
|
Printf.printf "%s" (ast_to_string result); print_newline(); flush stdout
|
|
done
|
|
with Lexer.Eof ->
|
|
exit 0
|
|
|
|
|