Loading ...
Sorry, an error occurred while loading the content.

How to reach lexbuf from parser?

Expand Messages
  • George
    Trying to make a helpful explanation of parsing errors. In my parser.mly I now have: %{ open Lexing;; open Printf;; let report_error message error_starts_at =
    Message 1 of 1 , Nov 30, 2012
    • 0 Attachment
      Trying to make a helpful explanation of parsing errors. In my parser.mly I now have:

      %{
      open Lexing;;
      open Printf;;

      let report_error message error_starts_at =
      printf "%s at %d:%d\n" message error_starts_at.pos_lnum (error_starts_at.pos_cnum-error_starts_at.pos_bol+1)
      ;;
      %}

      %%

      statement:
      ...
      | error CR { report_error "Syntax error" (Parsing.rhs_start_pos 1); [] }

      Is it possible, and if yes, "how?" to obtain a token which caused the error?

      PS. I know about menhir, but this is a class project and I am forced to use ocamlyacc.
    Your message has been successfully submitted and would be delivered to recipients shortly.