[antlr-interest] A little problem in actions
Anakreon
p98043 at rainbow.cs.unipi.gr
Tue Dec 30 13:24:49 PST 2003
Terence Parr wrote:
> On Thursday, December 25, 2003, at 07:43 AM, Anakreon wrote:
>
>>Hello all.
>>I'd like to report a little problem which I am facing.
>>
>>Consider this rule in a tree parser:
>>expression
>> :
>> ...rules
>> |! #(EQ_COMP eq_comp1:expression { #eq_comp1 =
>>getDefault(#eq_comp1);}
>>eq_comp2:expression { #eq_comp2 = getDefault(#eq_comp2);
>>//int code = EQ_COMP;
>>#expression = #([EQ_COMP, "="], #eq_comp1, #eq_comp2);
>> ;
>>
>>When the produced parser is compiled, this error apears.
>>========================================================
>>Found 1 semantic error compiling
>>"/home/e/code/java/aspParser/build/src/gr/omadak/leviathan/asp/
>>VbsTree.java"
>>expression_AST = (AST)astFactory.make( (new
>>ASTArray(3)).add(astFactory.create(tmp33_AST,"=")).add(eq_comp1_AST).ad
>>d(eq_comp2_AST));
>>Semantic Error: No applicable overload for the method named "create"
>>was found
>>in type "antlr.ASTFactory". Perhaps you wanted the overloaded version
>>"antlr.collections.AST create(antlr.Token $1, java.lang.String $2);"
>>instead?
>>=========================================================
>>
>>T guess this happens because the EQ_COMP in the action is miss taken
>>as the
>>token EQ_COMP in the matching rule.
>>The problem is easily solved if instead i rewrite the rule:
>>expression
>> :
>> ...rules
>> |! #(EQ_COMP eq_comp1:expression { #eq_comp1 =
>>getDefault(#eq_comp1);}
>>eq_comp2:expression { #eq_comp2 = getDefault(#eq_comp2);
>>int code = EQ_COMP;
>>#expression = #([code, "="], #eq_comp1, #eq_comp2);
>> ;
>>
>>However this is awkward.
>
>
> Yeah, this is because the action translation stuff sees EQ_COMP as
> #EQ_COMP when inside the #(...). Try EQ_COMP.getType() instead, which
> should work.
>
It doesn't.I tried EQ_COMP.getType() and #EQ_COMP.getType() but it fails in both
cases.When dot follows Token code, is treated as an int.
Even if it worked, it would be a hack.
I think that antlr could figure out that is the Token code I am referring to,
since there would be no meaning in a construct like [astObject, label].
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