[antlr-interest] Tree building, first class values, please HELP!

Octavian Nita octavian_nita_2004 at yahoo.com
Thu May 5 08:37:31 PDT 2005


Hello everybody!

I'm trying to put together a Lua->Java translator
and I have a tree building problem. In Lua, functions
are first class values so they can be assigned to vars
just like any other 'normal' value; more than that,
they can also be returned from functions, so an
expression like:

a("Foo-1")("Foo-2");

is correct (provided that the call to a returns a
function that takes one argument, of course).
I'm using the following rules:

protected
fCallSuf : (fCallHelp help) => fCallHelp fCallSuf
           { #fCallSuf = #([FCALL, "FCALL"],
fCallSuf); }
         | fCallHelp
         | tableHelp fCallSuf
         ;
fCall : ( IDENT | (LPAREN! exp RPAREN!) ) fCallSuf
        { #fCall = #([FCALL, "FCALL"], fCall); }
      ;

My problem is that I get the following output:
( FCALL a ( FCALL ( ExpList "Foo-1" )
                  ( ExpList "Foo-2" ) ) )
while what I actually want is something like:

FCALL
|
---FCALL
|  |
|  ---a
|  |
|  ---ExpList
|
|
---ExpList
   |
   ---"Foo-2"

What can I do?
Thanks!



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 


More information about the antlr-interest mailing list