[antlr-interest] Making common prefixes work

Gavin Lambert antlr at mirality.co.nz
Wed Dec 28 14:28:50 PST 2011


Mere moments ago, I wrote:
 >fragment TOP: 'TOP';
 >HASH
 >   : '#'
 >   ( /* nothing -- just a HASH */
 >   | (TOP) => TOP { $type = TOP; }
 >   | (ANOTHER) => ANOTHER { $type = ANOTHER; } /* eg. */
 >   );

Actually thinking about that some more, you might need to put the 
empty alt at the end of the rule, or use ? outside the parens 
instead.  I don't remember how picky ANTLR is about the order; 
it's been a while since I've written a lexer grammar myself. :)



More information about the antlr-interest mailing list