Compilers Project 2

Compilers Project 2 - CS 415: Compilers Fall 2010, Project...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 415: Compilers Fall 2010, Project 2 A Simple Compiler for a Pascal Subset Due date : Wednesday, May 5, at 11:55pm EST Modifications and Clarifications Project Description You will write a syntax directed translation scheme that will generate ILOC code for the language (Pascal ssubset) defined below. The project consists of two main parts. In part 1, you will perform syntax analysis and static type checking, reporting syntax errors and static semantics errors. In part 2, you will extend your solution of part 1 to implement a code generator that will produce ILOC code. You will use bison, a version of yacc, to implement our project as a syntax-directed translation scheme. You may test the correctness of your generated ILOC code by running it on the ILOC simulator provided as part of project 1. Pascal Subset Programs consist of single blocks. There are no procedure declarations. Base types are limited to integer and boolean. Composit types are limited to single dimensional arrays of base types, indexed by integers. Only the following statements are included: while-do, if-then, if-then-else, assignment, write, and compound. Operators are restricted to arithmetic, logical, and relational. The grammar that we are using for this language is as follows: start :: = program ID ; block . block :: = variables cmpdstmt variables :: = var vardcls | empty string vardcls :: = vardcls vardcl ; | vardcl ; vardcl :: = IDlist : type IDlist :: = IDlist , ID | ID type :: = array [ integer_constant . . integer_constant ] of stype
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
| stype stype :: = integer | boolean stmtlist :: = stmtlist ; stmt | stmt stmt :: = ifstmt | astmt | wstmt | cmpdstmt | writestmt wstmt :: = while condexp do stmt ifstmt :: = ifhead then stmt else stmt | ifhead then stmt ifhead :: = if condexp cmpdstmt :: = begin stmtlist end writestmt :: = writeln ( exp ) astmt :: = lvalue := exp exp :: = rvalue | exp + exp | exp - exp | exp * exp | exp and exp | exp or exp | exp exor exp | not exp | ( exp ) | constant condexp :: = exp != exp | exp == exp | exp < exp | exp <= exp | ID | boolean_con stant lvalue :: = ID | ID [ exp ] rvalue :: = ID | ID [ exp ] constant :: = integer_constant | boolean_constant boolean_co nstant :: = true | false Part 1 As part of this project, you will Write the parser and detect and report at least the following syntax errors by inserting appropriate error productions : "\n***Error: illegal variable declaration\n" "\n***Error: illegal statement\n" "\n***Error: illegal expression\n" "\n***Error: illegal conditional expression\n" Note: Reporting the same error occurrence multiple times is okay. The grammar given above is ambiguous. However, we used features of bison to deal with operator precedence and associativity to resolve the ambiguity.
Background image of page 2
Augment your parser to perform semantic analysis, in particular type checking. This will include the implementation a single-level symbol table. Your type checker has to detect and
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Compilers Project 2 - CS 415: Compilers Fall 2010, Project...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online