referenceInterpreter.mli 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
open Grammar
open Cst

(* This reference interpreter animates the LR automaton. It uses the
   grammar and automaton descriptions, as provided by [Grammar] and
   [Lr1], as well as the generic LR engine in [MenhirLib.Engine]. *)

(* The first parameter to the interpreter is a Boolean flag that tells
   whether a trace should be produced on the standard error channel. *)

(* The interpreter requires a start symbol, a lexer, and a lexing
   buffer. It either succeeds and produces a concrete syntax tree, or
   fails. *)

val interpret:
  bool ->
  Nonterminal.t ->
  (Lexing.lexbuf -> Terminal.t) ->
  Lexing.lexbuf ->
  cst option

22
(* This variant of the reference interpreter is used internally by us. We use
23
   it to debug [LRijkstra]. It checks that a sentence leads to a syntax error
24 25 26
   in the expected state. It is also used by several of the command line
   options [--interpret-error], [--compile-errors], etc. *)

27 28
type spurious_reduction =
  Lr1.node * Production.index
29 30

type target =
31
  Lr1.node * spurious_reduction list
32 33 34 35 36 37 38 39

type check_error_path_outcome =
  (* Bad: the input was read past its end. *)
| OInputReadPastEnd
  (* Bad: a syntax error occurred before all of the input was read. *)
| OInputNotFullyConsumed
  (* Bad: the parser unexpectedly accepted (part of) this input. *)
| OUnexpectedAccept
40 41 42 43 44 45 46
  (* Good: a syntax error occurred after reading the last input token. We
     report in which state the error took place, as well as a list of spurious
     reductions. A spurious reduction is a non-default reduction that takes
     place after looking at the last input token -- the erroneous token. 
     We note that a spurious reduction can happen only in a non-canonical
     LR automaton. *)
| OK of target
47 48 49 50 51 52

val check_error_path:
  Nonterminal.t ->   (* initial non-terminal symbol *)
  Terminal.t list -> (* input  *)
  check_error_path_outcome