Homework8-sol - So, CC[<do C E>] =...

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

View Full Document Right Arrow Icon
COP 5555 Programming Language Principles Homework 8 Solution 1. Problem 1 (30 Points) In the PowerPoint of Lecture 27, slide 21, at the end of the definition of the Pascal "for" loop, why do we have "(Replace m I \bottom, i, o)"? Solution: Because according to Pascal specification, the loop variable has to be undefined after the execution of the loop; its value is reset to undefined. 2. Problem 2 (30 Points) In the same Powerpoint lecture, slide 23, at the end of the definition of the Pascal "case" statement, why do we have "o (\lambda(v,s).s)"? Solution: The goal is to discard the value because a statement should return a state not a value-state tuple. 3. Problem 3 (40 Points) Add a 'do' statement (as in the C language) to the denotational semantics specification of Tiny.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Solution: First, add an item to the C syntactic domain: C = ... | <do C E> Then add a case in the definition of CC. The trick is to notice that do C while E is equivalent to C; while E do C;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: So, CC[&lt;do C E&gt;] = CC[ &lt;; C &lt;while E C&gt;&gt;] 4. Problem 4 (30 Points) Consider the denotational semantics specification of Tiny. Suppose we were to make a single change to the specification of the '+' operator (slide 20 lecture ppt 26). Consider changing the LAST occurrence of s2 to s1, on the next-to-last line. Explain in plain English how the semantics of the Tiny language change due to this change in the specification. Illustrate your argument by constructing a sample Tiny program that illustrates the different semantics. Solution: program x: assign i := 1 + read; output(read); end x. 5. Problem 5 (30 Points) Why is type checking difficult in the denotational description of Tiny? Solution: Because there is no variable declaration in Tiny. 6. Problem 6 (40 Points) Write the denotational description of the 'case' statement in C for Tiny. Solution: C_CC[&lt;c_c n C&gt;] = lambda(v,s). v eq \undef -&gt; (v,s) | v ne n -&gt; (v,s) | (\undef , s =&gt; CC[C])...
View Full Document

This note was uploaded on 01/22/2012 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 3

Homework8-sol - So, CC[&amp;amp;lt;do C E&amp;amp;gt;] =...

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

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