package menhirLib

  1. Overview
  2. Docs

Module InspectionTableInterpreter.MakeSource

This functor is invoked inside the generated parser, in --table mode. It constructs the inspection API on top of the inspection tables described in InspectionTableFormat.

Parameters

module IT : InspectionTableFormat.TABLES with type 'a lr1state = int
module ET : EngineTypes.TABLE with type terminal = int and type nonterminal = int and type semantic_value = Obj.t
module E : sig ... end

Signature

include IncrementalEngine.SYMBOLS with type 'a terminal := 'a IT.terminal with type 'a nonterminal := 'a IT.nonterminal
type 'a symbol =
  1. | T : 'a IT.terminal -> 'a symbol
  2. | N : 'a IT.nonterminal -> 'a symbol

The type 'a symbol represents a terminal or nonterminal symbol. It is the disjoint union of the types 'a terminal and 'a nonterminal.

type xsymbol =
  1. | X : 'a symbol -> xsymbol

The type xsymbol is an existentially quantified version of the type 'a symbol. This type is useful in situations where 'a is not statically known.

Sourcetype item = int * int

An LR(0) item is a pair of a production prod and a valid index i into this production. That is, if the length of rhs prod is n, then i is comprised between 0 and n, inclusive.

The following are total ordering functions.

Sourceval compare_terminals : _ IT.terminal -> _ IT.terminal -> int
Sourceval compare_nonterminals : _ IT.nonterminal -> _ IT.nonterminal -> int
Sourceval compare_symbols : xsymbol -> xsymbol -> int
Sourceval compare_productions : int -> int -> int
Sourceval compare_items : item -> item -> int
Sourceval incoming_symbol : 'a IT.lr1state -> 'a symbol

incoming_symbol s is the incoming symbol of the state s, that is, the symbol that the parser must recognize before (has recognized when) it enters the state s. This function gives access to the semantic value v stored in a stack element Element (s, v, _, _). Indeed, by case analysis on the symbol incoming_symbol s, one discovers the type 'a of the value v.

Sourceval items : _ IT.lr1state -> item list

items s is the set of the LR(0) items in the LR(0) core of the LR(1) state s. This set is not epsilon-closed. This set is presented as a list, in an arbitrary order.

Sourceval lhs : int -> xsymbol

lhs prod is the left-hand side of the production prod. This is always a non-terminal symbol.

Sourceval rhs : int -> xsymbol list

rhs prod is the right-hand side of the production prod. This is a (possibly empty) sequence of (terminal or nonterminal) symbols.

Sourceval nullable : _ IT.nonterminal -> bool

nullable nt tells whether the non-terminal symbol nt is nullable. That is, it is true if and only if this symbol produces the empty word epsilon.

Sourceval first : _ IT.nonterminal -> _ IT.terminal -> bool

first nt t tells whether the FIRST set of the nonterminal symbol nt contains the terminal symbol t. That is, it is true if and only if nt produces a word that begins with t.

Sourceval xfirst : xsymbol -> _ IT.terminal -> bool

xfirst is analogous to first, but expects a first argument of type xsymbol instead of _ terminal.

Sourceval foreach_terminal : (xsymbol -> 'a -> 'a) -> 'a -> 'a

foreach_terminal enumerates the terminal symbols, including error.

Sourceval foreach_terminal_but_error : (xsymbol -> 'a -> 'a) -> 'a -> 'a

foreach_terminal_but_error enumerates the terminal symbols, excluding error.

feed symbol startp semv endp env causes the parser to consume the (terminal or nonterminal) symbol symbol, accompanied with the semantic value semv and with the start and end positions startp and endp. Thus, the automaton makes a transition, and reaches a new state. The stack grows by one cell. This operation is permitted only if the current state (as determined by env) has an outgoing transition labeled with symbol. Otherwise, Invalid_argument _ is raised.