[antlr-interest] Newbie questions: How to traverse the AST ...

Gavin Lambert antlr at mirality.co.nz
Mon Jan 1 11:37:25 PST 2007

At 13:59 1/01/2007, Agnisys wrote:
 >NEWLINE :('\r''\n')=> '\r''\n' //DOS
 >     | '\n'                  //UNIX
 >     { newline(); }
 >     ;

FYI, that definition is incorrect -- it's only going to call the 
newline() function if it encounters UNIX-style line breaks, not 
DOS-style line breaks.

You need to enclose the alt-block in an additional set of 
parentheses, so that the action follows a single term, not an 
alt.  Or put the same action on both alts.

Alternatively, you can probably get away with writing it as a 
single alt, like so:
   '\r'? '\n'

More information about the antlr-interest mailing list