[antlr-interest] Tree output syntax
Jim Idle
jimi at temporal-wave.com
Thu Apr 5 10:35:30 PDT 2007
Me too and has done so for the last year. Usually these types of
exceptions come from a small typo somewhere else in the grammar (error
reporting will improve once ANTLR3 is using itself to parse the grammar
files etc - it is a bit raw right now, everyone knows that and it is on
Ter's huge list of things to improve.
So, I suspect that you have to do a 'binary chop' through the grammar,
commenting out one rule after another until you work out what it is
actually complaining about.
Things I have found you need to look for are:
Missing '}' on actions
Missing ; sometimes falls over
Incorrect order of things like @init and scopes (though this is a lot
better these days)
And so on. I also find the frequent check-ins to perforce allow me to
work out what typo I added that caused the failure.
Jim
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
Sent: Thursday, April 05, 2007 10:06 AM
To: ANTLR Interest
Subject: Re: [antlr-interest] Tree output syntax
Works for me.
Ter
--------------
/tmp $ java org.antlr.Tool A.g
ANTLR Parser Generator Version 3.0b7 (??, 2007) 1989-2007
error(106): A.g:7:15: reference to undefined rule: propertyDef
error(106): A.g:6:15: reference to undefined rule: fieldDef
error(106): A.g:5:15: reference to undefined rule: classDef
error(105): A.g:7:6: no lexer rule corresponding to token: K_PROP
error(105): A.g:5:6: no lexer rule corresponding to token: K_CLASS
error(105): A.g:6:6: no lexer rule corresponding to token: K_FIELD
/tmp $ cat A.g
grammar A;
options {output=AST;}
declaration
: K_CLASS^ classDef
| K_FIELD^ fieldDef
| K_PROP^ propertyDef
;
On Apr 5, 2007, at 4:41 AM, Gavin Lambert wrote:
> Yesterday, I wrote:
> >I can't quite work out how to do the tree output syntax for an
> >optional case.
> [...]
> >compoundString: STRING (PLUS^ STRING)*;
>
> In fact that syntax as a whole seems to give grief -- for example
> when I try to do this:
>
> declaration
> : K_CLASS^ classDef
> | K_FIELD^ fieldDef
> | K_PROP^ propertyDef
> ;
>
> ANTLR simply spews this out:
>
> error(100): .\Test.g3:0:0: syntax error: assign.types: <AST>:0:0:
> unexpected end of subtree
> error(10): internal error: .\Test.g3 :
> java.lang.ClassCastException: antlr.ASTNULLType
> org.antlr.tool.AssignTokenTypesWalker.block
> (AssignTokenTypesWalker.java:1215)
> org.antlr.tool.AssignTokenTypesWalker.rule
> (AssignTokenTypesWalker.java:1030)
> org.antlr.tool.AssignTokenTypesWalker.rules
> (AssignTokenTypesWalker.java:610)
> org.antlr.tool.AssignTokenTypesWalker.grammarSpec
> (AssignTokenTypesWalker.java:492)
> org.antlr.tool.AssignTokenTypesWalker.grammar
> (AssignTokenTypesWalker.java:363)
> org.antlr.tool.Grammar.setGrammarContent(Grammar.java:533)
> org.antlr.tool.Grammar.<init>(Grammar.java:443)
> org.antlr.Tool.getGrammar(Tool.java:331)
> org.antlr.Tool.process(Tool.java:267)
> org.antlr.Tool.main(Tool.java:70)
>
> (Note in particular that there's no line information for the
> grammar file, which made this *really* hard to track down the first
> time I encountered it).
>
More information about the antlr-interest
mailing list