[antlr-interest] "An Introduction to ANTLR" presentation slides

Monty Zukowski monty at codetransform.com
Wed Feb 27 13:46:54 PST 2008


>  > A syn pred simply specifies the sytnactic context
>  > that must be true
>  > for the parser (or lexer or tree parser) to pass.
>  > I.e., if you see X,
>  > then Y will match:
>  >
>  > a : (X)=> Y
>  >     | ...
>  >     ;
>  >
>
>
> Wait--is that example literal?  In rule a, how could
>  next token X predict Y?  I -had- thought I understood
>  the syntactic predicate.  :(

You're right, that wouldn't work in a parser with a:(X)=>Y;

X could be a prefix of Y.  So if these are lexer rules, then we would
have something like

A: (X)=>Y
   | ...
  ;

fragment X:...;

Y: X Z;

Where X is enough to disambiguate to choose the rule Y.  Likewise in a
parser it could be

a:(X)=>y
 | ...
;

Monty

Monty


More information about the antlr-interest mailing list