[antlr-interest] lexer problem

Gavin Lambert antlr at mirality.co.nz
Mon Nov 3 11:53:50 PST 2008


At 04:08 4/11/2008, Hendrik Maryns wrote:
 >This looks promising to solve my problem as well (see other
 >threads).
 >Could you explain further what the line
 >    :  (A) => A { $type = A; }
 >does?  I crawled the site for an explanation of "=>" but
 >couldn't find more than "semantic predicate" and "always
 >execute predicate".

It's called a "syntactic predicate".  Basically the fragment in 
parentheses before the => is evaluated as lookahead, and only if 
the entire thing is present does it enter the block to the right 
of the =>.  It's a way of forcing explicit lookahead.

Normally, you want to avoid putting loops (*/+) into the lookahead 
(since they're usually just a waste of time -- but not always), so 
it's more common to inline the rule rather than put it verbatim on 
both sides as above.  But in this case it's a simple sequence rule 
so it should be ok.



More information about the antlr-interest mailing list