[antlr-interest] Syntactic predicate confusion

Terence Parr parrt at cs.usfca.edu
Thu Feb 12 17:26:15 PST 2004


Hi Chris,

First thing: ANTLR only does the syn pred if the lookahead is 
consistent with that alternative; saves a lot.  Now, the second thing 
is that syn preds are of the form: (alpha) => beta and mean alpha will 
*always* and *completely* predict beta.  Note the "=>" means "implies". 
  In your example,

x : (b d)=>a
    | b
    ;
a : c
    | b d
    ;

you're saying that if you see a "b d" come down the road, match a.  It 
implicitly says that if you see c coming the line, it will *not* 
predict matching rule a.  You need:

x : (a) => a
    | b
    ;

and all will work.  It says "if you see a, it will match" which is 
bizarre, but you must control this backtracking as it can get out of 
hand when done automatically by ANTLR.

Does that makes sense?

Ter

On Feb 12, 2004, at 5:03 PM, Christopher Nebel wrote:

> Apparently I don't quite "get" syntactic predicates.  Does the
> predicate imply that the attached alternative will fire *only* if the
> predicate is true, or it only apply the predicate if the lookahead is
> otherwise ambiguous?  It appears to be the former, which seems lame.
> Here's my situation:
>
> 	x: a | b
> 	a: c | b d
>
> (The real thing is far more complicated, but this is the basic
> problem.)  Naturally, I get an ambiguity warning here -- if it sees the
> stuff predicted by "b", it doesn't know whether to follow x-> a-> b e
> or just x-> b.  So, I put in a predicate:
>
> 	x: (b d)=> a | b
> 	a: c | b d
>
> This doesn't work, however: if I give it something c-like, then it
> can't parse it -- it just completely ignores the a-> c production.  If
> I add a duplicate of x-> a without the predicate, I just get more
> ambiguity warnings.  What to do?  I don't want to break up the "a"
> rule, since the real thing is rather complicated, not to mention
> self-referential.  I suppose I could come up with a syntactic predicate
> for the duplicate x-> a rule, but it's going to be sort of large.
> Suggestions?
>
>
> --Chris Nebel
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com pure link sharing





 
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