This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COP5555 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 "lefttoright 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 heres the lefttoright bent for " ". Reconsider (f g) 4. The computation can be depicted by the diagram PLP Notes Tinys Denotational Semantics2 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 lefttoright 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
 Fall '08
 Staff

Click to edit the document details