[antlr-interest] Problem "debugging" ANTLR error messages.
Søren Andersen
soren.andersen at gmail.com
Wed Feb 3 05:16:51 PST 2010
Hello,
I'm new on this mailing list, so be nice :)
I'm toying with a Java-like language for fun, and I'm having a problem with ANTLR crashing when trying to use it.
Consider the following grammar:
grammar test;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
INT : '0'..'9'+
;
NEWLINE : '\r'? '\n';
class_decl
: 'class' name '{' NEWLINE* method* '}';
method : type name '(' formalArgs? ')' NEWLINE* '{' NEWLINE+ stmt* '}' NEWLINE* ;
formalArgs
: type name (',' type name)*;
type : ID NEWLINE*;
name : ID NEWLINE*;
stmt : variable_decl ';' NEWLINE* | method_call ';' NEWLINE*;
assignment
: name '=' expression;
variable_decl
: type name '=' expression;
creation
: 'new' name '(' arglist? ')' NEWLINE*;
method_call
: recievers name '(' arglist? ')' NEWLINE*;
arglist : expression (',' expression)*;
recievers
: (name '.')* | '(' creation ')' '.' (name '.')* ;
expression
: method_call | creation | name;
This works perfectly, and as expected!
However, change the stmt rule to:
stmt : variable_decl ';' NEWLINE* | method_call ';' NEWLINE* | assignment ';' NEWLINE*;
And suddenly ANTLR says:
[14:14:32] error(10): internal error: Exception test.g:19:64: unexpected char: 0xA0 at org.antlr.grammar.v2.ANTLRLexer.nextToken(ANTLRLexer.java:347): unexpected stream error from parsing test.g
[14:14:32] error(150): grammar file test.g has no rules
[14:14:32] error(100): test.g:0:0: syntax error: assign.types: <AST>:0:0: unexpected end of subtree
[14:14:32] error(100): test.g:0:0: syntax error: define: <AST>:0:0: unexpected end of subtree
I'm having a hard time figuring out why... Any tips? I mean - had the grammar become ambiguous or something, I'd understand - but this looks like ANTLR is crashing?
I'm using ANTLRworks 1.3.1.
Regards,
Søren
More information about the antlr-interest
mailing list