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

Tim Hilgenberg tim.hilgenberg at hewitt.com
Wed Nov 14 06:23:45 PST 2007


I'm sorry I wasn't more clear about my question. I wasn't looking to print 
the formal paramaters. I wanted to perform some action on each entry in 
the list. 

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 create a new object based on each entry in the formal 
paramaters list in the "function" 
definition and add it to a list. How do I get the following logic:

function
    :   ^(FUNC type ID formalParameter* block)
       {
        List<SomeObject> formalParmList = new List<SomeObject>;
        for (... interate over "formalParamter*"...) { 
           SomeObject formalParmSomeObject = new 
SomeObject($formalParameter.text);
                formalParmList.add (formalParmSomeObject)
           }

    ;

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


More information about the antlr-interest mailing list