CS 451-651   Homework #5 and #6

  -- Add declaration and type representation

 --  Get basic ILOC functionality working for literal expressions

 
This assignment covers two weeks of work.  You may do the tasks in any order;  however, the first half of the assignment should be handed in on Oct 12.

Due:  Monday Oct 12 (first half), Monday Oct 17 (full version)



1.  Add syntax for simple declarations

Full example:
    const int apple[36];
int pie = 31416;


2.  Add Decl Nodes and implement constructors.  (Decls can be a kind of "StmtNode")

(might want to have separate subclasses for ScalarDecl and ArrayDecl ...)


3.  Some issues about "type"

We discussed in class possible representations for "type":
Objects are probably best -- and more flexible, if one looks forward to having "typedef" (user-defined types).
Instances will need to be built and wired in at initialization time.

You'll also need to consider whether the built-in types such as "int" should be terminals or identifiers in the grammar.  Identifiers seems the most general, if it works. 


4. ILOC

Our compiler will generate code for the RISC architecture called "ILOC", which is used in the textbook.  Though we're not yet ready to handle variables, we could handle expressions containing literals.

Assignment:  generate (and execute) code for Print stmts containing expr's (+ - *  /) using only integer literals.
(Assume unlimited number of Reg's available)

-> ILOC support and API info can be obtained here.
  (also see class notes from Oct 7)

-> a working Compiler.jar with ILOC is provided to allow experimentation.  (It probably needs to be installed in the "jar" directory of some CUP tree).