This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 143 Compilers Handout 3 Programming Assignment II Due Tuesday, October 20, 2009 at 11:59 PM 1 Introduction In this assignment you will write a parser for Cool. The assignment makes use of two tools: the parser generator (the C++ tool is called bison ; the Java tool is called CUP ) and a package for manipulating trees. The output of your parser will be an abstract syntax tree (AST). You will construct this AST using semantic actions of the parser generator. You certainly will need to refer to the syntactic structure of Cool, found in Figure 1 of The Cool Reference Manual (as well as other parts). The documentation for bison and CUP is available online. The C++ version of the tree package is described in the Tour of Cool Support Code handout. The documentation for the Java version is available online. You will need the tree package information for this and future assignments. There is a lot of information in this handout, and you need to know most of it to write a working parser. Please read the handout thoroughly. As before, you may work individually or as a pair for this assignment. 2 Files and Directories To get started, create a directory where you want to do the assignment and execute one of the following commands in that directory . For the C++ version of the assignment, you should type make -f /usr/class/cs143/assignments/PA3/Makefile For Java, type: make -f /usr/class/cs143/assignments/PA3J/Makefile (notice the J in the path name). This command will copy a number of files to your directory. Some of the files will be copied read-only (using symbolic links). You should not edit these files. In fact, if you make and modify private copies of these files, you may find it impossible to complete the assignment. See the instructions in the README file. The files that you will need to modify are: cool.y (in the C++ version) / cool.cup (in the Java version) This file contains a start towards a parser description for Cool. The declaration section is mostly complete, but you will need to add additional type declarations for new nonterminals you introduce. We have given you names and type declarations for the terminals. You might also need to add precedence declarations. The rule section, however, is rather incomplete. We have provided some parts of some rules. You should not need to modify this code to get a working solution, but you are welcome to if you like. However, do not assume that any particular rule is complete....
View Full Document