]> git.kianting.info Git - uann/blob - ocaml_yacc/calc.ml
049297dc9d88cebbc2ab7da3539bce2c02f88e49
[uann] / ocaml_yacc / calc.ml
1 (* File calc.ml *)
2 let rec ast_to_string ast = match ast with
3 | Ast.Leaf s -> s
4 | Ast.Node ls -> "[" ^ String.concat " " (List.map ast_to_string ls) ^ "]"
5 ;;
6
7 let _ =
8 try
9 let lexbuf = Lexing.from_channel stdin in
10 while true do
11 let result = Parser.main Lexer.token lexbuf in
12 Printf.printf "%s" (ast_to_string result); print_newline(); flush stdout
13 done
14 with Lexer.Eof ->
15 exit 0
16
17