{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Homework8-sol

# Homework8-sol - So CC<do C E> = CC< C<while E...

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

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.

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

View Full Document
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;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: So, CC[<do C E>] = CC[ <; C <while E C>>] 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[<c_c n C>] = lambda(v,s). v eq \undef -> (v,s) | v ne n -> (v,s) | (\undef , s => CC[C])...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

Homework8-sol - So CC<do C E> = CC< C<while E...

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

View Full Document
Ask a homework question - tutors are online