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!
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.
Posted by: Brian Egge | October 24, 2007 at 08:42 AM
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.
Posted by: tomcopeland | November 21, 2007 at 11:33 AM
commant genaire un analysaur LEX/SYNTH avec javacc pour le langager ADA2005
Posted by: riad triki | April 05, 2008 at 02:53 PM