[antlr-interest] empty right hand side

Gavin Lambert antlr at mirality.co.nz
Fri Jun 27 19:06:06 PDT 2008


At 06:32 28/06/2008, Terence Parr wrote:
 >x? is same as (x|).  As a rule, you see:
 >
 >r : x
 >   |
 >   ;
 >
 >Use nothing to represent "nothing" :)

Some people put a comment in for this:

r
   :  x
   |  /* epsilon */
   ;

(Or 'nothing' in place of 'epsilon'.  Depends how formal you're 
feeling!)

Usually though there's no need to have empty alts (because using ? 
is more convenient) -- one exception is where you want to attach 
an action for the case when the first alternative is *not* present.



More information about the antlr-interest mailing list