[antlr-interest] Accessing a return value ...

Anthony Youngman Anthony.Youngman at ECA-International.com
Thu May 27 07:33:50 PDT 2004


I've looked in the manual, and it tells me how to return a value, but
not how to get at that value from the calling rule (at least as far as I
can see ... :-)

My treeparser is as follows:

programst
	:	#(PROGRAM (IDENT)? statement_list END) 
	|	#(SUBROUTINE (IDENT)? (formalargs)? statement_list END) 
	|	#(FUNCTION (IDENT)? (formalargs)? statement_list END) 
	;

deffunst
	: #(DEFFUN IDENT (formalargs)? (CALLING (IDENT |
STRING_LITERAL))? )
	;

formalargs returns [int argcount]
	: #(FORMALARGS (IDENT {argcount++;})+ )


And, as an example, I want the second line of programst to be
	|	#(SUBROUTINE (IDENT)? (formalargs)?
{st.write(argcount);} statement_list END) 
Obviously, I need to initialise it to 0 before formalargs gets called,
so that I've got a valid value to pass to st.write. I think I can get
round it by doing s/(formalargs)?/(formalargs{st.write(0);})/ and
putting an st.write in the formalargs rule, but I need to learn how to
pass results from rules ...

Cheers,
Wol


****************************************************************************

This transmission is intended for the named recipient only. It may contain private and confidential information. If this has come to you in error you must not act on anything disclosed in it, nor must you copy it, modify it, disseminate it in any way, or show it to anyone. Please e-mail the sender to inform us of the transmission error or telephone ECA International immediately and delete the e-mail from your information system.

Telephone numbers for ECA International offices are: Sydney +61 (0)2 8272 5300, Hong Kong + 852 2121 2388, London +44 (0)20 7351 5000 and New York +1 212 582 2333.

****************************************************************************



 
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