[antlr-interest] Syntactic anti-predicates

Steve Bennett stevagewp at gmail.com
Mon Feb 11 18:58:45 PST 2008


Ok, I had another go, and thought this might work:

table_line
 options { k= 2; }:
   table_header_cells
   |((PIPE ~RIGHT_BRACE) => ( table_caption | table_row_separator |
table_data_cells))
   ;

But it doesn't. Table captions parse fine, but as soon as it hits a
row separator, it starts down the table_caption rule, fails, and bails
out entirely.

So I obviously don't get how the lookahead stuff works at all. I would
have thought even a k of 2 is sufficient here: go into table_caption,
look for a pipe, look for a plus - no good? Ok, go, go into
table_row_separator, look for a pipe, look for a hyphen...ok. Perhaps
one of these masses of warnings is trying to tell me something useful:

[13:49:39] warning(205): C:\antlr\mediawiki10.g:292:29: ANTLR could
not analyze this decision in rule table_line; often this is because of
recursive rule references visible from the left edge of alternatives.
ANTLR will re-analyze the decision with a fixed lookahead of k=1.
Consider using "options {k=1;}" for that decision and possibly adding
a syntactic predicate.


Is that saying that k > 1 is out of the question for that rule? I
guess that would explain it?

[I'm asking all this out of curiosity and desire to understand - I
have a working solution for this bit of the grammar]

Steve


More information about the antlr-interest mailing list