ANTLR to run on Cygwin and GCJ
I've been trying to get ANTLR 2.7.4 to run under Cygwin with GCJ. After trying to piece information together, I've finally found a recipe that makes it work.
For those who don't know ANTLR: it's a replacement for the lex/yacc combination. Unlike YACC, which is a bottom up parser, ANTLR uses a TOP-DOWN parsing approach. There is a lot of information available on the ANTLR website. If you're interested in parser generation, you certainly should have a look. My goal is to write an ANTLR compatible grammar for VHDL.
Back to the topic: ANTLR comes with a standard
Some googling, resulted a link that shows how to work around the error.
I tried this, but probably because some things in my path weren't set correctly (I think), this didn't work very well either. I was able to create a libantlr.so file (see step 4 of that page), but step 5 broke down. Step 5 relies on a file called antlr/Tool.class, which doesn't exist in the ./antlr directory but in the antlr.jar file instead (a jar file is a tar-like library in which .class files can be gathered, I think.)
In the end, I got it to work by un-jarring all the files and simply bypassing the creation of a shared library.
Here's what I did: (basedir is the directory where you can find ./configure)
At this point, we have created that main executable that will convert a .g grammar file into a set of Java, C# or C++ files. These newly generated files, however, rely on base classes that are also part of the ANTLR distribution. For C++, we need to build a library that contains the compiled based classes.
The next step is to test if now have a fully working system.
This is how I got the system work for me while using GCJ and Cygwin. I'm pretty sure that the same procedure will also work in a Solaris or Linux environment...
For those who don't know ANTLR: it's a replacement for the lex/yacc combination. Unlike YACC, which is a bottom up parser, ANTLR uses a TOP-DOWN parsing approach. There is a lot of information available on the ANTLR website. If you're interested in parser generation, you certainly should have a look. My goal is to write an ANTLR compatible grammar for VHDL.
Back to the topic: ANTLR comes with a standard
./configure script. It executes fine, until, during compilation, there is an error related to AWT in directory base/antlr/debug/misc. AWT seems to be a JAVA standard library.Some googling, resulted a link that shows how to work around the error.
I tried this, but probably because some things in my path weren't set correctly (I think), this didn't work very well either. I was able to create a libantlr.so file (see step 4 of that page), but step 5 broke down. Step 5 relies on a file called antlr/Tool.class, which doesn't exist in the ./antlr directory but in the antlr.jar file instead (a jar file is a tar-like library in which .class files can be gathered, I think.)
In the end, I got it to work by un-jarring all the files and simply bypassing the creation of a shared library.
Here's what I did: (basedir is the directory where you can find ./configure)
- Install gcj (through the setup.exe on cygwin.com)
- Download the tar files of the latest version of ANTLR (2.7.4 in my case) and untar it in a local directory.
- Run
./configure --prefix=install dir. While we do not need to configure to compile the antlr executable, we do need it to compile the support C++ libraries. Do NOT run make after configure! - Delete AWT dependent code:
cd basedir/antlr/debug
rm -fr misc cd basedir- Un-jar all the files in the antlr.jar, back into their original position.
jar xfv antlr.jar - Compile everything into an executable
gcj --main=antlr.Tool `find antlr -name "*.class"` -o cantlr
If all is well, you will see a bunch of warnings on your screen that, I assume, you can safely ignore. The end result is a file calledcantlr.exe). - Test the executable by running it (
./cantlr). You should see a bunch of lines with program information. - Move this file to a place somewhere in your path (e.g.
/usr/local/bin)
At this point, we have created that main executable that will convert a .g grammar file into a set of Java, C# or C++ files. These newly generated files, however, rely on base classes that are also part of the ANTLR distribution. For C++, we need to build a library that contains the compiled based classes.
cd basedir/lib/cpp- Build the C++ library. This step won't work if you previously didn't run
./configure.make - If everything went fine, then the
./srcdirectory will contain a file calledlibantlr.a. Now install the library and include files to the place that was originally indicated during the./configurestep.make install
The next step is to test if now have a fully working system.
cd basedir/examples/cpp/calc- The standard Makefile will not know where to find the antlr executable. As a work around, just generate all files by manually invoking antlr.
cantlr calc.g
A set of C++ files will now be generated. make- If everything went fine, you will now see a fresh set of executables!
This is how I got the system work for me while using GCJ and Cygwin. I'm pretty sure that the same procedure will also work in a Solaris or Linux environment...

6 Comments:
When I run cantlr.exe, it tells me that it can't find _fcntl64 in cygwin1.dll. I looked with the Microsoft dependency walker, and sure enough, cygwin1.dll has _fcntl but not _fcntl64. I didn't even expect ANTLR to depend on cygwin. I updated cygwin, but with no better results.
This seems like a major anomaly..
@ganga
When you put antlr.jar in %ANT_HOME%\lib directory and run
ant, you get following exception:
java.lang.NoClassDefFoundError: antlr/Tool
But if I put antlr.jar in CLASSPATH before running ant, then everything
works ok.
ok, i can't comment any more intelligent than this except - that i remember lex/yacc
the yet another compiler compiler gave me nightmares in my third year :)
@Ganga
Hope u fixed the problem right now
@Alex
tnx. and how's you?
@Atul Sabnis
haha..i know you're quite intelligent at heart.liked your comment,Atul. and you know i used to bunk comp orgnsn classes..hehe
Have you managed to write a full VHDL grammar and generate a parser out of it?
Hi Nice Blog .ipod battery share the characteristics common to Lithium-based technology found in other devices. Like other rechargeable batteries, these batteries may eventually require replacement.
Post a Comment
<< Home