[antlr-interest] Looping forever on some input

Ola Bini ola.bini at gmail.com
Thu Apr 2 01:09:38 PDT 2009


Hi,

I'm having some trouble with the lexer looping forever on input that 
should be possible to disambiguate in limited time. Not exactly sure why 
this happens. It is definitely possible I have done something stupid in 
my grammar, of course.

I've seen eternal looping before, for some constructs. A typical example 
was the input of a single quote, before defining anything that allows a 
single quote. This behavior seems a bit strange, in my opinion, but I 
never figured out why it happened.

The current problem is for input such as "::foo". (without the double 
quotes).

The relevant productions (the only ones that include colon) look like this:
fragment
OperatorChar
    :
       '+'  | '-' | '*' | '%' | '<' 
    |  '>'  | '!' | '?' | '~' | '&' 
    |  '|'  | '^' | '$' | '=' | '@'
    |  '\'' | '`' | ':'
    ;

Identifier
    :
        '[]'
    |   '{}'
    |   (OperatorChar | '/') (OperatorChar | '#' | '/')*
    |   '#' (OperatorChar | '#')+
    |   '.' '.'+
    |   Letter (Letter|IDDigit|':'|'!'|'?'|'$')*
    |   ':' (Letter|IDDigit) (Letter|IDDigit|':'|'!'|'?'|'$')*
    ;

Where Identifier is part of the main production for the parser.

The full grammar can be seen at:
http://github.com/olabini/ioke/raw/9e2795c9c5f2b326c0cbb3dfb456f885b9625ba2/src/grammar/ioke.g 


Cheers

-- 
 Ola Bini (http://olabini.com) 
 Ioke creator (http://ioke.org)
 JRuby Core Developer (http://jruby.org)
 Developer, ThoughtWorks Studios (http://studios.thoughtworks.com)
 Practical JRuby on Rails (http://apress.com/book/view/9781590598818)

 "Yields falsehood when quined" yields falsehood when quined.




More information about the antlr-interest mailing list