Last updated:Thu 19 Apr 2018 19:31:03 AEST

Setting up Java-CUP and JFlex under Eclipse

Please report any problems with these instructions to me.

To set up the Java-CUP plug-in for Eclipse follow the instructions at:Eclipse plug-in

Setting up the build scripts, etc., for running the parser and lexical analyser generators under Eclipse.

There are two ways to run the parser and lexical analyser generators: manually run the corresponding ant script (build-cup.xml or build-flex.xml), or set up Eclipse to automatically rerun them when needed.

Automatic running of Ant Scripts

Within Eclipse

  • Setting up Preferences
  • Select Window>Preferences (or Eclipse>Preferences on a Mac)
  • Setting up Ant's classpath to know about Java-Cup and JFlex
    Select Ant>Runtime
  • Select tab Classpath
  • Select Ant Home Entries
  • Select Add JARs
  • From within your imported assignment 2 folder selectjava-cup-v11b.jarand then OK.
  • Repeat last three steps forjflex-1.6.1.jar
  • Setting up the Ant tasks "CUPTask" and "JFlexTask" used to run Java-CUP and JFlex from Ant scripts.
    Still in Ant>Runtime
  • Select tab Tasks
  • Select Add Task
  • Set name to "CUPTask"
  • Set location to yourjava-cup-v11b.jarthat you just added to your runtime preferences for Ant above.
  • Navigate from "/" into "java_cup" and select "anttask"
  • Select "CUPTask.class" and then OK.
  • Repeat previous steps but select Name "JFlexTask", Location yourjflex-1.6.1.jarand navigate to "JFlex", then "anttask" and select "JFlexTask.class" and then OK.
  • Select Apply and then OK.
  • Project Properties
  • Select your assignment 2 folder in the package Explorer
  • Select Project>Properties
  • Setting up the Java Build Path to know about Java-CUP and JFlex
  • Select Java Build Path
  • Select Add JARs
  • From your assignment 2 project selectjava-cup-v11b.jarand then OK.
  • Repeat above two steps forjflex-1.6.1.jar
  • Setting up the Eclipse builders to run the Ant scripts for Java-CUP and JFlex
    Still in the Properties menu select Builders
  • There should be a builder there for Java
  • Select New
  • Select Ant Builder and then OK
  • Set Name to "Java-CUP"
  • Under tab Main for Buildfile browse workspace and from within your assignment 2 project select A2 and then select "build-cup.xml" and then OK
  • Under tab Refresh select tick-box and then select "Specific resources" and select "Specify Resources" and within your assignment 2 project navigate into src/parser and select just CUPParser.java and CUPToken.java and then Finish.
  • Under tab "BuildOptions" select "Specify working set of relevant resources" and then "Specify Resources"
  • Navigate within your project to src/parser and select "PL0.cup".
  • Select Apply and then OK.
  • Repeat the above process to create a builder named "JFlex" from "build-flex.xml" that refreshes the resource "Lexer.java" and uses build resources "PL0.flex".
  • You should now have 3 builders.
  • Use Up/Down buttons to order them so that JFlex is first followed by Java_CUP followed by the Java Builder.
  • Finally OK.

Manually running an Ant script in Eclipse

You'll need to set up the project properties for the Java Build Path as described above under the first part of Project Properties.

  • Select the Ant script (build-cup.xml or build-flex.xml), right click and select "RunAs" and "Ant Build".
  • That will run the Ant script and produce a log on the Eclipse Console.