[antlr-interest] ANTLR 2.7.5 problem(?) with #[...] construct

Don Caton dcaton at shorelinesoftware.com
Tue May 3 13:47:28 PDT 2005


You don't need the '#' before the '[', e.g.:

  init = #( [STMT,"STMT"], #( [EXPR,"EXPR"], init ) );

Maybe that's confusing the parser.  But why not just put the action
following the rule, rather than embedding it in the rule?

 #( EXPR initval:value )
 {
    RefTreeNode decl = ...
 };

Unless there's more to your code, the end result is the same and the parser
will have seen the ending paren of the rule, so there's no question that
what follows is action code.

--
Don
 

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bryan Ewbank
> Sent: Tuesday, May 03, 2005 3:37 PM
> To: ANTLR Interest
> Subject: [antlr-interest] ANTLR 2.7.5 problem(?) with #[...] construct
> 
> I have the following in my *.g file:
> 280   #( EXPR initval:value
> 281       {
> 282           RefTreeNode decl = #( #[DECL,"DECL"], #id, #t );
> 283           RefTreeNode init = #( #[ASGN, "="], 
> copyTree(#id), #initval );
> 284           init = #( #[STMT,"STMT"], #( #[EXPR,"EXPR"], init ) );
> 285           decl->setNextSibling( RefAST(init) );
> 286           ## = decl;
> 287       }
> 288    )
> 
> The problem is that the #[EXPR,"EXPR"] is being detected as a 
> hit for the /EXPR/ node in the tree pattern, rather than as a 
> directive to create a new node.
> 
> Any suggestions?
> 




More information about the antlr-interest mailing list