Hi Soren :) Heh, it's weird. i get no error when i run your grammar with
stmt : variable_decl ';' NEWLINE* | method_call ';' NEWLINE* |
assignment ';' NEWLINE*;
could it be a weird char in your file?
Ter
On Feb 3, 2010, at 5:16 AM, Søren Andersen wrote:
> 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: [email protected](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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.