tiny.denot - COP-5555 PROGRAMMING LANGUAGE PRINCIPLES NOTES...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 heres the left-to-right bent for " ". Re-consider (f g) 4. The computation can be depicted by the diagram PLP Notes Tinys 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

Page1 / 7

tiny.denot - COP-5555 PROGRAMMING LANGUAGE PRINCIPLES NOTES...

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