

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Midterm Exam Sample Solutions Problem 1. Any of several instances of ambiguity could be identified as a response. For one, consider a command of the form while b do c1; c2. This has two structural descriptions. command command while expr do command command ; command b command ; command while expr do command c c1 c2 b c Another example would be a command of the form if b1 then if b2 then c1 else c2 that has two structural descriptions. command command if expr then command if expr then command else command b1 if expr then command else command b1 if expr then command c b2 c1 c2 b2 c
Problem 2. The first production in this attribute grammar is replaced by two new rules, namely
These productions provide for the addition of a binary exponent suffix. All the other productions and their attribute rules are unchanged. Note that in the examples in the problem statement, the exponent value is used as the multiplier (or dividend). This is in contrast with common usage where the multiplier has the exponent part as the power of the base -- this may have been distracting and was not enough simpler to justify it, sorry. Either of these choices was given full credit (and differ technically in a very small way). For consistency with the problem statement, the attribute evaluation rules provided here take the former approach (just put Val(
e
Val(<binary!digits> 2 ) 2 Len(<binary!digits>^2 )
e-
Val(<binary!digits> 2 ) 2 Len(<binary!digits>^2 )
Since the Val(