[antlr-interest] Passing values in tree walker

Mike Jones Mike.Jones at woofumdust.com
Wed Sep 3 21:20:38 PDT 2003


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/ 




More information about the antlr-interest mailing list