[antlr-interest] ANTLR never completes when generating certain lexers

A Z asicaddress at gmail.com
Fri Jul 13 07:16:05 PDT 2012


I've been changing a lexer around in an effort to give better error
messages and came across a case where ANTLR fails to terminate. The code
below is the minimum I could find that causes the problem.
  In my working grammar, I have functionally equivalent code working and
that entire grammar generates in about 6 seconds. After the changes, the
ANTLR code generator never completes and eventually the Java VM quits after
using all the system memory. Is there any debugging info ANTLR has that I
should be looking at to fix this? To be clear I'm not looking for what's
wrong with the grammar, just a means to isolate the problem faster. Thanks.

lexer grammar Y;

options
{
  language = C;
}


RULE :
      EscapedIdent
  |   EscapedIdent '(' MacroExpr (',' MacroExpr )* ')'
  ;

fragment EscapedIdent : '\\' (~ ('\r'|' '|'\n'))+ (' ' | '\n' | EOF);
fragment MacroExpr : (MacroSubExpr | ~(',' | '(' | '{' | ')' | '}' | '"'))*;
fragment MacroSubExpr :
    '('
    (
      (
        ~('(' | '{' | '[' | ')')
      | MacroSubExpr
      )+ ')'
    | ')'
    )
  | '{'
    (
      (
        ~('(' | '{' | '[' | '}')
      | MacroSubExpr
      )+ '}'
    | '}'
    );


More information about the antlr-interest mailing list