[antlr-interest] Behavior of LA(n) at EOF?

Richard Clark rd_clark at sbcglobal.net
Sat Oct 2 11:04:20 PDT 2004


I'm trying to get the antlr/eclipse bridge working and I've hit a 
glitch. I had to create an adaptor that uses an Eclipse document as an 
input source, and I'm running into an infinite loop in the lexer.

The lexer construct

COMMENT: "//" (~('\n' | '\r'))* EOLN;

generates

match("//");
{
_loop10:
do {
   if ((_tokenSet_0.member(LA(1))) {
     { match(_token_set_0); }
   }
   else {
     break _loop10;
   }
} while (true);

The problem is, if LA(1) returns CharScanner.EOF_CHAR before the 
comment is done (before an EOLN), the member(LA(1)) call returns true 
and the loop repeats forever.

Thus, what is the proper behavior for InputBuffer::LA(int i) when i is 
at or past the end of the file? Should it return EOF_CHAR (in which 
case, what should I do with the loop above) or throw an exception?

  ...Richard (directions: apply forehead to wall. repeat.)



 
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