I've been trying to do the same, and concluded that the current antlr3
package in Ubuntu's repositories doesn't work properly with the Python runtime support. The other Ubuntu package python-antlr
is even more obsolete as it's supposed to work with ANTLR 2. I suggest that you uninstall antlr3
and install ANTLR by hand together with the right Python runtime support.
Since I've just been through this myself, and found that the instructions are a bit scattered around, here's a summary of how to do it.
Uninstall the antlr3 package:
sudo apt-get purge antlr3
Get the complete Java binaries for the latest ANTLR 3.x:
wget http://www.antlr3.org/download/antlr-3.5.tar.gz
Prepare to install the Python runtime:
tar xzf antlr-3.5.tar.gz
cd antlr3-antlr-3.5/runtime/Python
Before you can call the install script, you have to patch the version number to point to what's available online. You can do this by editing ez_setup.py
and changing DEFAULT_VERSION = "0.6c5"
into DEFAULT_VERSION = "0.6c11"
.
Now you should be able to install the Python runtime with:
sudo python setup.py install
To see if it works, try import antlr3
into a Python shell. You shouldn't get any error.
Now, you have to install the corresponding version of ANTLR proper, which is in Java. For this, make sure you have a JVM installed (e.g., sudo apt-get install default-jdk
).
Get the latest ANTLR 3 jar:
wget http://www.antlr3.org/download/antlr-3.5-complete.jar
Permanently add the jar to your classpath (of course, you may move it where you want and adjust the path accordingly):
echo 'export CLASSPATH=~/antlr-3.5-complete.jar:$CLASSPATH' >> ~/.bashrc
Optional, but recommended: add a shell alias to call ANTLR 3:
echo "alias antlr3='java -jar ~/antlr-3.5-complete.jar'" >> ~/.bashrc
That's it! After you reread your .bashrc, see if everything works with antlr3 -version
. You should get a message such as:
ANTLR Parser Generator Version 3.5