[antlr-interest] [v3] Syntax error leads to a null pointer exception

Loring Craymer lgcraymer at yahoo.com
Wed Aug 16 12:09:00 PDT 2006


At the moment, I would classify this as a "feature":  the syntax error was detected in the parser (first line) which built an incomplete AST as a result; the first treewalker then blew up while walking the AST.  It is better to let errors cascade in early versions; that might make it easier to characterize the error conditions before cleaning up the error reporting later on.  One of the solutions might be to add "resynchronize after error" code to antlr.g--that has always been the dream--so that these failures do not propagate.  However, that will take a bit of work to implement.
   
  --Loring
  

"John B. Brodie" <jbb at acm.org> wrote:
  Greetings!

Hope this isn't a duplicate -- this grammar:

grammar T;

options {
output=AST;
}

@members {
int bar;
}

tokens {
FOO;
}

program
: id+=IDENTIFIER ('.' id+=IDENTIFIER)* -> ^(PATH $id+)
;

IDENTIFIER
: ('a'..'z'|'A'..'Z')+
;

gets this from org.antlr.Tool:

ANTLR Parser Generator Early Access Version 3.0b3 (July 21, 2006) 1989-2006
11:1: syntax error: antlr: t.g:11:1: unexpected token: tokens {
0:0: syntax error: assign.types: :0:0: unexpected end of subtree
0:0: syntax error: define: :0:0: unexpected end of subtree
internal error: t.g : java.lang.NullPointerException
org.antlr.tool.DefineGrammarItemsWalker.trimGrammar(DefineGrammarItemsWalker.java:88)
org.antlr.tool.DefineGrammarItemsWalker.finish(DefineGrammarItemsWalker.java:71)
org.antlr.tool.DefineGrammarItemsWalker.grammar(DefineGrammarItemsWalker.java:192)
org.antlr.tool.Grammar.setGrammarContent(Grammar.java:491)
org.antlr.tool.Grammar.(Grammar.java:409)
org.antlr.Tool.process(Tool.java:246)
org.antlr.Tool.main(Tool.java:70)


So the tokens{} must appear before the @members{}, OK, Not sure why, but OK
(some things in life just are the way they are ;-)

But then why does reporting that syntax error deserve a nullpointer?

-jbb


 		
---------------------------------
Do you Yahoo!?
 Get on board. You're invited to try the new Yahoo! Mail Beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060816/9d620149/attachment.html


More information about the antlr-interest mailing list