2006-01-31

Jjtree, Javacc and Javac.

I created a new branch of Choob today, so we could start work on implementing some form of loopback.

Anyway, Choob's build script includes calling jjtree and javacc to generate some of the ObjectDB parser. Just for fun, I decided to check if a new version had been released, it turns out one was released on the 2nd of January this year; version 4.0.

I upgraded, and ran it. JJTree runs through fine, but there's a problem with the files it generates: they all have the path at the top, like:

/* Generated By:JJTree: Do not edit this line. uk\co\uwcs\choob\support\ObjectDBClauseParserTreeConstants.java */

Note the \u in the above fragment of code.. also notice the / ... /, marking it as a comment.

This \u in a comment is, according to javac, a syntax error, which strikes me as very, very wrong. Some examples:

>sha1sum Test.java
fef20ace9697444325456db03715f4628449ae3c *Test.java

>cat Test.java
// \uwcs

>c:\java\jdk1.6.0\bin\javac.exe Test.java
Test.java:1: illegal unicode escape
// \uwcs
     ^
1 error

>c:\java\jdk1.5.0_06\bin\javac.exe Test.java
Test.java:1: illegal unicode escape
// \uwcs
   ^
1 error


>cp Test.java Test.cpp

>echo int main() { return 0; } >> Test.cpp

>sha1sum Test.cpp
cd994f7c35b84acdb882f5ddc738aeadc1511396 *Test.cpp

>gcc -v 2>&1 | grep version
gcc version 3.4.2 (mingw-special)

>gcc Test.cpp

>cl Test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

Test.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Test.exe
Test.obj

Both c++ compilers are perfectly happy with this code, neither of Sun's javac's are.

Hmm..

Update:

My patch of JavaCC/JJTree 4.0 to make it not break the java compiler on Windows platforms: diff of src/org/javacc/parser/JavaCCGlobals.java, binary (sig).


Commenting is disabled for this post.

Read more of Faux' blog