Hi Tilman,

The main reason of the NPE is due to a syntax error in your Optimizer.testsuite 
in which you should use "{tree-rule} walks {rule}:" for defining the test 
target (tree grammar's rules). Try to modify "expr:" to "expr walks expr:" in 
your testsuite, and it should work. You can also reference the wiki page for 
the correct syntax.
However, gUnit does need a detection here for preventing the kind of syntax 
error and provide a reminding message. I'll add this fix to the next release.

Also note that there're several errors in your tree grammar, e.g. it should use 
token PLUS instead of ADD, and here are some fixes for the tree grammar:
expr  
: ^(PLUS a=expr b=expr)    -> {$a.text.equals("0")}? $b
                                        -> {$b.text.equals("0")}? $a
                                        -> ^(ADD $a $b)
| ^(MINUS a=expr b=expr)  -> {$b.text.equals("0")}? $a
                                        -> ^(MINUS $a $b)
| ^(MULT a=expr b=expr)    -> {$a.text.equals("0")}? $a
                                        -> {$b.text.equals("0")}? $b
                                        -> {$a.text.equals("1")}? $b
                                        -> {$b.text.equals("1")}? $a
                                        -> ^(MULT $a $b)
| ^(DIV a=expr b=expr)       -> {$a.text.equals("0")}? $a
                                        -> {$b.text.equals("1")}? $a
                                        -> ^(DIV $a $b)
...

Leon

On Thursday, April 02, 2009, at 09:28AM, "Tilman Bender" 
<tben...@stud.hs-heilbronn.de> wrote:
>Hi folks,
>
>Tried to setup a testsuite for my tree grammar. The testsuite can be  
>run (allthough all tests fail) via the normal org.antlr.gunit.Interp  
>command but
>when I try to generate JUnit-Code for it I get an NPE:
>
>  java -cp ../../../target/classes/:$CLASSPATH org.antlr.gunit.Interp - 
>o Optimizer.testsuite
>Exception in thread "main" java.lang.NullPointerException
>       at org.antlr.gunit.JUnitCodeGen.changeFirstCapital(JUnitCodeGen.java: 
>322)
>       at org.antlr.gunit.JUnitCodeGen.genTestRuleMethods(JUnitCodeGen.java: 
>193)
>       at org.antlr.gunit.JUnitCodeGen.compileToBuffer(JUnitCodeGen.java:121)
>       at org.antlr.gunit.JUnitCodeGen.compile(JUnitCodeGen.java:113)
>       at org.antlr.gunit.Interp.main(Interp.java:55)
>
>I am using antlr-3.1.3 and the respective version of antlr3-maven- 
>plugin to do the grammar code-generation and compilation.
> From what I found so far it seems to be that :
>
>- gUnitTestSuite doesnt correctly set the treerule field
>- JUnitCodeGen doesn't check for null in genTestRuleMethods
>
>I attached my grammars so you can reproduce the problem.
>
>NB: If anybody has a neat solution to integrate gunit with maven  
>pleeease answer my prior thread :)
>
>
>
>
>kind regards
>
>Tilman Bender
>Student des Software Engineering
>Hochschule Heilbronn
>tben...@stud.hs-heilbronn.de
>
>
>
>

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 il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to