- let rec parse_and_print () =
- match Tiger.Lexer.token lexbuf with
- | None ->
- ()
- | Some token ->
- printf "%s\n" (Tiger.Parser.Token.to_string token);
- parse_and_print ()
- in
- parse_and_print ();
+ (match Tiger.Parser.program Tiger.Lexer.token lexbuf with
+ | exception Parsing.Parse_error ->
+ let
+ Lexing.({lex_curr_p = {pos_lnum; pos_bol; pos_cnum; _}; _}) = lexbuf
+ in
+ Printf.printf
+ "Syntax error in file %S, around line: %d, column: %d\n"
+ path_to_program_file pos_lnum (pos_cnum - pos_bol)
+ | program ->
+ print_endline program
+ );