Posted By:
Sinan_Karasu
Posted On:
Tuesday, June 5, 2001 06:32 PM
Let's taje a subset of fortran. Furthermore , let's say the lexer returns a character at a time, eating up the white space.
statement:
D O (DIGIT)+ id EQ num COMMA num
| id EQ expr
| C O N T I N U E
;
This requires large lookahead, so I put a couple
syn. preds.
statement:
(D O (DIGIT)+ id EQ num COMMA num)=> ...
| ( id EQ expr)=> ...
| C O N T I N U E
;
And now we throw the following statement at it:
d o 50 i= j.k (notice that it is a .(period) not a ,(comma))
and get
syntax error : CONTINUE expected.
That is because the parser is out of alternates.
This is because antlr will not quietly let you put a synpred on the last alternative.
Couple of ways to get around is to do micromanagement and use predicates in subclauses. But then the whole syntax gets messy.
Another method is to put an alternate that will never be satisfied(maybe a nonexistant token such as NoSuchToken as the last alternate and say "unclassifiable statement". However it is debatable if this really is an improvement.
Sinan