[antlr-interest] Predicate question

Brad Schick schick at robotbattle.com
Sat May 1 20:28:43 PDT 2004


I am working on a procedural language grammar that allows one 
statement per line. I specify line endings with the rule below.

// The RCURLY lookahead will match but not consume it,
// allowing the RCURLY to terminate the enclosing function
endline
    : (RCURLY) =>  
    | NEWLINE!;

This works fine, but the generate C++ code confuses me. The if 
statement that checks for a match of the first subrule first tests LA
(1) against a tokenset that includes RCURLY along with all tokens 
that can follow it (mostly tokens that could start the next line). 
If this tokenset is matched, the lookehead takes places and checks 
for RCURLY specifically.

What is the purpose of first matching LA(1) to this broad tokenset? 
I'm guessing this might be to reduce the need for the lookahead and 
a possibly exception, but why not just check LA(1) against the first 
token of the predicate?

Thanks, hope this makes sense.




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list