predictive parsing



I am running into an issue with my LL(1) parser
in representing some of the nonterminals.

The problem is this:

suppose that I have the following grammar:

start: A B
A: C | C A | D | D A
B: '*'
C: '!' | '@'
D: 'X' | 'Y'

Where A, B, C, D are nonterminals
that are represented by functions.

The issue arises in representing the following production:
A: C | C A | D | D A

Imagine my initial lookahead token is '!'.
C() would be called and I would get my next
token. How then could I determine if A() should
be called or if the lookahead token applies to B,
where I should return and then call B?

I would also like to generate a syntax error
if the initial lookahead token does not follow
one of the rules of A.

I think this has to do with properly computing
what should be in the FIRST() set.

--
j0mbolar
.



Relevant Pages

  • Re: predictive parsing
    ... suppose that I have the following grammar: ... The issue arises in representing the following production: ... so the parser knows right at the beginning which production to choose. ...
    (comp.compilers)
  • Re: syntax/notation used in describing cs grammar
    ... from one of those productions, ... nonterminal and R is a string of terminals and nonterminals. ... > the grammar of the grammar as it were. ... > is possible and easier to do a semi-parser than a full parser, ...
    (comp.lang.c)