[antlr-interest] Interating over a list in an AST

Tim Hilgenberg tim.hilgenberg at hewitt.com
Tue Nov 13 12:36:01 PST 2007


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/e09a6174/attachment.html 


More information about the antlr-interest mailing list