Examples grammar is regular

advertisement
Examples:
A grammar is regular if and only if γ is a single nonterminal and α is a
single terminal or a single terminal followed by a single nonterminal, that is
a production is of the form
X → a or X → aY,
Where X and Y are nonterminals and a is a terminal.
A regular grammar is any right-linear or left-linear grammar
Right-Linear Grammars
All productions have form:
A→ xB
or
A→ x
x is string of terminals
Left-Linear Grammars
All productions have form:
A→Bx
or
B→ x
x is string of terminals
1.
∑ = {a, b}, V = {S} and P = {S → aS, S → bS, S → Ʌ}
Where Ʌ empty string
2.
∑ = {a, b}, V = {S} and P = {S → aS, S → bS, S → a, S → b}
3.
Example: The grammar with the following productions:
S →aX
X →Sb
S → λ
Is linear but neither right-linear nor left-linear, and thus not a regular
grammar.
Example:
Let us construct an NFA for r = (a|b)*abb.
For subexpressions rl, the first a, we construct the NFA:
Start
a
2
3
State numbers have been chosen for consistency with what follows. For r2
we construct
b
Start
4
5
We can now combine N(r1) and N(r2), using the construction of figure
below to obtain the NFA for r3 = r|r2; this NFA is shown below
a
2

3

Start
6
1

4

5
b
The NFA for r4 = (r3)* is then as shown in below

a
2
3


Start
0
1
6


4
5
b

We construct the NFA for abb as figure below
a
b
8

b
9
10
7
We eventually construct the NFA for (a|b)*abb in figure below

a
2
3



Start
0
1
6


4
5
b

Decomposition of (ab|ba)a*
7
a
8
b
b
9
10
Download