[antlr-interest] Syntactic predicates sanity check

Martin Probst mail at martin-probst.com
Mon Apr 17 01:23:06 PDT 2006


> a: ((T2)* T3)=> (T2)* T3 | b T4;

Did you try without the predicate? I don't think you need one. You'll  
only need predicates to aid the parser in the decision which branch  
of the alternative to take. In your gramar, there is no alternative -  
all that is T2* T3 gets parsed in the same flow - or did you misplace  
the parens? If the rule is supposed to be

a:  ( T2 * T3  ) | ( b T4 );

b: ( T2* T5 ) | T6;

... then you'll need to disambiguate with predicates. Though in many  
cases it's easier to refactor such rules to

aBegin: T2+;

a: aBegin? ( T3 | ( T5 | T6 ) T4 );

Looks a bit scary now, but if you've got real rule names it's  
actually very natural most of the time (e.g. aBegin gets  
"methodDeclStart" or something).

HTH,
Martin

>
> It seems so because there can be an arbitrary number
> of T2s on the input stream.  I just want to verify
> that I'm not missing something because I know that
> there is a performance cost associated with syntactic
> predicates, so I'd like to avoid them when possible.
> Thanks!
>
> -exits
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>



More information about the antlr-interest mailing list