[UMN logo]

CSCI 5106: Programming Languages
Spring 2006, University of Minnesota
Homework 2


Posted: January 31, 2006
Due: Before class on February 14, 2006


Problem 1

Problem 2.10 in the book. Your grammar should be one that, in the sense discussed in class, assigns a parse tree to each expression that correspond closely to its intended abstract syntax.

Note: One may sometimes want to distinguish between expressions that yield values of different types within a grammar. For example, noticing that and is an operator that works only on boolean expressions, one may want to distinguish between those expressions that yield boolean values and those that yield integer values. This kind of `type checking' can be difficult to do through syntax rules and is typically not the way things are organized in compilers: in compilers, expressions are constructed in a type neutral way and then type checking is done over these structures to decide whether or not they are semantically well formed. Think about this issue and feel free not to build type checking into your semantic rules; actually a type neutral grammar would be my own preferred choice.


Problem 2

Draw parse trees with respect to the grammar you have described in Problem 1 for each of the expressions in Problem 2.11 in the book and the following expressions:
(i >= 0 + j) and x or y
(i >= 0 + j) and (x or y)
Would your grammar accept the first of the above expressions if the parentheses were left out? If yes, show the parse tree for it. If no, explain briefly why not.


Problem 3

Identify the abstract syntax corresponding to each of the expressions in Problem 2.


Problem 4

Problem 2.15 in the book.


Problem 5


Problem 6 (Extra credit)

First read Sections 13.1 and 13.2 in the book.


Last updated on Jan 31, 2006 by gopalan@cs.umn.edu