[antlr-interest] How to define multi and div?
=?GB2312?B?0MLC8g==?=
inshua at gmail.com
Mon Dec 12 06:42:12 PST 2005
I see.same structure must in a rule...
Now it works OK.
Thank u very much.
2005/12/11, Bryan Ewbank <ewbank at gmail.com>:
>
> It cannot be *split*, because of the ambiguity. It can be joined into
> one rule, though. Since MULTI and DIV are at the same precedence
> level, you need to build the grammar to accept either one:
>
> mulitdivExpr
> : parenExpr ( ( MULTI^ | DIV^ ) parenExpr )* ;
>
> This says to match a parenExpr, with zero or more following MULTI or
> DIV operation. Perhaps it's easier to see if it's written this
> (equivalent) way:
>
> mulitdivExpr
> : parenExpr // A
> ( MULTI^ parenExpr // * B
> | DIV^ parenExpr // / B
> )*
> ;
>
> Hope this helps,
> - Bryan
>
> On 12/10/05, °p <inshua at gmail.com> wrote:
> > I 'd found this way in samples ,it did not define MULTI and DIV but
> define
> >
> > MULTI_DIV : * | /
> >
> > but in this way , the multi expr and div expr cannot be recognized in
> the
> > parser, in the following step, I should test the text of the AST node to
> > decide how to run the whole expression.
> >
> > A same rule cannot be split ?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051212/633d8667/attachment.html
More information about the antlr-interest
mailing list