| Chomsky type | Grammar type | Most complicated data structure |
|---|---|---|
| 0 / 1 | PS / CS | production dag |
| 2 | CF | production tree |
| 3 | FS | production list |
| 4 | FC | production element |
generate $a^nb^nc^n$ grammar from using
1. Ss -> abc | aSQ
2. bQc -> bbcc
3. cQ -> Qc
This way of doing things is called breadth-first production; computers are better at it than people.
S = N | L, '&', N ;
N = 't' | 'd' | 'h' ;
L = N, ',', L | N ;
Problems
These four groups together are called useless non-terminals.
// A demo grammar for grammar cleaning
S ---> AB|DE
A ---> a
B ---> bC
C ---> c
D ---> dF
E ---> e
F ---> fD
We solve this dilemma by first marking all rules and non-terminals as “Don’t know”. We now go through the grammar of demo and for each rule for which we do know that all its right-hand side members are productive, we mark the rule and the non-terminal it defines as “Productive”.