CS 415: Compilers
Project 2: A Simple Compiler
Due date: Monday, April 22, 2019

Clarifications and Modifications

Pascal-Like Subset

Using flex and bison, you are to write a parser and code generator for a Pascal-like language . There are no procedures in this language. Base types are limited to integer and boolean. Composit types are limited to single dimensional arrays of base types, indexed by integers (0-based indexing). Only the following statements are included: while-do, if-then-else, assignment, print, and compound. Operators are restricted to arithmetic, logical, and relational.

Project Description

As part of this project, you will given the full scanner (scan.l) and a skeleton parser (parse.y), together with a nearly complete implementation of the symbol table (symtab.h and symtab.c). Funtions needed to generate ILOC code are also provided (instrutils.h and instrutils.c). As part of this project, you have to write a syntax-directed translation scheme. You will have to

Specific Details

Names are case sensitive .

Logical operators (and, or) require boolean arguments. The arithmetic and relational operators (e.g., +, <=) require integer arguments. Integer and boolean arguments cannot be mixed. The equality/inequality operators (==, !=) apply to any type, as long as the two argument types match.

Getting Started

The following code is provided as a starting point for your project. The files listed below live on the ilab cluster in subdirectory ~uli/cs415/projects/proj2 . Please copy the files into your subdirectory of choice using the command
cp -r ~uli/cs415/projects/proj2 myProjectSubdirectory . You may modify files for your project according to the following guideline.
  1. declaration of types and attribute operations: attr.h and attr.c
  2. Additional information needed in symbol table and symbol table operations: symtab.h and symtab.c
  3. Scanner: scan.l (flex); do not modify
  4. Parser: parse.y (bison); here is most of your work. The current version contains some valuable hints of how your code should look like.
  5. Makefile; do not modify
  6. There are several test programs in subdirectory "testcases"; you can run the sample solution sol-codegen on these test cases and look at the generated code in iloc.out and the generated error messages. Note: your code should have the same functionality, but your code may look somewhat different.
You can generate an executable called codegen by typing make . The executable codegen expects the input on stdin, i.e., the call has the form ./codegen < testcases/demo1 .

Due Date

The project is due at 11:59 pm on Monday April 22, 2018--that is, one minute before midnight.

If you have specific, overriding, personal reasons why these dates are unreasonable, you should discuss them directly with the instructor before the deadline.

Our standard every starting 24 hour based late penalty policy of 20% applies.

Submission Procedure

Will be posted later.

Grading Criteria

The project will be mainly graded on functionality. You will receive no credit for the entire project if your code does not compile and run on the ilab cluster . We may use automatic testing tools, so make sure that your error messages are exactly as described above .