[antlr-interest] Labels with multiple alternatives
Joan Pujol
joanpujol at gmail.com
Thu Jul 29 15:48:12 PDT 2004
On Thu, 29 Jul 2004 15:34:59 -0700, Monty Zukowski
<monty at codetransform.com> wrote:
> Do something like this:
>
> a:alias1! {##=#(#a,##);}
Yes but this is only for one alternative, isn't it?
And I want to mange the two alternatives (ilogic and ologic):
exp1: exp2 ( (ilogic|ologic) exp2)*
I have to use conditional code, or there is a faster elegant solution?
Also I have seen that ANTLR says that there are nondeterminism in the
rule because ilogic and ologic starts with a IDENTIFIER. The semantic
predicate don't solve the nondeterminism?
ilogic: {LT(1).getText().equals("i")}?
{LT(1).setType(OPILOGIC);} IDENT ;
ologic: {LT(1).getText().equals("o")}?
{LT(1).setType(OPOLOGIC);} IDENT;
Cheers,
>
> Note that this will overwrite a's firstChild parameter, so if your rule
> had actually returned a tree you will loose everything except the root
> node.
>
> Monty
>
> ANTLR & Java Consultant -- http://www.codetransform.com
> ANSI C/GCC transformation toolkit --
> http://www.codetransform.com/gcc.html
> Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
>
>
>
>
> On Jul 29, 2004, at 3:18 PM, Joan Pujol wrote:
>
> > Hi,
> >
> > I'm doing a compiler for a catalan pseudocode. In catalan "or" is 'o'
> > and "and" is "i".
> >
> > I don't defined "i" and "o" as tokens in the Lexer because then I
> > can't use it as variables.
> > Instead I use two rules in the Parser:
> >
> > ilogic: {LT(1).getText().equals("i")}? {LT(1).setType(OPILOGIC);}
> > IDENT ;
> > ologic: {LT(1).getText().equals("o")}?
> > {LT(1).setType(OPOLOGIC);} IDENT;
> >
> >
> > Then when I use it in the expression rule I have:
> >
> > exp1: exp2 ( (ilogic|ologic) exp2)*
> >
> > And the question is, what is the better method to make the operator
> > (ilogic or ologic) the root.
> >
> > I have seen that you can't use the same label for the two rules, and
> > you can't use the ^ because there are not tokens but rules.
> >
> >
> > --
> > Joan Jesús Pujol Espinar
>
>
> Yahoo! Groups Links
>
>
>
>
>
--
Joan Jesús Pujol Espinar
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list