LR Parser Semantics #
This file defines the table-driven parser side of LR parsing. It is intentionally
separate from Langlib.Grammars.LR.Definition, which contains the grammar-side
LR(k) predicate.
The definitions here are the parser object that the LR(k)-to-DPDA direction will use: a deterministic action/goto table, stack configurations, and the induced one-step parser transition.
As elsewhere in this development, a context-free rule is a pair
rule : N × List (symbol T N) whose first component rule.1 is the left-hand
nonterminal and whose second component rule.2 is the right-hand output string.
Parser action selected by the current parser state and one lookahead symbol.
The lookahead will be none exactly at end-of-input.
- shift {T N State : Type} (next : State) : Action T N State
- reduce {T N State : Type} (rule : N × List (symbol T N)) : Action T N State
- accept {T N State : Type} : Action T N State
- error {T N State : Type} : Action T N State
Instances For
A parser stack entry stores the grammar symbol and the state reached after placing that symbol on the stack. The top of the stack is the head of the list.
Equations
- LR.Parser.StackEntry T N State = (symbol T N × State)
Instances For
The current parser state: either the state stored at the top of the stack or the parser's initial state when the stack is empty.
Instances For
The grammar symbols stored in the top n parser-stack entries.
Equations
- LR.Parser.topSymbols n stack = List.map Prod.fst (List.take n stack)
Instances For
Perform a reduce action, if the top stack symbols match the rule's right-hand side and the goto table is defined.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One deterministic parser transition, if any.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Relational view of one parser transition.
Instances For
Reflexive-transitive closure of parser steps.
Equations
Instances For
A parser accepts an input word when it reaches an end-of-input configuration
whose action is accept.
Equations
- p.Accepts w = ∃ (c : LR.Parser.Config T N State), p.Reaches (LR.Parser.initialConfig w) c ∧ c.input = [] ∧ p.action (p.stateOfStack c.stack) none = LR.Action.accept
Instances For
The language accepted by a table-driven LR parser.
Instances For
The parser transition is deterministic because it is defined by a function.