[antlr-interest] Re: newbie question

tsipaggiedad garyf at austinaggies.com
Tue Oct 26 09:32:23 PDT 2004



Cool.. thanks.. the first thing (making it greedy) worked (I tried the
second one a bit, but couldn't get my actions to work out correctly).

At any rate.. now.. I need to figure out how to improve it's speed.  I
assume there is a penalty (that I will have to live with) for
"greedy=true".  However, are there some things I could do to make this
speedier?  On my test platform, I'm only parsing about 15k lines/second.

--- In antlr-interest at yahoogroups.com, Barry Kelly
<barry.j.kelly at g...> wrote:
> I've removed the actions and some of the parentheses to improve
> readability here:
> 
> > class CSVParser extends Parser;
> > options { k=1; }
> > line 
> >        : (record )+ NEWLINE 
> >        | EOF
> >        ;
> > 
> > record
> >        : RECORD (COMMA)?
> >        | COMMA
> >        ;
> 
> You'll see that, when reading in multiple records on a line, there are
> two ways to parse a comma. It could be eaten by
> 
> 1) the first alternative of the record rule, 
> 
> or
> 
> 2) it could be ignored until the next iteration of the (record)+ part
> of the line rule and read as the second alternative of the record
> rule.
> 
> One way to get rid of this is to use options { greedy = true; } just
> before the (COMMA)? part of the record rule. Another way would be to
> rewrite line as something like:
> 
> line 
>        : (RECORD)? (COMMA (RECORD)?)* NEWLINE 
>        | EOF
>        ;
>  
> -- Barry





 
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