[antlr-interest] Passing values in tree walker

Mike Jones Mike.Jones at woofumdust.com
Wed Sep 3 22:32:50 PDT 2003


Terence,

I feel stupid!

Ok, so to reference it:

Expr2
{
	int i2;
}
: expr[i2]
;

I tried that and the resulting code fails because it only calls with the
AST parameter.

Any suggestion?

Mike

-----Original Message-----
From: Terence Parr [mailto:parrt at cs.usfca.edu] 
Sent: Wednesday, September 03, 2003 11:06 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Passing values in tree walker

Hi Mike, try

expr[int i] returns [int r] : ... ;

:)

Terence

On Wednesday, September 3, 2003, at 09:20  PM, Mike Jones wrote:

> There is an example tree walker in the documentation that shows how to
> return a value:
>
> class CalcTreeWalker extends TreeParser;
>
> expr returns [int r]
> {
> 	int a,b;
> 	r=0;
> }
> 	:	#(PLUS a=expr b=expr) {r = a+b;}
> 	|	#(STAR a=expr b=expr) {r = a*b;}
> 	|	i:INT		      {r =
> Integer.parseInt(i.getText());}
> 	;
>
> If I wanted to pass a value to expr, how would I do it?
>
> I tried:
>
> Expr (int i) returns [int r]
>
> but this does not appear to be valid syntax. Nothing in the
> documentation says you can do this. Is it possible?
>
> The reason I would like to do it is so I can easily create a list of
> things while recursively processing nodes. Otherwise I have to create
> some kind of global and manage it carefully.
>
> Mike
>
>
>
>
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/
>
>
>
--
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 link sharing, pure-n-simple




 

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




 

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




More information about the antlr-interest mailing list