CS 451-651 Homework #3 -- set up CUP+jFlex tools
First Part (to be done by Wednesday, Sept 23): Install the
tools
- Download the tar file for CUP and jflex
- unpack it using tar ( tar
vxf cup.tar ) which will create a directory expression
- cd to the new
expression directory and give a build command ( ant ) to make sure things will
work
If all is well, ant will build a scanner and parser (as demonstrated in
class) and report "0 errors".
If you don't have a recent version of ant or java, it might not build.
- I'm running ant 1.7, though 1.6.5 will also work. Java 1.5
will work, so will 1.6.
- If you're running at UMass, you will need to give the
following csh commands:
(as ant is not normally installed on
the unix system, for some dark reason).
Second Part (to be done by Monday, Sept 28): learn your way
around
Using the parser and scanner provided, run some programs through and
start to become familiar with what is happening. (This should
parse the same language as your top-down parser, without the IF
statement).
- Follow the trace output
- (note that you can use parentheses to make more complex
expressions: for instance, (a+b)+(c+d)
- Add some additional println's if there's more you'd like to know
- Select the 1c version and look at how it's capturing information
and using it to build "nodes" (objects of class N)
- (class N is defined in the 'src' directory)
And then:
- pick up this
Parser.cup file (which has the "classical expression grammar")
- install it
- (it probably needs a few additional to the Scanner.jflex file)
- run int
- add rules to support 'assignment statement', also to have a
'program' be a list of 'statement's.
Where we're going:
We'll exchange the simple-program grammar for one which is more like
Java, including simple variable (and array) declarations and more
complete expressions. Using this, we'll define data structures
(classes) and build a parse tree, which we'll then process in later
portions of the compiler.
Very brief guide to CUP and jFlex:
- The parser definition file is in the 'cup' directory, file name
'Parser.cup'. (note capitalization).
- The scanner definition file is in the 'jflex' directory, file
name 'Scanner.jflex'.
- If you provide additional Java files (as we will, for our
compiler), they go into the 'src' directory. The build script
will use 'javac' to compile 'src/*.java' and make them available to the
Compiler.
- To run the compiler you've built, execute the following:
java -jar jar/Compiler.jar
The Parser I've supplied is set to read input from the terminal;
or it may be given, as a command-line argument, the name of a file to
read from.
I've supplied several versions of Parser.cup. Use a symbolic link
(or cp or mv) to select the one you want. (The file name
'Parser.cup' is known to build.xml. In general, we'll just be
working with one parser, so this is not a problem.
If you're interested, there's a short manual
available for CUP and jFlex.
(we'll not be using the material about operator precedence)