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. To install Jflex execute the command
    brew install jflex
  2. Copy the folders java_cup_v11_draw_tree (that you can find in this zip file) inside compilers, in order to have the path /home/skenz/compilers/java_cup_v11_draw_tree.
  3. Enter the CUP directory
    cd java_cup_v11_draw_tree/java_cup
  4. 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 .zshrc (the .zshrc file is executed by the shell each time you open a terminal and usually it is used to configure a shell):

cd
touch .zshrc
open .zshrc

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

PATH=$PATH:.:/Users/skenz/compilers/java_cup_v11_draw_tree/java_cup/:/Users/skenz/compilers/jflex-1.8.2/bin
export PATH
CLASSPATH=.:/Users/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: 2024/04/08 22:34 by 127.0.0.1

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