Right-Regular (Type-3) Grammar Definitions #
This file defines right-regular grammars as a restricted variant of the unrestricted (Type-0) grammar framework. A right-regular grammar is the most restricted class in the Chomsky hierarchy, generating exactly the regular languages.
Grammar restriction #
An unrestricted grammar allows rules of the form α A β → γ where α, β, γ
are arbitrary strings of terminals and nonterminals. A right-regular grammar restricts
every production rule to one of three forms:
A → a B(a terminal followed by a nonterminal)A → a(a single terminal)A → ε(the empty string)
where A, B are nonterminals and a is a terminal symbol.
Main declarations #
RG_rule— A production rule in a right-regular grammar.RG_grammar— A right-regular grammar.RG_transforms— One-step derivation in a right-regular grammar.RG_derives— Reflexive-transitive closure ofRG_transforms.RG_language— The language generated by a right-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.
- instDecidableEqRG_rule.decEq (RG_rule.cons a a_1 a_2) (RG_rule.single a_3 a_4) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.cons a a_1 a_2) (RG_rule.epsilon a_3) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.single a a_1) (RG_rule.cons a_2 a_3 a_4) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.single a a_1) (RG_rule.single b b_1) = if h : a = b then h ▸ if h : a_1 = b_1 then h ▸ isTrue ⋯ else isFalse ⋯ else isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.single a a_1) (RG_rule.epsilon a_2) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.epsilon a) (RG_rule.cons a_1 a_2 a_3) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.epsilon a) (RG_rule.single a_1 a_2) = isFalse ⋯
- instDecidableEqRG_rule.decEq (RG_rule.epsilon a) (RG_rule.epsilon b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
A right-regular (Type-3) grammar over terminal alphabet T.
This is the most restricted class in the Chomsky hierarchy.
Every production has the form A → aB, A → a, or A → ε.
Instances For
Extract the left-hand-side nonterminal from a rule.
Equations
- (RG_rule.cons A a a_1).lhs = A
- (RG_rule.single A a).lhs = A
- (RG_rule.epsilon A).lhs = A
Instances For
Convert an RG rule to its output as a list of symbols.
Equations
- (RG_rule.cons A a a_1).output = [symbol.terminal a, symbol.nonterminal a_1]
- (RG_rule.single A a).output = [symbol.terminal a]
- (RG_rule.epsilon A).output = []
Instances For
One step of right-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 right-regular grammar.
Equations
Instances For
The language generated by a right-regular grammar.
Equations
- RG_language g = setOf (RG_generates g)