User Tools

Site Tools


compilers:install_linux_bash
Return to Home page

Install Jflex, CUP and Java in Linux Bash Shell

Guide on how to install Java, Jflex and CUP in the Linux operating systems and using bash shell.

Jflex

To install Jflex on Ubuntu linux you can use apt tool, running in the shell the following command:

sudo apt install jflex

Java

The Oracle JDK can be downloaded at the following address https://www.oracle.com/java/technologies/javase-jdk13-downloads.html (at the moment of this guide the recommended version to download is jdk-13.0.2_linux-x64_bin.tar.gz).
Do not use Linux OpenJDK package.

Java installation

To install Java a possible guide is the following:

  • Create a folder into your home directory
    cd
    mkdir -p compilers
    cd compilers
  • Download into the folder the Java installation file jdk-13.0.2_linux-x64_bin.tar.gz
  • Decompress it
    tar xvfz jdk-13.0.2_linux-x64_bin.tar.gz
  • Change the symbolic links of Java programs (i.e., java, javac and jar) to the new installation of java with the following commands:
    cd /usr/bin/
    sudo ln -fs /home/skenz/compilers/jdk-13.0.2/bin/java .
    sudo ln -fs /home/skenz/compilers/jdk-13.0.2/bin/javac .
    sudo ln -fs /home/skenz/compilers/jdk-13.0.2/bin/jar .

CUP

To install CUP follow the following steps:

Download CUP

Download CUP at the following link: Download Cup version 11 (zip) with drawTree option (this version is an improved version w.r.t. normal release)

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

Installation

Execute next instructions:

  • Create in your home directory an installation folder for CUP:
    cd
    mkdir -p compilers
    cd compilers
  • Download the CUP files into the folder:
    wget https://www.skenz.it/repository/compilers/progs/java_cup_v11_draw_tree.zip
  • Decompress CUP files:
    unzip java_cup_v11_draw_tree.zip
  • Enter the CUP directory
    cd java_cup_v11_draw_tree/java_cup
  • Compile CUP:
    javac *.java runtime/*.java ../StdDraw.java

Configure environment variables

Before running CUP, 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):

cd
gedit .bashrc

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

PATH=$PATH:.:/home/skenz/compilers/java_cup_v11_draw_tree/java_cup/
export PATH
CLASSPATH=.:/home/skenz/compilers/java_cup_v11_draw_tree/
export CLASSPATH

Note: to make active the new environment variables you must reopen a new shell. Remember that both $PATH and $CLASSPATH environmental variables have to contain the . (dot) that represents the current directory.

Check installation

To verify that the programs have been installed correctly, open a command prompt (cmd) and enter:

jflex

A graphical window should be opened.

For CUP you can type into the command prompt:

java java_cup.Main

and if it is correctly installed you see nothing in the terminal. To stop it you can press CTRL-c.

The installed CUP version contains also the functionality to draw into the screen the parse tree (this version was made especially for this course). To check this part you can type into the command prompt:

java java_cup.MainDrawTree

and if it is correctly installed you see nothing in the terminal. To stop it you can press CTRL-c.

Complete Check of installation

  1. Download the following code: exClass-2.zip
  2. Decompress in a directory end type in a terminal the following commands
jflex scanner.jflex
java java_cup.MainDrawTree parser.cup
javac *.java
java Main example_expr.txt

Other resources

AUR packet for Arch Linux

For the Arch Linux architecture you need to extract the following archive (i.e., file polito-cup.tgz) and execute the command makepkg -si inside the directory polito-cup, in order to automatically download source codes from the website of the course, compile them, and insert them in a pacman packet, which can be later installed in Arch Linux. The packet also contains some scripts, which are installed within CUP, that automatically configure system variables before executing java commands (i.e., polito-cup, polito-cup-drawTree, polito-cup-javac, polito-cup-java).

Archive download: polito-cup.tgz

(This latter procedure was not verified by the professor. If you found it has some problems, please communicate it to the professor)


If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/compilers/install_linux_bash
/web/htdocs/www.skenz.it/home/data/pages/compilers/install_linux_bash.txt · Last modified: 2024/04/08 22:34 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy