[antlr-interest] Is my brain crooked?
Tim Gleason
tgleason at gmail.com
Sun Jun 17 05:26:25 PDT 2007
I think Matt gave me the best solution (for me anyway). Predicates
are the way to go -- I just hadn't made it to chapter 12 :) I found
this the most readable and easiest to implement:
math_expr
: (times_expr times_op) => (times_expr times_op math_expr)
-> ^(BIN_EXPR times_op times_expr math_expr)
| times_expr -> times_expr
;
Thanks for all of your help!
Tim
On 6/17/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On Jun 17, 2007, at 8:41 AM, Diehl, Matthew J wrote:
>
> > I think I saw something like this in the book, but what you could try
> > (if reordering your original grammar and using predicates doesn't work
> > (times_expr times_op)=>), is: (oh yeah, page 188 of the book)
> >
> > math_expr
> > : (times_expr -> times_expr)
> > (
> > times_op me2=math_expr -> ^(BIN_EXPR times_op $math_expr $me2)
> > )?
> > ;
>
> or
>
> math_expr : times_expr (times_op^ math_expr)* ;
>
> except BIN_EXPR must be injected into the times_op. Can do with an
> action.
>
> Ter
>
>
More information about the antlr-interest
mailing list