UMBC CMSC431, Compiler Design Principles, Fall 2009
Project 4
Due: Monday, October 26, 2009, 12:00pm (noon)
Objective
This project continues to expand the features available in your programming
language. You will add conditional statements and control structures to
your language.
Assignment
Add the following features to your programming language:
- A Boolean type for variables and Boolean constants for true and false.
- Boolean operations (and, or, not).
- Relational operators (less than, less than or equal to, equals, not
equals, greater than or equal to, greater than) for integer and floating
point expressions.
- If statements.
- While loops.
Implementation Notes
- For simplicity, just use 4 bytes to hold a Boolean value.
- Since we are using signed integers, you want to use the
"signed" jump instructions. For example, use JG (jump greater than)
instead of JA (jump above).
- For simplicity, specify "near jumps" for all of your branching.
- For floating point comparisons, look at
double5.asm and
double5.txt. Explanations
for this is in Section 8.3.6 of the
IA-32 Intel Architecture
Software Developer's Manual.
- Generating labels for the assembly language program for if statements
and while loops require some care. Your compiler must allow for an
arbitrary number of nested if statements and an arbitrary number of nested
while loops.
- You might find it useful to have mid-rule actions in your
yacc file. ( Hint, hint.) This is explained in
Section 3.5.5 of the Bison Book and in the "Embedded Actions" sections
of the Flex and Bison book (p. 143).
- When you invent a new grammar for if statements and while loops, keep
in mind that bison cannot parse everything. In the following example from
the flex and bison book (p. 50), we have:
phrase: cart_animal AND CART
| work_animal AND PLOW
;
cart_animal : HORSE | GOAT ;
work_animal : HORSE | OX ;
It is not possible for Bison to generate a parser that can determine
whether HORSE should reduce to cart_animal or to work_animal because that
depends on whether "phrase" expands to "cart_animal AND CART" or
"work_animal AND PLOW". The LALR(1) parser that Bison generates cannot look
past AND to see if "phrase" ended with CART or PLOW. (Note: this
grammar is not ambiguous.)
Submitting Your Project
We will use a new repository for Project 4. You should first use CVS
to check-out Project 4.
cvs -d /afs/umbc.edu/users/c/h/chang/pub/cs431f09/Proj4 checkout -d MyProj4 user1
Then, use cvs add and cvs commit to check-in any files that you have
copied over from Project 3 (and any other files that you want to submit).
Since your programming language is looking more like a real programming language and less
like a calculator, this is a good time to rename your expr.l and expr.y
files.
Include in your submission some test programs that demonstrate your
implementation of Boolean expressions, if statements and while loops. Your
test programs should show that your compiler can handle multiply nested if
statements and while loops.
Last Modified:
22 Jul 2024 11:27:41 EDT
by
Richard Chang
to Fall 2009 CMSC 431 Homepage