[antlr-interest] Re: Handling delimeter separated lists

lgcraymer lgc at mail1.jpl.nasa.gov
Fri Mar 12 14:38:10 PST 2004


Look at the AST generation and tree parser support.  Generally, you want to use the parsing pass to structure a tree and process 
actions from a tree walker, possibly after several tree transformation passes.

--Loring

--- In antlr-interest at yahoogroups.com, Jason <jasonriz at y...> wrote:
> Hello,
> 
> I have a grammar which has multiple instances of
> comma-separated lists of different types.  The upshot
> of this is that I've got several sets of rules which
> look like this:
> 
> foo_list: foo (COMMA foo)*;
> 
> I find these lists much harder to process than their
> LR counterparts.  I'm generally doing something like
> this:
> 
> foo_list
>   returns [List fooInstList]
>   :
> { String fooInst = null; fooInstList = null; } 
> :
>   fooInst = foo[true, null] 
>   {
>     fooInstList = new ArrayList( );
>     fooInstList.add(fooInst);
>   }
>   (EAL_COMMA property[false, fooInstList])*
>   {
>     // Nothing left to do
>   }
> }
> ;
> 
> foo [boolean isFirst, List foobarList] returns [String
> fooInst]
>   {fooInst = null;} 
>   :
>   foo:FOOBAR
>   {
>     String fooInst = foo.getText( );
>     if (!isFirst)
>     {
>       foobarList.add(fooInst);
>     }
>   }
> ;
> 
> This seems to work but it seems less than elegant
> especially in those cases where foo is called from
> productions other than foo_list.  This issue must
> arise pretty frequently in LL grammars.  Does anyone
> have any idioms they'd like to share?  Is there
> something I'm missing?  Thanks in advance.
> 
> -jason  
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Search - Find what you're looking for faster
> http://search.yahoo.com



 
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