[antlr-interest] common prefix on Parser rules.
jbb at acm.org
jbb at acm.org
Sun Mar 30 16:22:00 PST 2003
>Hello, this is more a grammar design question but antlr related ;)
>
>Look:
>
>Supose I have the next grammar description:
>
>MemberExpresion: new MemberExpression Arguments
>
>NewExpression: new NewExpression | MemberExpression
>
>
>Obviously the new prefix is causing a non-determinism escenario. Any
>suggestion for transforming this description to let antlr generate a
>correct parser?
>
>MemberExpression has others rules too, not just "new MemberExpression
>Arguments".
[I assume that you meant MemberExpression on the lhs of the first rule above]
^^
Note that this is *not* a grammar design question but rather is a
question of how to transform a grammar into proper LL(k) form (for
some finite value of k).
Observe that:
NewExpression: new NewExpression | MemberExpression
is equivalent to (unless there are also other NewExpression rules you
didn't tell us about):
NewExpression: ( new )* MemberExpression
Thus we now have
MemberExpression: new MemberExpression Arguments ;
NewExpression: ( new )* MemberExpression ;
which is the same as
MemberExpression: ( new )+ MemberExpression Arguments ;
NewExpression: MemberExpression ;
You said that there are other MemberExpression rules so this result
may not be of any use to you...
--
-jbb
----------------+----------------------------
John B. Brodie | Email : jbrodie at cs.fit.edu
----------------+----------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list