package menhirGLR

  1. Overview
  2. Docs

Module Make.StateSource

Sourceval n : int

n is the number of states in the LR(1) automaton. We exploit the fact that every state number lies in the semi-open interval [0, n).

Sourceval foreach_shift : state -> token Input.input -> (state -> unit) -> unit

foreach_shift state input enumerates the shift transitions that can be taken, out of the state state, considering the current lookahead symbol, which can be obtained via input. Because an LR automaton is deterministic, there is at most one such transition.

Sourceval foreach_reduction : state -> token Input.input -> (production -> unit) -> unit

foreach_reduction state input enumerates the productions that can be reduced, in the state state, considering the current lookahead symbol, which can be obtained via input. There can be zero, one, or several such reductions. If there is a default reduction then this function does not need to query the input stream input to examine the lookahead symbol.

Sourceval goto : state -> nonterminal -> state

goto state nt returns the target state of the goto transition that leaves the state state and is labeled nt. This transition must exist.

Sourceval unique_action : state -> token Input.input -> [ `Shift of state | `Reduce of production | `Fail | `Fork ]

unique_action offers information that is also accessible (in a less efficient way) through foreach_shift and foreach_reduction.

unique_action state input determines what shift and reduction actions are permitted, in the state state, considering the current lookahead token, which can be obtained via input. If exactly one action is permitted, then a description of this action, `Shift _ or `Reduce _, is returned. If no action is permitted then `Fail is returned. If more than one action is permitted then `Fork is returned.