Cool, it works, thanks!
I don't remember using this {} syntax in rewrite rules before... will
have to re-read your books looking for it.
Edson
2011/2/22 Terence Parr <[email protected]>
> Yo bro! try {$andRule::se1} in the rewrite itself instead of just $se1
> Ter
> On Feb 22, 2011, at 12:48 PM, Edson Tirelli wrote:
>
> > Hi all,
> >
> > Imagine I have an expression grammar that has to deal with the
> following
> > expression:
> >
> > age > 10 && < 20
> >
> > When finding the above input, the grammar has to rewrite that into:
> >
> > age > 10 && age < 20
> >
> > My expression grammar is a typical expression grammar otherwise, but
> for
> > simplification lets imagine it is like this:
> >
> > relationalExpression : operand (operator^ operand)*
> >
> > operand : // will match the "age" token above;
> >
> > operator: // will match operators, like the > and < above;
> >
> > And then I have my "and" rule where I need to use the rewrite:
> >
> > andRule : relationalExpression ( '&&' operator operand )*;
> >
> > I tried the following:
> >
> > andRule :
> > scope { CommonTree se1 = null; }
> > ( relationalExpression -> relationalExpression )
> > ( ( '&&' op=operator se2=operand ) -> ^('&&' $andRule ^( $op $se1 $se2
> )
> > )*;
> >
> > And then setting se1 in the relational expression, but the rewrite rule
> > does not allow me to reference $se1. I am probably over-thinking this,
> but
> > any help would be greatly appreciated. BTW, the "operand" is actually
> > several calls down in the real grammar... above is just a simplified
> > snippet, but the problem is the same.
> >
> > Thanks,
> > Edson
> >
> >
> > --
> > Edson Tirelli
> > JBoss Drools Core Development
> > JBoss by Red Hat @ www.jboss.com
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.