Left-Regular (Type-3) Grammar Definitions #
This file defines left-regular grammars as a restricted variant of the unrestricted (Type-0) grammar framework. A left-regular grammar is a variant of the Type-3 class in the Chomsky hierarchy, generating exactly the regular languages.
Grammar restriction #
A left-regular grammar restricts every production rule to one of three forms:
A → B a(a nonterminal followed by a terminal)A → a(a single terminal)A → ε(the empty string)
where A, B are nonterminals and a is a terminal symbol.
Main declarations #
LG_rule— A production rule in a left-regular grammar.LG_grammar— A left-regular grammar.LG_transforms— One-step derivation in a left-regular grammar.LG_derives— Reflexive-transitive closure ofLG_transforms.LG_language— The language generated by a left-regular grammar.is_LG— A language is left-regular if it is generated by some left-regular grammar.
References #
- Hopcroft, Motwani, Ullman. Introduction to Automata Theory, Languages, and Computation, 3rd ed. Section 3.3.
Equations
- One or more equations did not get rendered due to their size.
- instDecidableEqLG_rule.decEq (LG_rule.cons a a_1 a_2) (LG_rule.single a_3 a_4) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.cons a a_1 a_2) (LG_rule.epsilon a_3) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.single a a_1) (LG_rule.cons a_2 a_3 a_4) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.single a a_1) (LG_rule.single b b_1) = if h : a = b then h ▸ if h : a_1 = b_1 then h ▸ isTrue ⋯ else isFalse ⋯ else isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.single a a_1) (LG_rule.epsilon a_2) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.epsilon a) (LG_rule.cons a_1 a_2 a_3) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.epsilon a) (LG_rule.single a_1 a_2) = isFalse ⋯
- instDecidableEqLG_rule.decEq (LG_rule.epsilon a) (LG_rule.epsilon b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
A left-regular (Type-3) grammar over terminal alphabet T.
This is a variant of the most restricted class in the Chomsky hierarchy.
Every production has the form A → Ba, A → a, or A → ε.
Instances For
Extract the left-hand-side nonterminal from a left-regular rule.
Equations
- (LG_rule.cons A a a_1).lhs = A
- (LG_rule.single A a).lhs = A
- (LG_rule.epsilon A).lhs = A
Instances For
Convert an LG rule to its output as a list of symbols.
A → Baoutputs[B, a]A → aoutputs[a]A → εoutputs[]
Equations
- (LG_rule.cons A a a_1).output = [symbol.nonterminal a_1, symbol.terminal a]
- (LG_rule.single A a).output = [symbol.terminal a]
- (LG_rule.epsilon A).output = []
Instances For
One step of left-regular grammar derivation.
Rewrites a nonterminal A in context u ++ [A] ++ v according to a rule.
Equations
Instances For
A word (list of terminals) is generated by a left-regular grammar.
Equations
Instances For
The language generated by a left-regular grammar.
Equations
- LG_language g = setOf (LG_generates g)
Instances For
A language is left-regular if it is generated by some left-regular grammar.
Equations
- is_LG L = ∃ (g : LG_grammar T), LG_language g = L