Course of Formal Languages and Compilers

Install JFlex e Cup in the Linux environment (bash shell)

Home > Install for Linux operationg systems (bash shell)
Guide to install Java, Jflex and Cup in Linux operationg systems and using bash shell

0 - Indice

1 - Download necessary programs
2 - Java installation
3 - JFlex installation
4 - Cup configuration
5 - Cup DrawTree installation
6 - Configuration
7 - Check installation

1 - Download programs

1.1 - Java

To download J2SE (Java 2 Standard Edition) connect to the Oracle Java Download page (
At the time of writing, the last versione is 7 update 3 (7u3). Click on Download in the JDK column and follow the instructions. Among the various packages, select the one for the Linux operating system, distributed as a compressed file (tar.gz extension).

1.2 - Cup

Download Cup version 10k (tar.gz)
Download Cup version 10k (tar.gz) with drawTree option (recommended)

2 - Java Installation

Install java following the instructions provided by Oracle.

3 - JFlex Installation

To install jflex on Ubuntu linux you can use apt tool, running in the shell the following command:
sudo apt-get install jflex

4 - Cup Installation

Important: do not use apt tool to install Cup, because it does not work correctly.

Simply follow these instructions:
  • Create in your home directory an installation folder for Cup:
    mkdir tooljava
  • Move to the installation folder of Cup:
    cd ~/tooljava
  • Create a folder where Cup will be installed:
    mkdir cup
  • Move the Cup installation file java_cup_v10k.tar.gz into the folder:
    mv java_cup_v10k.tar.gz ~/tooljava/cup
  • Enter the folder:
    cd cup
  • Decompress the installation file:
    tar xvfz java_cup_v10k.tar.gz

5 - Cup DrawTree installation

A modified version of Java CUP allows to graphically represent the derivation tree during the parsing processes. The package can be downloaded HERE as a tar.gz compressed archive.
The installation procedure is pretty much the same of the normal CUP distribution:
  • Decompress the downloaded file in the same folder where Cup was installed:
    cd ~/tooljava tar xvf java_cup_v10k_drawTree.tar.gz
  • Delete the previous Cup installation:
    rm -fr cup
  • Rename the folder:
    mv java_cup_v10k_drawTree cup

A parser with the support for the derivation tree drawing can be generated launching CUP with the command:
java java_cup.MainDrawTree parser.cup

5 - Environment Configuration

Before running the installed programs the Linux Shell environment variables must be configured. This guide refers to the bash shell.
To check the shell you are using, type the following command:
echo $SHELL
To set the environment variables, open in your home directory the file .bashrc (the .bashrc file is executed by the shell each time you open a terminal and usually it is used to configure a shell):
gedit .bashrc

After opening the .bashrc file, add on its top the following lines:
export PATH

Note: to make active the new environment variables you must reopen a new shell.

7 - Check installation

To verify that the programs have been correctly installed, run Jflex from the shell:
A graphical window should be opened.

Launch Cup writing into the shell:
java java_cup/Main
the shell output will be:
Opening files...
Parsing specification from standard input...

Sponsored by,, and by

Policy sui Cookie