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 operating 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
The Java SDK software can be downloaded in the Oracle Java Download page (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
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).
Do not use Linux OpenJDK package.
1.2 - Cup
Download Cup version 11 (zip) with drawTree option (this version is an improved version w.r.t. normal release)
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:
- Move the Cup installation file java_cup_v11_draw_tree.zip into the folder:
mv java_cup_v11_draw_tree.zip ~/tooljava
- Move to the installation folder of Cup:
- Decompress the installation file:
- Enter the CUP installation directory
- Compile CUP:
javac *.java runtime/*.java ../StdDraw.java
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:
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):
After opening the .bashrc file, add on its top the following lines:
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.
7 - Check installation
To verify that the programs have been correctly installed, run Jflex from the shell:
A graphical window should be opened.
For CUP without the draw tree generation you can type into the shell:
and if it is correctly installed you see nothing in the terminal. To stop it you can press CTRL-c.
Instead, to test CUP with the draw tree option you can type in the terminal the following command: