Module Info.Lr1Source

LR(1) state information. LR(1) states extend LR(0) cores with lookahead information, determining when reductions should be performed.

include INDEXED with type 'g n = 'g lr1
Sourcetype 'g n = 'g lr1
Sourceval cardinal : 'g grammar -> 'g n Fix.Indexing.cardinal
Sourceval of_int : 'g grammar -> int -> 'g n Fix.Indexing.index

all g is the set of all LR(1) states in grammar g

Sourceval accepting : 'g grammar -> 'g n Utils.Misc.indexset

accepting g is the set of LR(1) accepting states in grammar g. These states are reached after fully recognizing an entrypoint.

Sourceval wait : 'g grammar -> 'g n Utils.Misc.indexset

wait g is the set of "wait" states in grammar g. A wait state is an LR(1) state where the parser must look at more input before deciding how to proceed. Wait states include initial states and targets of shift transitions, excluding accepting states.

to_lr0 g s returns the LR(0) "core" state corresponding to LR(1) state s. Multiple LR(1) states may share the same LR(0) core but differ in lookaheads.

Sourceval incoming : 'g grammar -> 'g n Fix.Indexing.index -> 'g symbol Fix.Indexing.index option

incoming g s returns the symbol that labels the transition into state s. Returns None for initial states. For non-initial states, returns Some sym where sym is the symbol that was parsed to reach this state.

items g s returns the set of LR(0) items in the kernel of state s, i.e., the items before closure is applied.

Sourceval is_entrypoint : 'g grammar -> 'g n Fix.Indexing.index -> 'g production Fix.Indexing.index option

is_entrypoint g s returns Some prod if s is an entrypoint state, where prod is the pseudo (start) production. Returns None otherwise.

Sourceval entrypoints : 'g grammar -> 'g n Utils.Misc.indexset

entrypoints g is the set of LR(1) states that correspond to grammar entrypoints

Sourceval entrypoint_table : 'g grammar -> (string, 'g n Fix.Indexing.index) Stdlib.Hashtbl.t

Hash table mapping entrypoint names to their corresponding LR(1) states

Debug printing functions. Formats are not stable across versions.

Sourceval to_string : 'g grammar -> 'g n Fix.Indexing.index -> string

Converts an LR(1) state to a debug string

Sourceval list_to_string : 'g grammar -> 'g n Fix.Indexing.index list -> string

Converts a list of LR(1) states to a debug string

Sourceval set_to_string : 'g grammar -> 'g n Utils.Misc.indexset -> string

Converts a set of LR(1) states to a debug string

Sourceval symbol_to_string : 'g grammar -> 'g n Fix.Indexing.index -> string

Converts the incoming symbol of a state to a debug string

shift_on g s is the set of terminals that state s can shift on, i.e., terminals for which there is a shift transition from s.

reduce_on g s is the set of terminals that trigger a reduction in state s, i.e., lookahead terminals for which a reduce action is taken.

reject g s is the set of terminals that cause a syntax error in state s, i.e., terminals for which there is no shift, reduce, or default action.

predecessors g s is the lazy stream of LR(1) states that have a transition going to state s. Lazy evaluation avoids materializing all predecessors upfront.

Wrapper around IndexSet.inter speeding-up intersection with all

Sourceval default_reduction : 'g grammar -> 'g n Fix.Indexing.index -> 'g production Fix.Indexing.index option

default_reduction g s returns the default reduction for state s, if any. Some states have a single applicable reduction that can be taken without checking the lookahead terminal.