User Tools

Site Tools


compilers:install_linux_bash
Return to Home page

Differences

This shows you the differences between two versions of the page.


compilers:install_linux_bash [2024/04/08 22:34] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== 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:
 +<code bash>
 +sudo apt install jflex
 +</code>
 +
 +==== 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<code bash>
 +cd
 +mkdir -p compilers
 +cd compilers
 +</code>
 +  * Download into the folder the Java installation file ''jdk-13.0.2_linux-x64_bin.tar.gz''
 +  * Decompress it<code bash>
 +tar xvfz jdk-13.0.2_linux-x64_bin.tar.gz
 +</code>
 +  * Change the symbolic links of Java programs (i.e., ''java'', ''javac'' and ''jar'') to the new installation of java with the following commands:<code bash>
 +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 .
 +</code>
 +
 +==== CUP ====
 +To install CUP follow the following steps:
 +=== Download CUP ===
 +Download CUP at the following link: [[https://www.skenz.it/repository/compilers/progs/java_cup_v11_draw_tree.zip|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:<code bash>
 +cd
 +mkdir -p compilers
 +cd compilers
 +</code>
 +  * Download the CUP files into the folder:<code bash>
 +wget https://www.skenz.it/repository/compilers/progs/java_cup_v11_draw_tree.zip
 +</code>
 +  * Decompress CUP files:<code bash>
 +unzip java_cup_v11_draw_tree.zip
 +</code>
 +  * Enter the CUP directory<code bash>
 +cd java_cup_v11_draw_tree/java_cup
 +</code>
 +  * Compile CUP:<code bash>
 +javac *.java runtime/*.java ../StdDraw.java
 +</code>
 +
 +=== 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):
 +<code bash>
 +cd
 +gedit .bashrc
 +</code>
 +
 +After opening the ''.bashrc'' file, add on its top the following lines:
 +<code bash>
 +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
 +</code>
 +
 +**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:
 +<code>
 +jflex
 +</code>
 +A graphical window should be opened.
 +
 +For CUP you can type into the command prompt:
 +<code>
 +java java_cup.Main
 +</code>
 +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:
 +<code>
 +java java_cup.MainDrawTree
 +</code>
 +and if it is correctly installed you see nothing in the terminal. To stop it you can press ''CTRL-c''.
 +
 +==== Complete Check of installation ====
 +  - Download the following code: [[https://www.skenz.it/repository/compilers/classroom/exClass-2.zip|exClass-2.zip]]
 +  - Decompress in a directory end type in a terminal the following commands
 +<code>
 +jflex scanner.jflex
 +java java_cup.MainDrawTree parser.cup
 +javac *.java
 +java Main example_expr.txt
 +</code>
 +
 +
 +==== 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: [[https://www.skenz.it/repository/compilers/progs/polito-cup.tgz|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?rev=1584305353&do=diff

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