Greetings!

On Tue, 2010-03-02 at 20:41 +0530, swathy murthy wrote:
> Hi
> 
> I am currently working on a language translation. So, I have created a
> template and the tree grammar. But, the template is not executing. It
> is giving a Null Pointer Exception. I have the following grammars:
...snipped....

If you look closely at the generated t.java file (and thankfully that is
a strength of ANTLR that one can inspect the generated code without
being driven insane, but i shouldn't digress...).

You will see that the generated program_return structure contains the
field `st` and that is what is returned by a call upon `getTemplate()`.

Further in the code for the program rule contains no initialization for
this `st` field! Thus the null pointer exception back in your Main when
you try to print it.

Unlike AST construction, ANTLR can not, by default, set any of the st
values returned by your rules. There is no reasonable implicit template
value.

So when using templates, you really want some form of
     -> {...result here...}
in *every* rule so that you explicitly govern the template generation
and propagation.

change your t.g program to be `program : stat -> {$stat.st} ;` and the
null pointer exception goes away. 

Hope this helps...
   -jbb




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.

Reply via email to