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

Terence Parr parrt at cs.usfca.edu
Thu May 27 07:58:47 PDT 2004


On May 27, 2004, at 7:43 AM, Anthony Youngman wrote:

> But how do I access that value in the programst rule ... that's where I
> want to use it and I haven't got a clue how to get at it ...
>

Hi Anthony,

Just add an action that uses val such as  
{System.out.println("val="+val);} :)

Terence
> Cheers,
> Wol
>
> -----Original Message-----
> From: Ric Klaren [mailto:klaren at cs.utwente.nl]
> Sent: 27 May 2004 15:38
> To: antlr-interest at yahoogroups.com
> Subject: Re: [antlr-interest] Accessing a return value ...
>
> On Thu, May 27, 2004 at 03:33:50PM +0100, Anthony Youngman wrote:
>> 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 ... :-)
>>
>
> programst { int val; } :
>       #(PROGRAM (IDENT)? statement_list END)
>    |  #(SUBROUTINE (IDENT)? (val=formalargs)? statement_list END)
>    |  #(FUNCTION (IDENT)? (val=formalargs)? statement_list END)
>    ;
>
>> deffunst
>> 	: #(DEFFUN IDENT (formalargs)? (CALLING (IDENT |
>> STRING_LITERAL))? )
>> 	;
>>
>> formalargs returns [int argcount]
>> 	: #(FORMALARGS (IDENT {argcount++;})+ )
>
> In C++ you can do:
>
> formalargs returns [int argcount = 0]
>  	: #(FORMALARGS (IDENT {argcount++;})+ )
> 	;
>
> Not 100% sure if java works like that too.
>
> But this might work as well:
>
> formalargs returns [int argcount] { argcount = 0; } :
>    #(FORMALARGS (IDENT {argcount++;})+ )
>    ;
>
> Cheers,
>
> Ric
> --  
> ----- 
> +++++*****************************************************+++++++++
> -------
>     ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755   
> ----
> ----- 
> +++++*****************************************************+++++++++
> -------
>   "I think we better split up."
>   "Good idea. We can do more damage that way."
>   --- Ghostbusters
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
> *********************************************************************** 
> *****
>
> 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
>
>
>
>
>





 
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