[antlr-interest] native rules?

whaefelinger ora.et.labora at web.de
Fri Oct 22 02:19:22 PDT 2004



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

<*> 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