[antlr-interest] Interating over a list in an AST
Jim Idle
jimi at temporal-wave.com
Tue Nov 13 12:46:56 PST 2007
If you just want to print them, then put your action code against the
rule:
^(FUNC type ID (fp=formalParameter { System.out.println($fp.text); } )*
block)
Jim
_____
From: Tim Hilgenberg [mailto:tim.hilgenberg at hewitt.com]
Sent: Tuesday, November 13, 2007 12:36 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Interating over a list in an AST
I'm trying to figure out how to create a "for" loop around an AST node
that has between zero and n children. I'll use the Cminus walker
example.
Suppose I wanted to print out all the formal paramaters in the
"function" definition. How do I get the following logic:
function
: ^(FUNC type ID formalParameter* block)
{
String formalParmString;
for (... interate over "formalParamter*"...) {
formalParameterString = formalParamterString + " "+
$formalParameter.text }
System.out.println("define "+$type.text+" "+$ID.text+"(" +
formalParmString+ ")");}
;
formalParameter
: ^(ARG type ID)
;
_____
The information contained in this e-mail and any accompanying documents
may contain information that is confidential or otherwise protected from
disclosure. If you are not the intended recipient of this message, or if
this message has been addressed to you in error, please immediately
alert the sender by reply e-mail and then delete this message, including
any attachments. Any dissemination, distribution or other use of the
contents of this message by anyone other than the intended recipient is
strictly prohibited. All messages sent to and from this e-mail address
may be monitored as permitted by applicable law and regulations to
ensure compliance with our internal policies and to protect our
business. Emails are not secure and cannot be guaranteed to be error
free as they can be intercepted, amended, lost or destroyed, or contain
viruses. You are deemed to have accepted these risks if you communicate
with us by email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071113/856821aa/attachment.html
More information about the antlr-interest
mailing list