[antlr-interest] internal error
Mark Volkmann
r.mark.volkmann at gmail.com
Fri Feb 1 12:28:50 PST 2008
On Feb 1, 2008 1:42 PM, Olivier Lefevre <lefevrol at yahoo.com> wrote:
> The grammar (the sorry abortion of one, rather) and the
> stack trace on the console are attached. Frankly I was
> asking whether it is a bug out of courtesy: when faced
> with invalid input, a tool like ANTLR should definitely
> put a nice message, not blow up.
>
> Regards,
>
> -- O.L.
>
>
> grammar Bug1;
>
> options {
> output = AST;
> }
>
> tokens {
> ARRAY; ITEM;
> }
>
> prog: stat+ ;
>
> stat:
> list NEWLINE -> list
> | NEWLINE ->
I think you don't need the line above if you change NEWLINE the way I
show below.
> ;
>
> list : '['! (elements)? ']'! -> ^(ARRAY elements) ;
You are using AST operators (in this case !) and a tree construction
rewrite rule in the same rule alternative. I thought that wasn't
allowed. I think you want this.
list: '[' elements? ']' -> ^(ARRAY elements?);
or maybe
list: '[' elements ']' -> ^(ARRAY elements);
> elements : item (','! item)* ;
>
> // ints only for now
> item : INT -> ^(ITEM item) ;
Should this be change to the following?
item: INT -> ^(ITEM INT);
> INT: '0'..'9'+ ;
> NEWLINE:'\r'?'\n' ;
Try the following to allow any number of newlines to terminate a statement.
NEWLINE: ('\r'? '\n')+
> WS: (' '|'\t'|'\n'|'\r')+ {skip();} ;
If you want to use newlines as statement terminators then you can't
skip the characters that make them up. Try changing the line above to
this.
WS: (' ' | '\t')+ { skip(); };
> ANTLR Parser Generator Version 3.0.1 (August 13, 2007) 1989-2007
> error(10): internal error: Bug1.g : java.lang.IllegalArgumentException: Can't find template tokenRefBangTrack.st
> org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:485)
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:372)
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:384)
> org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:464)
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:372)
> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:384)
> org.antlr.codegen.CodeGenTreeWalker.getTokenElementST(CodeGenTreeWalker.java:160)
> org.antlr.codegen.CodeGenTreeWalker.atom(CodeGenTreeWalker.java:1992)
> org.antlr.codegen.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1641)
> org.antlr.codegen.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1490)
> org.antlr.codegen.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1252)
> org.antlr.codegen.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1037)
> org.antlr.codegen.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:753)
> org.antlr.codegen.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:544)
> org.antlr.codegen.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:486)
> org.antlr.codegen.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:333)
> org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:406)
> org.antlr.Tool.processGrammar(Tool.java:347)
> org.antlr.Tool.process(Tool.java:268)
> org.antlr.Tool.main(Tool.java:70)
>
>
--
R. Mark Volkmann
Object Computing, Inc.
More information about the antlr-interest
mailing list