This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COP-5555 PROGRAMMING LANGUAGE PRINCIPLES NOTES ON THE DENOTATIONAL SEMANTICS OF TINY. 1. The " ° " operator. The " ° " operator is defined as follows: ° = λ f. λ g. λ x. f x eq error → error | g(f x) i.e., " ° " takes two functions, f and g, and yields a new function on x that returns g(f x) if (f x) does NOT evaluate to error, and error if (f x) does evaluate to error. " ° " simply serves as a convenient way to put error checking in our denotational definition everywhere without laboriously specifying it ourselves every- where. In the denotational semantics description of Tiny we will be using " ° " as an INFIX operator, writ- ing f ° g instead of ° f g. Thus f ° g = λ x. f x eq error → error | g(f x) This is purely a syntactic convention of ours that turns out to make denotational semantics descriptions read easier. It allows a "left-to-right flow" reading of such descriptions, exemplified below. Consider an exam- ple where f = λ y. 2/y g = λ z. z+3 Then f ° g = λ x. ( λ y.2/y) x eq error → error | ( λ z.z+3) (( λ y.2/y)x) = λ x. 2/x eq error → error | 2/x+3 Consider applying f ° g to an actual argument, say, 4: (f ° g) 4 = 2/4 eq error → error | 2/4+3 = 2/4+3 = 3 1/2. Now consider (f ° g) 0 = 2/0 eq error → error | 2/0+3 = error, since 2/0 eq error (division by zero). It is to catch things like division by zero or undeclared identifiers that we use " ° ". Now here’s the left-to-right bent for " ° ". Re-consider (f ° g) 4. The computation can be depicted by the diagram PLP Notes Tiny’s Denotational Semantics-2- 4 f(x) g(f(x)) f ° g 4 gets "sent into" f, and the result pops out on the other side of f, i.e. (f x). This result (f x) gets sent into g (unless it equals error, in which case the computation in g is skipped), and the final answer is g(f x). So, you can read " ° " expressions very naturally in a left-to-right manner. In general, read the expression f 1 ° f 2 ° ... ° f k as denoting that function of x that first sends x through f 1 , the result of which is sent through f 2 , the result of which is sent through f 3 , ..., the result of which is sent through f k , with error checking at each step so that if the evaluation of any f i applied to its argument is "error", then the evaluation of functions f i + 1 ... f k are SKIPPED and the final answer is "error". " ° " therefore, takes two functions and produces a third. 2. The " = > " operator. "x = > f" denotes "x eq error → error | f x"....
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.
- Fall '08