[antlr-interest] A little problem in actions

Terence Parr parrt at cs.usfca.edu
Thu Dec 25 12:33:31 PST 2003


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.

Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, http://www.peerscope.com pure link sharing




 

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