Course of Formal Languages and Compilers

Install JFlex e Cup in the Linux environment


Home > Install for Linux operationg systems
Guide to install Java, Jflex and Cup in Linux operationg systems

0 - Indice

1 - Download necessary programs
2 - Java installation
3 - JFlex installation
4 - Cup configuration
5 - Configuration

1 - Download programs

1.1 - Java

To downaload J2SE (Java 2 Standard Edition) connect to the Oracle Java Download page (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
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 - JFlex

Download JFlex version 1.4.1 (zip)
Download JFlex version 1.4.1 (tar.gz)

1.3 - Cup

Download Cup version 10k (zip)
Download Cup version 10k (tar.gz)

2 - Java Installation

Supposing you have downloaded the file jdk-7u3-linux-x64.tar.gz, move the archive into your home directory and decompress the archive into the same directory:
mv jdk-7u3-linux-x64.tar.gz ~
cd ~
tar xvfz jdk-7u3-linux-x64.tar.gz
The Java environment is now installed in your home directory, i.e. ~/jdk1.7.0_03.

3 - JFlex Installation

  • Create a folder, tooljava in the proposed installation procedure, where installing JFlex and Cup. To create the folder, move to the folder where you want create it:
    cd ~
  • create the folder with the command:
    mkdir tooljava
  • move the JFlex installation file into that folder:
    mv jflex-1.4.1.tar.gz ~/tooljava or mv jflex-1.4.1.zip ~/tooljava
To install JFlex, simply decompress the file jflex-1.4.1.tar.gz or jflex-1.4.1.zip into the directory previously created.
  • Move to the folder:
    cd tooljava
  • For the .tar.gz extension execute the command:
    tar xvfz jflex-1.4.1.tar.gz (x=extract; v=verbose; f=file; z=zipped)
  • otherwise, for the .zip extension, execute:
    unzip jflex-1.4.1.zip

4 - Cup Installation

The Cup installation is similar to the JFlex one.
  • Move to the installation folder of JFlex and 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
  • Execute the installation script:
    ./INSTALL
Note: the installation script is written for the csh shell. If you are using a different shell, follow the instructions in the next section to complete the installation process.

5 - Environment Configuration

Before running the installed programs the Linux Shell environment variables must be configured. This guide refers to the tcsh shell.
In the case you are using a different shell, the shell tcsh can be launched with the command:
./tcsh
Edit a text file called, for example, compilers_environment and add the following lines:
#!/bin/tcsh -f

set path =($path . /home/skenz/jdk1.5.0_05/bin/ /home/skenz/tooljava/jflex-1.4.1/bin/ /home/skenz/tooljava/cup/java_cup/ )
setenv CLASSPATH .:/home/skenz/tooljava/cup

Each time you want run Java, JFlex or CUP it is necessary to setup the environment variables using the command:
source compilers_environment

To verify that the programs have been correctly installed, run Jflex from the sheel:
jflex
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...

6 - 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 JFlex/CUP were installed:
    tar xvfz java_cup_v10k_drawTree.tgz
  • Modify the environment configuration file created in the previous step substituting the CLASSPATH variable with:
    setenv CLASSPATH .:/home/skenz/tooljava/java_cup_v10k_drawTree

The last step is required for avoiding conflicts with the standard CUP installation. A parser with the support for the derivation tree drawing can be generated launching CUP with the command:
java java_cup.MainDrawTree parser.cup

Sponsored by wiki.altervista.org, www.linkorganizer.net, and by www.skenz.it


Policy sui Cookie