[antlr-interest] Re: native rules?

lgcraymer lgc at mail1.jpl.nasa.gov
Fri Oct 22 03:02:10 PDT 2004



--- In antlr-interest at yahoogroups.com, "Alexey Demakov" <demakov at i...>
wrote:
> '-' '\n' will be processed incorrectly

True--the alternative needs to be
    '-' ~('-' | '\n' )

--Loring

> 
> Regards,
> Alexey
> 
> > Wolfgang--
> > 
> > Why not
> > 
> > COMMENT
> >     :
> >     "--"
> >     (   ~( '\n' | '-' )
> >     |   '-' ~'-'
> >     )*
> >     ( "--" )?  // NEWLINE or whatever picks up '\n'
> >     ;
> > 
> > The greedy/non-greedy stuff is much overused.
> > 
> > --Loring
> > 
> > 
> > --- In antlr-interest at yahoogroups.com, "whaefelinger"
> > <ora.et.labora at w...> wrote:
> > > 
> > > Hello,
> > > my language allows a comment to start with "--" and end with
ither "-
> > > -" or with an EOL character ('\n'). So I wrote this two rules:
> > > 
> > > protected
> > > UNTIL_END_OF_COMMENT
> > >     : ( options {greedy=false;} : . )* ("--"|"\n")
> > >     ;
> > > 
> > > COMMENT
> > >     : "--" UNTIL_END_OF_COMMENT
> > >     ; 
> > > 
> > > ANTLR warns me then (as  written  in the manual)  about  "nongreedy 
> > > block may exit incorrectly due to limitations of linear approximate 
> > > lookahead [..].
> > > 
> > > Here's a snippet of what ANTLR generates for rule 
> > > UNTIL_END_OF_COMMENT
> > > 
> > >  _loop53:
> > >  do {
> > >    // nongreedy exit test
> > >    if ( (LA(1)=='\n'||LA(1)=='-') && (true)) 
> > >       break _loop53;
> > >    // ...
> > >  } while (true);
> > > 
> > > Hmm, that's almost fine. If I just could rewrite this as 
> > > 
> > >  _loop53:
> > >  do {
> > >    // nongreedy exit test
> > >    if ( LA(1)=='\n' || (LA(1)=='-' && LA(2)=='-') ) 
> > >       break _loop53;
> > >    // ...
> > >  } while (true);
> > > 
> > > then I would be done (BTW: I do have the feeling that I can attack 
> > > the problem with a predicate - but haven't found the right solution 
> > > yet).
> > > 
> > > Now I was wondering whether ANTLR would allow me to tweak in my own 
> > > handcraftet rules? What I'm thinking about is something like:
> > > 
> > > protected UNTIL_END_OF_COMMENT ;
> > > 
> > > That means: If a  protected  rule with no "body" exists then ANTLR 
> > > will not generate a method but will rather assume that such a
method 
> > > already exists.
> > > 
> > > This seems trivial to implement but does not exist. Therefore I 
> > > assume that there must be specific reasons for not having this 
> > > native rule escape. 
> > > 
> > > Can someone give me a hint on this??
> > > 
> > > 
> > > Thanks,
> > > Wolfgang.
> > 
> > 
> > 
> > 
> > 
> >  
> > Yahoo! Groups Links
> > 
> > 
> > 
> >  
> > 
> > 
> >





 
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