Please note that the deadline for this assignment is firm, since I'll be giving out my solution (or, rather, an "almost" solution) during next week's lab.


Assuming you have the latest build.xml update from Assignment 3, you shouldn't need to install anything for this project, since CUP was already installed with the first project distribution.

A maintenance update to CUP (ver.11b) was released this week. However, I strongly recommend that you do not update to this version from ver.11a. Version 11b seems to have changed the behavior of the automatic generation of left and right variables for each declared nonterminal, and the documentation has not yet been updated to describe this change. It is a significant one, and trying to infer the new convention from the change log and manual inspection of a generated parser file has eaten far too much of my own time. I recommend you stick with version 11a, and do not follow my example.

To get you started and to aid in testing your parser, I've bundled a few files together, which can be obtained from


The CUP manual is available online at

Your Job

Complete the skeleton CUP specification for the Tiger programming language. Refer to the language manual for details of the syntax. Your grammar should correctly reflect all precedence and associativity rules.

It is possible (indeed likely) that you will encounter one or more shift/reduce conflicts. By default, CUP resolves such conflicts in favor of shifting. If this is the correct choice for the conflict, you should add a directive to CUP, telling it to expect this conflict. Specifically, in the build.xml file, there is a task, genParse:

<target name="genParse" depends="init" description="Generate the parser">
    <cup srcfile="${src_root}/tigerc/syntax/parse/Tiger.cup" 

Change the value of the expect attribute to reflect the number of acceptable shift/reduce conflicts in your grammar.

All reduce/reduce conflicts should be considered errors in your grammar, and they must be eliminated. Similarly, if you have any shift/reduce conflicts that should resolve in favor of reduction, you will need to eliminate them by rewriting that part of your grammar.

Turn In:

John H. E. Lasseter