Re: predictive parsing



This looks very much like the sort of problem i'd give students in
tutorials, so i have some misgivings...

Your first problem is that you have an ambiguous grammar (at LL(1)) so
you need to fix any productions with a common prefix, so
A -> C | CA | D | DA
becomes
A -> C A1 | D A2
A1 -> A | e
A2 -> A | e

where e means epsilon.
At this point all that is necessary is to do is remove the epsilon
transitions and all will be well.

You could in fact take this grammar all the way through to CNF, but
that's probably excessive...

.