[antlr-interest] BaseTreeAdaptor.becomeRoot throwsNullPointerException

Alessandro alessnet at gmail.com
Sat Jun 9 03:42:23 PDT 2007


my grammar : http://pastie.textmate.org/68884
input : "var = \r\n"


On 6/8/07, Jim Idle <jimi at temporal-wave.com> wrote:
> Hmm - debatable whether you should get the crash, which I presume is null exception on atom10 after an NVE?

There is an NoViableAltException in atom(). atom() try to recover and returns.
Because the exception was thrown before any initialisation of the
tree, atom() return an null pointer for the tree ...

Perhaps I must to do something about error handling ? :-(
- Hide quoted text -


> However, I suspect that what is happening is that you are generating a default tree or have not covered the case, so you can either 'fix' this or work around it, depending on whether this is really a bug or not by looking for it. We would need to see your grammar to see exactly why it causes this, but for the moment, let's presume that atom10 can somehow be null and you still want to generate a tree, then:
>
> r1: e1=r2 (PLUS e2=r2)
>         -> {$e2 != null}? ^(PLUS e1 e2)
>         -> e1
> ;

> Or something similar, more apropos to your purpose should get you around that.
>
> However it looks a bit suspicious that it is trying to generate a tree on an error, unless this is just cascading up the expression tree and by the time you try to use it... etc.
>
> Jim
>


More information about the antlr-interest mailing list