This document describes how to install ANTLR (version 4.9.2) in a persistent way so that it does not need to be re-downloaded for each practical session.
Before starting, make sure you know the location of your permanent home
directory.
If needed, refer to your UNIX/Shell course documentation.
You may also consult memoshell.pdf for a reminder of basic shell
commands.
Open a terminal and create a bin directory in your home directory:
mkdir ~/binDownload the file:
antlr-4.9.2-complete.jar
Place it inside:
~/bin
The ANTLR commands are long. It is recommended to define aliases.
You have two options.
Each time you open a terminal, run:
export CLASSPATH=.:~/bin/antlr-4.9.2-complete.jar:$CLASSPATH
alias antlr4='java -Xmx500M -cp "~/bin/antlr-4.9.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
alias grun='java -Xmx500M -cp "~/bin/antlr-4.9.2-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'This makes antlr4 and grun available for the current session only.
To avoid repeating the commands at every session, modify your shell configuration file.
If you are using bash, edit:
~/.bashrc
Add the following lines:
export CLASSPATH=.:~/bin/antlr-4.9.2-complete.jar:$CLASSPATH
alias antlr4='java -Xmx500M -cp "~/bin/antlr-4.9.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
alias grun='java -Xmx500M -cp "~/bin/antlr-4.9.2-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig'Save the file.
If a terminal was already open, reload the configuration:
source ~/.bashrcAfter this, the commands antlr4 and grun will be available
automatically.
To compile a grammar file named Fic.g4, run:
antlr4 Fic.g4
javac Fic*.javaThis generates and compiles the lexer and parser corresponding to the grammar.