



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1. Introduction. Here we show, by way of example, the use of denotational semantics for the specification of seman- tics of programming languages. In general, a denotational semantic description consists of three parts: a set of syntactic domains, a set of semantic domains, and a set of semantic functions. The semantic functions map syntactic domains into semantic domains. Typically the syntactic domains are AST’s; a semantic function might map an AST into a value (in a semantic domain), which "denotes" the meaning of the construct. Example: Suppose we were to give the denotational semantic description of a two-operand machine language, for a 16-bit machine with 8 registers. The syntactic domain might be the set of AST’s of the form < Opcode Operand Operand >. The semantic domains might as follows:
Register: {0,1,2,3,4,5,6,7} Value: (16-bit binary number) Address: (16-bit binary number) Memory: Address → Value RegValues: Register → Value
A semantic function might be EE (for EEvaluate):
EE: AST → (RegValues × Memory) → (RegValues × Memory)
EE takes an AST, then the current configuration of the machine, i.e. a (registers,memory) pair, and pro- duces a new (registers,memory) pair that shows the effect of the operation. For example, consider a "reg- ister-to-memory" add operation:
EE[+ r m] = λ (R,M). let Result = R r + M m in (R,( λ a.a eq m → Result | M a))
The meaning of an operation "+ r m", where r is a register and m is a memory address, is a function that: 1.- Takes a RegValues function R, and a Memory function M; 2.- Applies R to r (obtaining the contents of register r), applies M to m (obtaining the con- tents of address m), adds the two values, and calls the result "Result"; 3.- Returns a pair consisting of: a) The same RegValues fucntion R, and b) A new memory function that, when applied to m, returns Result, and behaves like M otherwise. The "meaning" of the operation is evident in this description: register-to-memory operation "+" adds the contents of the given register and the given memory location. It also updates the given memory location with the result of the addition, and leaves the registers unchanged. We now give the denotational semantic description of the CSE machine, for which there was (up to now) no formal, rigorous specification.
2. Denotational Semantics of the CSE Machine.
2.1. Syntactic Domains. The only syntactic domain is ST, the set of standardized trees for RPAL programs. We should note that the standardization is partial: the "→" is not standardized. Control structures are also unnecessary.
2.2. Semantic Domains.
State: Env × Output Env: Id → Value Output: Value* (tuples of values) Value: Boolean+Integer+String+Tuple+Function+ST+dummy+{error} Tuple: Value* Function: Value → Value Result: Value × Output
2.3. Semantic Functions. First, some notation. "x = > f" denotes the expression "x eq error → error | f x". This is the "pipeline" operator. An expression of the form a= >b= >c means: send a into b, and send the result into c. If anywhere along the way there is an error, propagate it. It is important to note that "= >" is LEFT associa- tive. The principal semantic function is EE: ST → (State → Result). EE is a function that takes a stan- dardized tree, and returns a State to Result function. The State is an (environment,output) pair, i.e the cur- rent configuration of the machine. The Result is a (value,output) pair, i.e. the value of the program and its output. We now describe how EE operates, on a case-by-case basis. EE[name] = λ (e,o).(e name,o) EE[
The meaning of the program is, then: EE[< γ < λ x <Print<+x2>>>1>] (PE,nil) = ( λ (e,o).(e,o) = > EE[1] = > ( λ (v,o).(e,o) = > EE[< λ x <Print<+x2>>>] = > ( λ (f,o).IsClosure f → EE[f 3] (Addenv v (f 2) (f 4),o) | Iseta f → EE[< γ < γ < λ <f 2> <f 3> > f > v > ] (e,o) | (f eq Y) & (IsClosure v) → (( η,v 2,v 3,v 4),o) | (f v,o) ) ) ) (PE,nil) =
(PE,nil) = > EE[1] = > ( λ (v,o).(PE,o) = > EE[< λ x <Print<+x2>>>] = > ( λ (f,o).IsClosure f → EE[f 3] (Addenv v (f 2) (f 4),o) | Iseta f → EE[< γ < γ < λ <f 2> <f 3> > f > v > ] (PE,o) | (f eq Y) & (IsClosure v) → (( η,v 2,v 3,v 4),o) | (f v,o) ) ) =
(PE,nil) = > EE[< λ x <Print<+x2>>>] = > ( λ (f,o). IsClosure f → EE[f 3] (Addenv 1 (f 2) (f 4),o) | Iseta f → EE[< γ < γ < λ <f 2> <f 3> > f > 1 > ] (PE,o) | (f eq Y) & (IsClosure 1) → (( η,1 2,1 3,1 4),o) | (f 1,o) ) =
(( λ ,x,<Print<+x2>>,PE),nil) = > ( λ (f,o).IsClosure f → EE[f 3] (Addenv 1 (f 2) (f 4),o) | Iseta f → EE[< γ < γ < λ <f 2> <f 3> > f > 1 > ] (PE,o) | (f eq Y) & (IsClosure 1) → (( η,1 2,1 3,1 4),o) | (f 1,o) ) =
EE[<Print<+x2>>] (Addenv 1 x PE,nil) = EE[<Print<+x2>>] (( λ N.N eq x → 1 | PE N),nil) = (( λ N.N eq x→1|PE N),nil) = > EE[<+x2>] = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
EE[2] (( λ N.N eq x→1|PE N),nil) = > ( λ (v 2 ,o).EE[x] (( λ N.N eq x→1|PE N),o) = > ( λ (v 1 ,o).PE + v 1 v 2 (( λ N.N eq x→1|PE N),o)) ) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
(2,nil) = > ( λ (v 2 ,o).EE[x] (( λ N.N eq x→1|PE N),o) = > ( λ (v 1 ,o).PE + v 1 v 2 (( λ N.N eq x→1|PE N),o)) ) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
EE[x] (( λ N.N eq x→1|PE N),nil) = > ( λ (v 1 ,o).PE + v 1 2 (( λ N.N eq x→1|PE N),o)) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
(( λ N.N eq x→1|PE N) x,nil) = > ( λ (v 1 ,o).PE + v 1 2 (( λ N.N eq x→1|PE N),o)) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
(1,nil) = > ( λ (v 1 ,o).PE + v 1 2 (( λ N.N eqx →1|PE N),o)) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
PE + 1 2 (( λ N.N eq x→1|PE N),nil) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
(1∈Integer+Real)&(2∈Integer+Real) → (1+2),nil)|error = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
(3,nil) = > ( λ (v,o).PE Print v (( λ N.N eq x→1|PE N),o)) =
PE Print 3 (( λ N.N eq x→1|PE N),nil) =
(dummy, nil aug 3) WHEW !!!