| Introduction to Automata Theory, Languages, and Computation |
Revised 11/11/01.
S -> 0S1 | 01
S -> AB | CD
A -> aA | ε
B -> bBc | E | cD
C -> aCb | E | aA
D -> cD | ε
E -> bE | b
To understand how this grammar works, observe the following:
Rightmost: S => A1B => A10B => A101B => A101 => 0A101 => 00A101 => 00101
S -> S+S | SS | S* | (S) | 0 | 1 | phi | e
The idea is that these productions for S allow any expression to be, respectively, the sum (union) of two expressions, the concatenation of two expressions, the star of an expression, a parenthesized expression, or one of the four basis cases of expressions: 0, 1, phi, and ε.
S
/ | \
A 1 B
/ | / |
0 A 0 B
/ | / |
0 A 1 B
| |
e e
In the above tree, e stands for ε.
B -> BB | (B) | [B] | ε
ListItem -> <LI> Doc </LI>
S S
/ | / / | \
a S a S b S
/ | \ \ | \ |
a S b S a S e
| | |
e e e
The two leftmost derivations are: S => aS => aaSbS => aabS => aab and S => aSbS => aaSbS => aabS => aab.
The two rightmost derivations are: S => aS => aaSbS => aaSb => aab and S => aSbS => aSb => aaSb => aab.
S -> aS | aTbS | ε
T -> aTbT | ε
The grammar:
E -> E+T | T
T -> TF | F
F -> F* | (E) | 0 | 1 | phi | e