[antlr-interest] Problems walking an AST for a method call
chiplastique
jeremyj at imtc.gatech.edu
Mon May 17 14:04:10 PDT 2004
This is my first project using ANTLR, so please forgive me if the
answer to my problem is obvious and my explanation too verbose.
I've written a parser for a very simple scripting language, and am
generating an AST that I can use to evaluate expressions written in
the language. The expressions can include conventional parameterized
function calls, which have a method identifier and an argument list
of arbitrary length (i.e. methodname(a,b,c,d...)).
My parser generates an AST with the arguments as children to the
method identifier. The code from the parser looks something like
this:
method
: i:METHOD_ID^ LPAREN! arglist RPAREN!
;
arglist
: expression(COMMA! expression)*
;
Now in my AST, I want to read the method name, evaluate the list of
argumets and build an array of their values which can be used to
invoke the function. Unfortunatly, I can't seem to determine how to
write an AST rule that can walk this argument list of arbitrary
length and evaluate the arguments to build the array.
In theory, I'd like to do something like this in the AST:
argList returns [Array r]
{
r = null;
}
: argList a=arg
{ r.Add( a);}
| a=arg
{r = new Array; r.Add( a);}
;
Of course, this doesn't work and I understand why. It just
illustrates conceptually what I want to do. I've tried using a (...)*
construct to create such a rule, but I can't seem to access the
returned values inside the (...)*.
Can anyone suggest how I might accomplish this?
Thanks!
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