[antlr-interest] NoSuchElementException

Justin Murray jmurray at aerotech.com
Thu Sep 6 06:46:05 PDT 2012


Hi,

 

I'm having an issue when processing my grammar, the tool spits out a
NoSuchElementException:

 

java.util.NoSuchElementException: can't look backwards more than one
token in this stream

                at
org.antlr.runtime.misc.LookaheadStream.LB(LookaheadStream.java:159)

                ...

 

I sometimes get a Null reference exception as well (but can't reproduce
it at the moment). I've reduced my grammar to the following, which will
still reproduce it.

 

 

grammar Test;

 

options

{

                language=C;

}

 

 

// Parser rules

preprocess

                :               (line? NEWLINE_)* line? EOF

                ;

 

line

                :               PP_directive_

                |              SOURCE_LINE_

                ;

 

// Lexer rules

 

PP_directive_

                :               '#define'

                ;

            

NEWLINE_

                :               '\u000D'? '\u000A'

                |              '\u0085'

                |              '\u2028'

                |              '\u2029'

                ;

                

SOURCE_LINE_

                :               ~NEWLINE_+

                ;

 

 

So I have two questions. It seems to me that the tool should never
crash, so is this an ANTLR bug? Secondly, there is clearly a problem
with what I am trying to do here. Is it not possible to capture
everything on a line (that is not a newline) as a token? Does anyone
have a workaround?

 

Thanks,

 

- Justin



More information about the antlr-interest mailing list