ICS 142
Homework 2
Due 4/26
- (10 points) Use Bison to generate a parser for Tiny-Ada using the grammar in http://www.ics.uci.edu/~klefstad/s/142/src//hw2/declare.y, then combine it with your lexical analyzer from last homework to form a complete recognizer for the language.
- (40 points) Rewrite the expression grammar to handle operator predecence and associativity according to the following rules:
- AND has lowest precedence and is left-associative
- "<" has higher precedence than AND and is non-associative
- "+" has higher precedence than "<" and associates to the left
- "*" has higher precedence than "+" and associates to the left
- NOT has higher precedence than all binary operators
- identifiers, numbers, and parenthesized expressions are atomic and have equal and highest precedence.
- Note: DO NOT use %prec, %left, %right, or %assoc declarations.
- Do not try to handle type checking with syntax rules.
- (20 points) Print out assignment statements and expressions in postfix to show you handle precedence and associativity correctly.
- (30 points) Write a hand-coded recursive descent parser for Tiny-Ada, but assume assignment statements are only of the form Id := Id; and handle the rest of the language unchanged.
- Submit your modified grammar and a sample run of your Bison parser on one complex correct Tiny-Ada program to convince me it works. Also submit your recursive-decent parser and sample run on a similarly complex program that contains nested declare blocks and every type of statement and declaration, but be sure to keep expressions of the form ID := ID; Use a variety of long identifiers.