uann/ocaml_yacc/calc.ml

18 lines
486 B
OCaml
Raw Normal View History

2024-03-25 00:32:19 +08:00
(* 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