[antlr-interest] Re: manual AST construction: what am I doing wrong?

Jorge Scandaliaris j_scandaliaris at yahoo.es
Thu Jun 19 06:52:51 PDT 2003


> -----Original Message-----
> From: antlrlist [mailto:antlrlist at yahoo.com]
 
> I just want to confirm that heterogenous ASTs work very well in java
> mode (even if there are some tricks to know, like only modifying ##
> at the ending action of each rule :| ).

Enrique (or somebody that can reply), can you develop the point you
mentioned here, i.e. ...ONLY MODIFYING ## AT THE ENDING ACTION OF EACH
RULE? 

I was already with my grammar half-way done, when I noticed I wasn`t
respecting the trick you mention. Because everything worked I didn't
touched it :), but today I came across one rule where this was causing
trouble. I want to identify why it is a problem and in what conditions,
'cause respecting your "trick" would make me re visit all the grammar,
and doing nothing can explode things up.
One clue I have, is that it might be because the problematic rule is
recursive:
 expression!:
	:	{## = ##(##,#[IMAG_NODE]);// only way I managed to
create 			// manually only one node for a rule. This node
collects the 		// info from sub rule NODES
		primary 
	{	## actions here}
	(	operator primary
	{	##actions here}
	)*
	{	## actions here}
	;

primary
	: some stuff | expression
	;

When I can I put ## actions at the end, but in cases where I have
(...)*, this forces me to create temporary objects to collect the info
from the loop, and then I have to pass it to ##. Using ## directly saves
me from this, and as I said above, it works OK in many rules.

Cheers,

Jorge



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list