Now in stock!

Tom Copeland's Recent Posts

RSS Feeds

« A new domain specific language book - with JavaCC | Main | Better JJTree Visitors »

A JavaCC/JJTree bug fixed

Paul Cager has been working on various JavaCC and JJTree bugs lately.  Just recently he fixed a rather annoying bug; in JavaCC 4.0, the OUTPUT_DIRECTORY option setting wasn't copied from the .jjt file into the .jj file.  So you'd have a grammar like this:

$ cat foo.jjt 
options {
  OUTPUT_DIRECTORY="foobar";
}
PARSER_BEGIN(Foo)
public class Foo {}
PARSER_END(Foo)
void a() : {} {" a" }

And running JJTree on it would result in an error like this:

$ jjtree foo.jjt 
Java Compiler Compiler Version 4.0 (Tree Builder)
(type "jjtree" with no arguments for help)
Reading from file foo.jjt . . .
File "foobar/Node.java" does not exist.  Will create one.
Exception in thread "main" java.lang.Error: java.io.FileNotFoundException:
foobar/Node.java (No such file or directory)
        at org.javacc.jjtree.NodeFiles.ensure(Unknown Source)
        at org.javacc.jjtree.NodeFiles.ensure(Unknown Source)
        at org.javacc.jjtree.NodeScope.insertOpenNodeCode(Unknown Source)

And if you did create the "foobar" directory and run JJTree again, the "foo.jj" file would be created in the working directory and wouldn't have the OUTPUT_DIRECTORY option.  Booo.  However, with Paul's changes, it now works fine:

$ ~/javacc/bin/jjtree foo.jjt 
Java Compiler Compiler Version 4.1d1 (Tree Builder)
(type "jjtree" with no arguments for help)
Reading from file foo.jjt . . .
Warning: Output directory "foobar" does not exist. Creating the directory.
File "foobar/Node.java" does not exist.  Will create one.
File "foobar/SimpleNode.java" does not exist.  Will create one.
Annotated grammar generated successfully in foobar/foo.jj

And the OUTPUT_DIRECTORY option is preserved:

$ grep OUTPUT_DIRECTORY foobar/foo.jj 
  OUTPUT_DIRECTORY="foobar";

Good stuff!  I think we're getting close to a 4.1 release, which will be nice since it'll have lots of improvements to the Java 1.5 code that JavaCC generates, and it'll be the first official release that's BSD licensed.     Hopefully we can get in a few more bug fixes and then get this release out the door.

And, of course, here's a gratuitous plug for my JavaCC book!

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/512521/22689970

Listed below are links to weblogs that reference A JavaCC/JJTree bug fixed:

Comments

4.1 will be able to generate better Java 1.5 code, but it looks like the source code changes to 1.5 were reverted. I didn't see anything on the forum about this, but I saw it in the CVS commits.

Brian - yup, there was some confusion (mainly on my part, I think) about when we wanted to shift to Java 1.5. We're sticking with 1.4 for now, but we'll keep those patches around and reapply them at some point.

commant genaire un analysaur LEX/SYNTH avec javacc pour le langager ADA2005

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In