User Tools

Site Tools


compilers:install_macos
Return to Home page

Install Jflex, CUP and Java in macOS

Guide on how to install Java, Jflex and CUP in the macOS operating system.

THIS GUIDE FOR NOW WAS CHECKED ONLY BY ONE STUDENT, AS A CONSEQUENCE IF YOU FOUND ERRORS OR SOME PASSAGES THAT CAN BE SIMPLIFIED, PLEASE LET ME KNOW BY SENDING AND EMAIL.

Java

The Oracle JDK can be downloaded at the following address https://www.oracle.com/java/technologies/javase-downloads.html, choosing the one marked as Windows x64 Installer (at the moment of this guide the recommended version to download is jdk-15.0.2_osx-x64_bin.tar.gz).

Java installation

To install Java a possible guide is the following:

  1. Create a folder into your home directory
    cd
    mkdir -p compilers
    cd compilers
  2. Download into the folder the Java installation file jdk-15.0.2_osx-x64_bin.tar.gz.
  3. Decompress it
    tar xvfz jdk-15.0.2_osx-x64_bin.tar.gz

Jflex and CUP

To install JFlex and CUP follow the following steps:

  1. Copy the folders java_cup_v11_draw_tree and jflex-1.8.2 (that you can find in this zip file) inside compilers, in order to have the two paths /home/skenz/compilers/java_cup_v11_draw_tree and /home/skenz/compilers/jflex-1.8.2.
  2. Enter the CUP directory
    cd java_cup_v11_draw_tree/java_cup
  3. Compile CUP:
    javac *.java runtime/*.java ../StdDraw.java

Configure environment variables

Before running CUP and Jflex, environment variables must be configured.

To set the environment variables, open in your home directory the file .bash_profile (the .bash_profile file is executed by the shell each time you open a terminal and usually it is used to configure a shell):

cd
open .bash_profile

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

PATH=$PATH:.:/home/skenz/compilers/java_cup_v11_draw_tree/java_cup/:/home/skenz/compilers/jflex-1.8.2/bin
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

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_macos
/web/htdocs/www.skenz.it/home/data/pages/compilers/install_macos.txt · Last modified: 2021/03/24 14:10 by zioskenz

Privacy Policy