LR(k) Grammars #
This file defines the grammar-side deterministic context-free notion used in
parser theory, as a restriction of the repository's own context-free grammars
(CF_grammar). The key definition is CF_grammar.IsLRk: after a rightmost
derivation step, the reducible handle is uniquely determined by the already-built
sentential prefix and by k terminal lookahead symbols.
This is the grammar-side class intended to match DPDAs. The full equivalence
with is_DCF requires the two standard constructions:
- an LR(k) parser as a DPDA, proving
is_LR → is_DCF; - a deterministic grammar construction from a DPDA, proving
is_DCF → is_LR.
Those constructions are not encoded here yet.
A context-free rule is, in this development, a pair r : g.nt × List (symbol T g.nt)
whose first component r.1 is the left-hand nonterminal and whose second component
r.2 is the right-hand output string.
A rightmost use of a context-free rule r = (input, output).
The rule rewrites an occurrence of r.1 whose suffix contains terminals only.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A single rightmost derivation step in a context-free grammar.
Equations
- g.ProducesRightmost u v = ∃ r ∈ g.rules, CF_grammar.RewritesRightmost r u v
Instances For
Rightmost derivation: reflexive-transitive closure of rightmost production.
Equations
Instances For
The k terminal symbols visible as LR lookahead.
Equations
- CF_grammar.lrLookahead k w = List.take k w
Instances For
Semantic LR(k) condition for a context-free grammar.
If two rightmost derivations reach configurations where one more rightmost step
creates the same sentential prefix, and their remaining terminal suffixes have
the same k-symbol lookahead, then the reducible handle and rule are identical.
The terminal suffixes themselves need not be equal beyond the visible lookahead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
LR lookahead is monotone: a grammar that is LR(k) is also LR(l) for any l ≥ k.