[antlr-interest] Hi,what means "=>"?

Geir Ove Skjaervik geiroves at online.no
Thu Dec 8 03:00:24 PST 2005


Hello,
 
=> is the syntax for a Syntactic Predicate. Syntactic Predicates are
used to initiate a Geussing Mode of the parser:
If the current rule you are referring to cannot be resolved with the
lookhead you are using (K=1, K=2 meaning 1 or 2 Tokens lookahead), then
you have two options: Either increase K to more tokens lookahead: 
 
However this slows down the entire parser, or using Syntctic Predicates
to help the the parser to see what will be matched next.
 
Syntactic Predicates MUST be used when the potential lookahead must be
infinite to match the next rule, e.g. A method call with arbitrary
number of parameters.
 
Assuming a keywordless language, the following will not match however
large you set K
 
methodCallOrDeclaration
 : methodCall
 | methodDeclaration 
 
methodCall
 : ID "("  (ID)*  ")" ";"!
 ;
 
methodDeclaration
 : ID "("  (ID)*  ")"  "=" "{"  ... "}" ";"!
 ; 
 
We will get an ambiguity between rule 1 and 2 above in
methodCallOrDeclaration
 
Using a Syntactic Predicate we can make it work:
 
methodCallOrDeclaration
 : (methodCall) => methodCall
 | methodDeclaration 
 ; 
 
Note that the Syntactic Predicate MUST come before the Rule is resolves
the ambiguity for
 
Geir Ove
 
 
 

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of ÐÂÂò
Sent: 8. desember 2005 09:23
To: antlr-interest at antlr.org
Subject: [antlr-interest] Hi,what means "=>"?


I'm learning the samples,in TinyC demo,there is 
 
declaration
 : (variable) => variable
 | function
 ;
 
I found "=>" in the manual.

{...}? 
semantic predicate 

(...)=> 
syntactic predicate 
These 2 sentences are too short to understand.
Can someone tell me about that ~
 
thx.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051208/60ecc300/attachment.html


More information about the antlr-interest mailing list