Grammar.LRTable (IchorRuntime v0.1.0)

Copy Markdown View Source

The SLR(1) action/goto table shape itself, plus the two lookups every LR-family engine needs at match time -- interpreted (Grammar.LR, Grammar.GLR.Runtime) or compiled (generated Grammar.Native.LR/ .GLR code) alike.

Building a table from a grammar (Grammar.LRTable.Builder.build/1, which needs Desugar/Sets/Automaton) is a dev-time-only concern that stays in ichor proper -- this module holds only what a generated parser (or the interpreted engines) still calls once a table already exists.

Summary

Functions

The current lookahead terminal name at pos in stream, or end_symbol once input is exhausted -- shared by every LR-family engine (Grammar.LR, Grammar.GLR.Runtime, and generated Grammar.Native.LR/.GLR code alike), interpreted or compiled.

The shared "no action applies here" parse error, naming the offending token (or end of input).

Types

action()

@type action() ::
  {:shift, state_id()} | {:reduce, production_id :: non_neg_integer()} | :accept

state_id()

@type state_id() :: non_neg_integer()

t()

@type t() :: %Grammar.LRTable{
  action: %{required(state_id()) => %{required(atom()) => [action()]}},
  end_symbol: atom(),
  goto: %{required(state_id()) => %{required(atom()) => state_id()}},
  productions: %{required(non_neg_integer()) => Grammar.LRTable.Production.t()},
  root: atom(),
  start_state: state_id(),
  start_symbol: atom()
}

Functions

current_terminal(stream, pos, end_symbol)

@spec current_terminal(tuple(), non_neg_integer(), atom()) :: atom()

The current lookahead terminal name at pos in stream, or end_symbol once input is exhausted -- shared by every LR-family engine (Grammar.LR, Grammar.GLR.Runtime, and generated Grammar.Native.LR/.GLR code alike), interpreted or compiled.

unexpected_error(stream, pos)

@spec unexpected_error(tuple(), non_neg_integer()) :: Ichor.Error.t()

The shared "no action applies here" parse error, naming the offending token (or end of input).