1 (*===----------------------------------------------------------------------===
2 * Top-Level parsing and JIT Driver
3 *===----------------------------------------------------------------------===*)
5 (* top ::= definition | external | expression | ';' *)
6 let rec main_loop stream
=
7 match Stream.peek stream
with
10 (* ignore top-level semicolons. *)
11 | Some
(Token.Kwd '
;'
) ->
19 ignore
(Parser.parse_definition stream
);
20 print_endline
"parsed a function definition.";
22 ignore
(Parser.parse_extern stream
);
23 print_endline
"parsed an extern.";
25 (* Evaluate a top-level expression into an anonymous function. *)
26 ignore
(Parser.parse_toplevel stream
);
27 print_endline
"parsed a top-level expr";
28 with Stream.Error s
->
29 (* Skip token for error recovery. *)
33 print_string
"ready> "; flush stdout
;