Epsilon Elimination for CFGs #
This file computes nullable nonterminals and removes empty productions while preserving the nonempty part of the language.
Main declarations #
Properties of context-free transformations to the empty string
NullableNonTerminal n holds if n can be transformed into the empty string
Equations
Instances For
NullableWord u holds if u can be transformed into the empty string
Equations
Instances For
NullableRelated u v means that v and u are equal up to interspersed nonterminals, each of
which can be transformed to the empty string (i.e. for each additional nonterminal nt,
NullableNonterminal nt holds)
- empty_left
{T : Type uT}
{g : ContextFreeGrammar T}
(u : List (Symbol T g.NT))
(hu : NullableWord u)
: NullableRelated [] u
The empty string is
NullableRelatedto anyw, s.t.,NullableWord w - cons_term
{T : Type uT}
{g : ContextFreeGrammar T}
{u v : List (Symbol T g.NT)}
(huv : NullableRelated u v)
(t : T)
: NullableRelated (Symbol.terminal t :: u) (Symbol.terminal t :: v)
A terminal symbol
tneeds to be matched exactly - cons_nterm_match
{T : Type uT}
{g : ContextFreeGrammar T}
{u v : List (Symbol T g.NT)}
(huv : NullableRelated u v)
(n : g.NT)
: NullableRelated (Symbol.nonterminal n :: u) (Symbol.nonterminal n :: v)
A nonterminal symbol
ncan be matched exactly - cons_nterm_nullable
{T : Type uT}
{g : ContextFreeGrammar T}
{u v : List (Symbol T g.NT)}
(huv : NullableRelated u v)
{n : g.NT}
(hn : NullableNonTerminal n)
: NullableRelated u (Symbol.nonterminal n :: v)
A nonterminal symbol
n, s.t.,NullableNonterminal non the right, need not be matched
Instances For
Check if a symbol is nullable (w.r.t. to set of nullable symbols p), i.e.,
symbol_is_nullable p s only holds if s is a nonterminal and it is in p
Equations
Instances For
A rule is nullable if all output symbols are nullable
Equations
- ContextFreeGrammar.ruleIsNullable p r = decide (∀ s ∈ r.output, ContextFreeGrammar.symbolIsNullable p s = true)
Instances For
Add the input of a rule as a nullable symbol to p if the rule is nullable
Equations
- ContextFreeGrammar.addIfNullable r p = if ContextFreeGrammar.ruleIsNullable p r = true then insert r.input p else p
Instances For
generators g is the set of all nonterminals that appear in the left hand side of rules of g
Equations
Instances For
Single round of fixpoint iteration; adds r.input to the set of nullable symbols if all symbols in
r.output are nullable
Equations
- One or more equations did not get rendered due to their size.
Instances For
Fixpoint iteration computing the set of nullable symbols of g.
Equations
Instances For
Compute the least-fixpoint of add_nullable_iter, i.e., all (and only) nullable symbols
Equations
Instances For
Compute all possible combinations of leaving out nullable nonterminals from u
Equations
- One or more equations did not get rendered due to their size.
- ContextFreeGrammar.nullableCombinations p [] = [[]]
- ContextFreeGrammar.nullableCombinations p (Symbol.terminal t :: s) = List.map (fun (x : List (Symbol T N)) => Symbol.terminal t :: x) (ContextFreeGrammar.nullableCombinations p s)
Instances For
Computes all variations of leaving out nullable symbols (except the empty string) of r
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compute all variations of leaving out nullable symbols (except the empty string) of gs rules
Equations
Instances For
Equations
- g.eliminateEmpty = { NT := g.NT, initial := g.initial, rules := ContextFreeGrammar.removeNullables g.computeNullables }