[antlr-interest] Re: Another newbie question
derek_kusiak
derek_kusiak at yahoo.com
Sat Dec 4 07:28:42 PST 2004
--- "lgcraymer" <lgc at m...> wrote:
(...)
> ANTLR doesn't do labeled subrules; what you need instead
> is something like command
> { Token f = null; }
> : INTFUNC i:INTEGER // So far so good
(...)
> REALFUNC (e:FLOAT { f = e; } | i:INTEGER { f = i} )
> {
> cout << "result = "
> << realfunc(atof(f->getText().c_str()))
> << endl;
> }
> ;
>
> or have an action for each of the subrule alternatives
> (instead of the single action for both).
Thanks for the tip, Loring. I modified your idea a bit and
ran with it:
protected
integer returns [int value]
: i:INTEGER
{
value = atoi(i->getText().c_str());
}
;
protected
real returns [float value]
: i:INTEGER
{
value = atof(i->getText().c_str());
}
| f:FLOAT
{
value = atof(f->getText().c_str());
}
;
realfunc
{ float f; }
: REALFUNC f=real { realfunc(f); }
;
intfunc
{ int i; }
: INTFUNC i=integer { intfunc(i); }
;
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