[antlr-interest] AST construction problem??
Ric Klaren
klaren at cs.utwente.nl
Mon Aug 4 04:06:06 PDT 2003
On Fri, Aug 01, 2003 at 07:34:34PM -0000, Fan Yang wrote:
> In order to be familiar with AST construction, I did some small tests
> by usning ANTLR 2.7.2. I realized that ANTLR 2.7.2 can't generate code
> (in CPP or Java) correctly, but ANTLR 2.7.1 can. I don't know if I do
> it in a wrong way or ANTLR 2.7.2 has a bug. Would you please point me
> the problem. thanks.
>
> Here is the problem, I modified grammar of exprAST which exists
> in "examples" directory of ANTLR. I use manual tree construction for
> the rule instead of automatic one.
>
> expr! :
> assignExpr EOF!
^- this is the culprit.
> {#expr = #(assignExpr, EOF);}
> ;
Due to the '!' on EOF no AST return is generated (the tmp1_AST) if you
remove the !-operator the rule will work. It will also work if you label
teh EOF and use the label like this:
expr! :
assignExpr e:EOF!
{#expr = #(assignExpr, #e);}
;
In this case the labeling of the EOF overwrites the !-operator. Although it
would be nice if antlr gave a warning in such a case. Giving a warning for
the particular case you constructed could be tricky, but I'll see what I
can do.
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
"Don't call me stupid." "Oh, right. To call you stupid would be an insult
to stupid people. I've known sheep that could outwit you! I've worn
dresses with higher IQs!" --- A Fish Called Wanda
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list