Exam1F06Hints

Exam1F06Hints - Design of Programming Languages - Fall 2006...

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

View Full Document Right Arrow Icon
Design of Programming Languages - Fall 2006 First Exam - October 17, 2006 Do any 5 Name: Points: 1. 2. 3. 4. 5. 6. 7. 1. (10 pts) Terminology. Compare and contrast: a) Abstract Syntax and Concrete Syntax b) Denotational Semantics and Operational Semantics c) Environment and Store d) Exception and Continuation See the notes and/or the textbook. 2. (10 pts) Operational semantics in μ Scheme. Scheme ( μ or otherwise) uses the list as a major data structuring facility. Represent a cons cell as CONS a l 1 , l 2 A , where l 1 and l 2 are locations holding the values of the car and cdr , respectively. The primitive cons is identiFed in the abstract syntax as PRIMITIVE( cons ). a) (5 pts) ±ill in the ”numerator” of the cons semantic judgment: a APPLY( e 1 , e 2 , e 3 ) , ρ, σ 0 A , ⇓ a CONS a l 1 , l 2 A , σ 3 { l 1 m→ v 1 , l 2 m→ v 2 }A b) (5 pts) Give the semantic judgments for both primitives car and cdr See the main text, p.98. 3. (10 pts) ML Programmimng. Design a structure Stack that represents a stack of elements of some arbitrary type. Include the functions: create (return an empty stack), push (add an element to the top of the stack and return the resulting stack), pop (delete the top element of the stack and return the resulting stack), isEmpty (test whether a given stack is empty), and top (return the top element). Also include an exception EmptyStack to catch attempts to read or pop the top element of an empty stack. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Two possible solutions (NOT involving ref types): Soln. 1: using a list to maintain a stack. structure Stack = struct exception EmptyStack; fun create () = []; fun push e stack = e::stack; fun pop (top::Rest) = Rest | pop _ = raise EmptyStack; fun isEmpty [] = true | isEmpty _ = false; fun top (t::Rest) = t | top _ = raise EmptyStack; end; Soln. 2: using a more specialized data structure. structure Stack = struct exception EmptyStack; datatype ’item stack = Empty | Node of ’item * ’item stack; fun create () = Empty; fun push x S = Node (x, S); fun pop (Node(x, S)) = S | pop _ = raise EmptyStack; fun isEmpty Empty = true | isEmpty _ = false; fun top (Node(x, S)) = x | top _ = raise EmptyStack; end; Other solutions, also involving ref types (and so side-eFects), are possible. They all require the appropriate keywords structure , struct and end . 4. (10 pts) DataTypes and Operational Semantics in Impcore. Use the semantic judg- ments for WHILE, < , SET and + and the global environment ξ = { x m→ 1 } to show that, at the end of the computation (while (< x 2) (set x (+ x x))) , the global environment is ξ = { x m→ 2 } .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2012 for the course CS 91.531 taught by Professor Giam during the Fall '09 term at UMass Lowell.

Page1 / 6

Exam1F06Hints - Design of Programming Languages - Fall 2006...

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