[antlr-interest] How to resolve ambiguous grammar of property file: example A = B C K = L

Bryan Ewbank ewbank at gmail.com
Thu Apr 14 13:47:25 PDT 2005


I think this works; there was a left-recursion problem in how variable
was defined - it's replaced with a ()? suffix instead.

The weird part is that the value production is recursive - if there
are two more IDENTs in the stream, then recurse to eat one and look
again.

Syntactic predicates, such as "(IDENT IDENT) =>", don't work if there
are single alternatives, which is why /value/ is written with ( ... |
) instead of ( ... )?

   class EquParser extends Parser;
   options { k = 1; buildAST = true; }
   program: ( statement )* ;
   statement: ( variable EQ value )* SEMI ;
   variable: IDENT ( MINUS IDENT )? ;
   value:
       IDENT
       ( ( IDENT IDENT ) => value
       | /* no match - next IDENT will be variable */
       )
   ;

Hope this helps,
- Bryan


More information about the antlr-interest mailing list