Presentation is loading. Please wait.

Presentation is loading. Please wait.

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © 2005--2006, University of Aarhus [ ] [

Similar presentations


Presentation on theme: "C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © 2005--2006, University of Aarhus [ ] ["— Presentation transcript:

1 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © 2005--2006, University of Aarhus [ brabrand@daimi.au.dk ] [ http://www.daimi.au.dk/~brabrand/ ] S EMANTICS (Q1,’06) W EEK 4: ”STR. IND., DEFINITIONS, STATIC AND DYN. SEM.”

2 C LAUS B RABRAND [ 2 ] S EMANTICS (Q1,’06) S EP 21, 2006 Outline Competition Results Feedback from T.A.s Structural Induction (and Proof Structure) Comprehensive Structural Induction Example Finite vs. Infinite Stores Functional Languages (Let) Definitions (Let++) Type-Checking Definitions (Let B ++)

3 C LAUS B RABRAND [ 3 ] S EMANTICS (Q1,’06) S EP 21, 2006 Hand-in 2 Competition Hand-in 2 Competition:

4 C LAUS B RABRAND [ 4 ] S EMANTICS (Q1,’06) S EP 21, 2006 And the winner is... 1. 3. 2. Rikke Bendlin Emil Renner Berthing Jannick Bitsch (for introduction)

5 C LAUS B RABRAND [ 5 ] S EMANTICS (Q1,’06) S EP 21, 2006 Feedback from T.A.s Live exercises...(!!) Activation (both during + after lecture) Getting a fish vs. learning to fish... Exercise = Exam Training (really nice to have) Non-canonical (using your suggestions) 'Improvisation' (depending on feedback in auditorium) Otherwise: ask specific questions on the webboard... Curriculum...(?) Not unfair that lectures may actually be useful (!!) Exam questions are based on written material Notes + presentation slides + exercises

6 C LAUS B RABRAND [ 6 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exam Preliminary Date October 18, 2006 (Wednesday) 5 ECTS 4 hours All usual materials 13-scale And yes, there will be at least one exercise on Structural Induction.

7 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 S TRUCTURAL I NDUCTION A Detailed Example: Determinism of SOS for L-Expressions

8 C LAUS B RABRAND [ 8 ] S EMANTICS (Q1,’06) S EP 21, 2006 Structural Induction (for Exp) Given: Arithmetic Expressions ( e  Exp) e ::= n | v | e 0 +e 1  e  Exp : P(e) P(n)  composite (inductive) case base cases Principle of structural induction: P(e 0 )  P(e 1 )  P(e 0 +e 1 )  P(v) and

9 C LAUS B RABRAND [ 9 ] S EMANTICS (Q1,’06) S EP 21, 2006 Intuition: Induction vs. Str’ Induction Induction: Holds for ? Structural Induction: Holds for ? P(0)P(0) => P(1)P(1) => P(2)P(2) => P(3)  P(3) P(7+(x+y)) P(7) P(x) P(y) P(x+y) P(7+(x+y))     

10 C LAUS B RABRAND [ 10 ] S EMANTICS (Q1,’06) S EP 21, 2006 Structural Induction Examples Given: Arithmetic Expressions ( e  Exp) Determinism of SOS* for L-expressions : “One-step evaluation of expressions is deterministic” e ::= n | v | e 0 +e 1 P(e)  ,  ’: [ (  | _ e     | _ e   ’ ) =>  =  ’ ]  e: P(e) */ using the (side-effectless) small-step operational semantics Let  be given: Prove: (i.e., “prove property, P, holds for all expressions”)

11 C LAUS B RABRAND [ 11 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof Structure (according to SI) Base cases: Case [ n ]; show : Case [ v ]; show : Inductive case: Case [ e 0 +e 1 ]; show : assume induction hypothesis [lhs]: P(e 0 )  P(e 1 ) show inductive step [rhs]: P(e 0 +e 1 ) P(n)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

12 C LAUS B RABRAND [ 12 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Base Case [n] Case [ n ]; show : Show implication “ => ” (assume [lhs], show [rhs]): However, since [lhs] is trivially false (no rules for constants), the whole thing is trivially true (aka. “vacuously true”) Recall that: [explanation]explanation P(n)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(n)   b : (false => b)  true P  Q   P  Q PQ P  Q false true falsetrue false true

13 C LAUS B RABRAND [ 13 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Base Case [v] Case [ v ]; show : Show implication “ => ” (assume [lhs], show [rhs]): assume [lhs]: and for some ,  ’ show [rhs]: could only be because ; thus,  =  (v) …and similarly: could only be because ; thus,  ’ =  (v) Thus, we have that:  =  (v) =  ’ (as required)  P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(v)  |_ v   |_ v    =  ’  |_ v  ’ |_ v  ’  |_ v   |_ v    | _ v   (v)  |_ v  ’ |_ v  ’

14 C LAUS B RABRAND [ 14 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Inductive Case [e 0 +e 1 ] Case [ e 0 +e 1 ]; show : assume induction hypothesis: P(e 0 )  P(e 1 ) show inductive step: P(e 0 +e 1 ) Show implication “ => ” (assume [lhs], show [rhs]): Assume [lhs]: and for some ,  ’ Show [rhs]: When could we have that: (?) Case Analysis (on e 0 +e 1 ) Three possibilities ( [SUM 1 ], [SUM 2 ], and [SUM 3 ] )… P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(e 0 )  P(e 1 ) => P(e 0 +e 1 )  | _ e 0 +e 1    | _ e 0 +e 1   ’  =  ’  | _ e 0 +e 1  

15 C LAUS B RABRAND [ 15 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Case Analysis (on e 0 +e 1 ) Case Analysis (on e 0 +e 1 ): Case [SUM 1 (e 0  Z)]: could only be because But from our induction hypothesis, P(e 0 ) ; i.e. … : … we get that: and implies that: e 0 ’ = e 0 ” Thus we have that:  = e 0 ’+e 1 = e 0 ”+e 1 =  ’ (as required)  | _ e 0 +e 1    |_ e0  e0’ |_ e0  e0’  | _ e 0 +e 1  e 0 ’+e 1 =   |_ e0  e0” |_ e0  e0”  | _ e 0 +e 1  e 0 ”+e 1 =  ’  | _ e 0 +e 1   ’   |_ e0  e0’ |_ e0  e0’  |_ e0  e0” |_ e0  e0” P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’

16 C LAUS B RABRAND [ 16 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Case Analysis (on e 0 +e 1 ) Case [SUM 2 (e 0  Z, e 1  Z)]: (analoguous) Case [SUM 3 (e 0  Z, e 1  Z)]: could only be because Thus, we have that:  = m = n 0 +n 1 = m’ =  ’ (as required)  | _ n 0 +n 1    | _ n 0 +n 1   ’  | _ e 0 +e 1  m =   | _ e 0 +e 1  m’ =  ’ m = n 0 +n 1 m’ = n 0 +n 1   

17 C LAUS B RABRAND [ 17 ] S EMANTICS (Q1,’06) S EP 21, 2006 What did we do: Proof Structure Base cases: Case [ n ]; showed : Case [ v ]; showed : Inductive case: Case [ e 0 +e 1 ]; showed : assumed induction hypothesis [lhs]: P(e 0 )  P(e 1 ) showed inductive step [rhs] via case analysis: P(e 0 +e 1 ) P(n)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

18 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 I NFINITE vs. F INITE S TORES

19 C LAUS B RABRAND [ 19 ] S EMANTICS (Q1,’06) S EP 21, 2006 Problem: Infinite Stores Problem: (Var infinite) Solution: (for V  FIN Var) Now define finite configurations:   Store = Var  Z  v  Store V = V  Z  V,E := { | Var E ( e )  V    Store V } appropriate store all vars in “V”

20 C LAUS B RABRAND [ 20 ] S EMANTICS (Q1,’06) S EP 21, 2006 Finite Typeable Configurations Configurations (Exp): Transitions (using “  V,E ”): Configurations (Com): Transitions (using “  V,C ”):  V.C := { | Var C ( c )  V    Store V  | _ wfc c }  V,E := { | Var E ( e )  V    Store V   : | _ e:  }  V,E [ SUM 1 ]  V,C [ SEQ 1 ]  {  |   Store V }

21 C LAUS B RABRAND [ 21 ] S EMANTICS (Q1,’06) S EP 21, 2006 Variable Extraction Functions Var E : Exp  P(Var) Var E ( n ) = Ø Var E ( t ) = Ø Var E ( v ) = { v } Var E ( ~ e ) = Var E ( e ) Var E ( e  e’ ) = Var E ( e )  Var E ( e’ ) Var C : Com  P(Var) Var C ( nil ) = Ø Var C ( x := e ) = { x }  Var E ( e ) Var C ( c ; c’ ) = Var C ( c )  Var C ( c’ ) Var C ( if e then c else c’ ) = Var E ( e )  Var C ( c )  Var C ( c’ ) Var C ( while e do c ) = Var E ( e )  Var C ( c ) e ::= n | v | ~ e | e  e’ c ::= nil | v := e | c ; c’ | if b then c else c’ | while b do c

22 C LAUS B RABRAND [ 22 ] S EMANTICS (Q1,’06) S EP 21, 2006 Finite Typeable Configurations Configurations (Exp): Transitions (using “  V,E ”): Configurations (Com): Transitions (using “  V,C ”):  V.C := { | Var C ( c )  V    Store V  | _ wfc c }  V,E := { | Var E ( e )  V    Store V   : | _ e:  }  V,E [ SUM 1 ]  V,C [ SEQ 1 ]  {  |   Store V }

23 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 D EFINITIONS (FUNCTIONAL LANGs)

24 C LAUS B RABRAND [ 24 ] S EMANTICS (Q1,’06) S EP 21, 2006 Introducing Binding Constructs Consider the language ”Let”: Expressions ( e  Exp): Example Let program: Note: the actual identifier names are irrellevant (only the use-def links are significant) e ::= n | x | e  e’ | let x = e in e’   { +, -, * } …where: x + let x = 5 in x + let x = 1 + x in x * x Definition (def) Usage (use): Free use Bound use use-def link Terminology definition scope for ' x '

25 C LAUS B RABRAND [ 25 ] S EMANTICS (Q1,’06) S EP 21, 2006 Free Variables Determine the free variables? FV: Exp  P(Var) FV( n ) = Ø FV( x ) = { x } FV( e  e’ ) = FV( e )  FV( e’ ) FV( let x=e in e’ ) = FV( e )  ( FV( e’ ) \ { x } ) e ::= n | x | e  e’ | let x = e in e'

26 C LAUS B RABRAND [ 26 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics (Trans. Sys.) Define (family of) environments: recall terminology (no side-effects) Configurations: i.e., numbers Transition relation: ; writing for  V = { |   Env V  FV( e )  V } T V = { |   Env V  z  Z }  v  Env V = V  Z Note: this is done slightly differently in the note [SOS]: through “relative transition systems” that are (implicitly) relative to an environment. V  V  VV  V  V  |- e  V e (, )  ‘  V ’

27 C LAUS B RABRAND [ 27 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics [n] | [x] | [e  e] Structural Operational Semantics: [ BOP 1 ] [ BOP 2 ] [ BOP 3 ] [ VAR ]  |- e 0  e 1  V e 0 ’  e 1  |- e 0  V e 0 ’  |- z 0  z 1  V z z = z 0  z 1  |- z 0  e 1  V z 0  e 1 ’  |- e 1  V e 1 ’  |- x  V z z =  (x)   Env V = V  Z

28 C LAUS B RABRAND [ 28 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics [ let-in ] Structural Operational Semantics: Note: the premisis works in the extended environment Live exercise: eval in env: [ LET 2 ] [ LET 3 ] [ LET 1 ]  |- let x = e 0 in e 1  V let x = e 0 ’ in e 1  |- e 0  V e 0 ’  |- let x = z in n  V n  |- let x = z in e 1  V let x = z in e 1 ’  [x  z] |- e 1  V  {x} e 1 ’ let x=y in x [y7][y7]   Env V = V  Z

29 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C OMPOUND D EFINITIONS

30 C LAUS B RABRAND [ 30 ] S EMANTICS (Q1,’06) S EP 21, 2006 Compound Definitions Consider language Let++: Expressions ( e  Exp): Definitions (d  Def): e ::= n | x | e  e’ | let d in e d ::= nil | x = e | d ; d’ | d and d’ | d in d’ x + 3y = x+7 Graphically:  Val  Env {x}  Env {y} [x1][x1]  Env {x} [x1][x1][y8][y8] 4   { +, -, * } …where:

31 C LAUS B RABRAND [ 31 ] S EMANTICS (Q1,’06) S EP 21, 2006 Graphically: [x = e] | [d ; d’] Definition block: E.g.: Sequential definition: E.g.: let d in e d 0 ; d 1 let x=a ; y=b in b * c + y a b c x y b c >

32 C LAUS B RABRAND [ 32 ] S EMANTICS (Q1,’06) S EP 21, 2006 Graphically: [d and d’] | [d in d’] Simultaneous definition: E.g.: Private definition: E.g.: d 0 and d 1 d 0 in d 1 >

33 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C OMPOUND D EFINITIONS Semantics of Let++

34 C LAUS B RABRAND [ 34 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics: Let++ Problem: I.e. non-disjoint simultaneous definitions! Solution: static semantics def / exp “well-formedness relations”: ‘|- wfd ’ / ‘|- wfe ’: let x = 1 and x = 2 in x | _ wfe e | _ wfe e’ | _ wfe e  e’ Exp well-formedness: | _ wfe n | _ wfe x | _ wfd d | _ wfe e | _ wfe let d in e  Definition well-formedness: | _ wfd nil | _ wfe e | _ wfd x = e | _ wfd d | _ wfd d’ | _ wfd d ; d’ | _ wfd d | _ wfd d’ | _ wfd d and d’ | _ wfd d | _ wfd d’ | _ wfd d in d’ DV( d )  DV( d’ ) = Ø

35 C LAUS B RABRAND [ 35 ] S EMANTICS (Q1,’06) S EP 21, 2006 Recall: Free Variables for Let Let: FV( n ) = Ø FV( x ) = { x } FV( e  e’ ) = FV( e )  FV( e’ ) FV( let x=e in e’ ) = FV( e )  ( FV( e’ ) \ { x } ) Let++: FV( let d in e’ ) = FV( d )  ( FV( e’ ) \ DV( d ) ) So we need FV( d ) and DV( d ) …

36 C LAUS B RABRAND [ 36 ] S EMANTICS (Q1,’06) S EP 21, 2006 Defining Variables and Free Variables DV: Def  P(Var) DV( nil ) = Ø DV( x = e )= { x } DV( d ; d’ ) = DV( d )  DV( d’ ) DV( d and d’ )= DV( d )  DV( d’ ) DV( d in d’ )= DV( d’ ) FV: Def  P(Var) FV( nil ) = Ø FV( x = e )= FV( e ) FV( d ; d’ ) = FV( d )  ( FV( d’ ) \ DV( d ) ) FV( d and d’ )= FV( d )  FV( d’ ) FV( d in d’ )= FV( d )  ( FV( d’ ) \ DV( d ) ) + should be disjoint union d ::= nil | x = e | d ; d’ | d and d’ | d in d’

37 C LAUS B RABRAND [ 37 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics Expression Configurations: Problem: what should definitions evaluate to? Environments (like expressions evaluate to numbers) Solution: “environments as results” (add intermediate syntax): Definition Configurations:  V,E = { |   Env V  FV( e )  V  |- wfe e } T V,E = { |   Env V  z  Z } only well-formed exps d ::= nil | x = e | d ; d’ | d and d’ | d in d’ |  0  V,D = { |   Env V  FV( d )  V  |- wfd d } T V,D = { |   Env V } only well-formed defs

38 C LAUS B RABRAND [ 38 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics: Exp Structural Operational Semantics: Note: the premisis works in the  0 - extended environment [ LET 2 ] E [ LET 3 ] E [ LET 1 ] E   Env V = V  Z  |- let d in e  V let d’ in e  |- d  V d’  |- let  0 in n  V n  |- let  0 in e  V let  0 in e’  [  0 ] |- e  V  DV(  0) e’

39 C LAUS B RABRAND [ 39 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [nil] | [x=e] Structural Operational Semantics: [ NIL ] D  |- nil  V [] the empty environment,  [] [ DEF 1 ] D  |- x = e  V x = e’  |- e  V e’ [ DEF 2 ] D  |- x = n  V [x  n] the environment,  [x  n]   Env V = V  Z

40 C LAUS B RABRAND [ 40 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [d;d’] Structural Operational Semantics: Note: the premisis works in the  0 - extended environment Note: the result is the combined environment,  0 [  1 ] [ SEQ 2 ] D [ SEQ 3 ] D [ SEQ 1 ] D  |- d 0 ; d 1  V d 0 ’ ; d 1  |- d 0  V d 0 ’  |-  0 ;  1  V  0 [  1 ]  |-  0 ; d 1  V  0 ; d 1 ’  [  0 ] |- d 1  V  DV(  0) d 1 ’   Env V = V  Z Live exercise: evaluate in environment: x = 2 ; x = x+y [ y = 1]

41 C LAUS B RABRAND [ 41 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [d and d’] Structural Operational Semantics: Notice the independence of the two operands ( d 0 & d 1 ) Note: the result is the disj. combined environment,  0  1 [ AND 2 ] D [ AND 3 ] D [ AND 1 ] D  |- d 0 and d 1  V d 0 ’ and d 1  |- d 0  V d 0 ’  |-  0 and  1  V  0  1  |-  0 and d 1  V  0 and d 1 ’  |- d 1  V d 1 ’   Env V = V  Z Q: what happens if operands do not contain disjoint definitions (e.g. "x=1 and x=2") A: trans. sys. was only def'd for well-formed exps/defs! Hence, no such runtime errors!

42 C LAUS B RABRAND [ 42 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [d in d’] Structural Operational Semantics: Note: the premisis works in the  0 - extended environment Note: the result is only the last environment,  1 [ IN 2 ] D [ IN 3 ] D [ IN 1 ] D  |- d 0 in d 1  V d 0 ’ in d 1  |- d 0  V d 0 ’  |-  0 in  1  V  1  |-  0 in d 1  V  0 in d 1 ’  [  0 ] |- d 1  V  DV(  0) d 1 ’   Env V = V  Z

43 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 T YPE C HECKING D EFINITIONS

44 C LAUS B RABRAND [ 44 ] S EMANTICS (Q1,’06) S EP 21, 2006 Adding Boolean Variables: Let B ++ Consider language Let B ++: Mixed Expressions ( e  Exp): Definitions (d  Def): Note: The type of a var is now context dependent I.e. a context-free (grammar) approach will not suffice Examples: ? ? … e ::= n | t | x | ~ e | e  e’ | e ? e’ : e” | let d in e d ::= nil |  x = e | d ; d’ | d and d’ | d in d’   { +, -, *, =, or } …where: x or tt x * x type definition (annotation)   { bool, int } …where:

45 C LAUS B RABRAND [ 45 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics: Let B ++ FV E, DV D and FV D as before …adding: We now need type environments: Type = { bool, int } Define static semantics (type checking rel’s): “ e has type  (given type environment  )” provided “ d yields type env.  (given type env.  )” provided FV E ( e ? e’: e” ) = FV E ( e )  FV E ( e’ )  FV E ( e” ) TEnv V = V  Type  |- V e :   |- V d :  FV E ( e )  V FV D ( d )  V

46 C LAUS B RABRAND [ 46 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics (expressions) Expressions: [ NUM ] E  |- V n : int  |- V t : bool [ TVL ] E [ VAR ] E  |- V x :  (x) [ VAR ] E  |- V ~ e : bool  |- V e : bool [ LET ] E  |- V let d in e :   |- V d :   [  ] |- V  DV{  } e :  [ IFE ] E  |- V e 0 ? e 1 : e 2 :   |- V e 0 : bool  |- V e 1 :  1  |- V e 2 :  2  = 1 =2 = 1 =2 [ BOP ] E  |- V e 0  e 1 : type  (  0,  1 )  |- V e 0 :  0  |- V e 1 :  1

47 C LAUS B RABRAND [ 47 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics (definitions) Definitions: [ NIL ] D  |- V nil : [] [ DEF ] D  |- V  x = e : [x  ]  |- V e :  ’  = ’ = ’ [ SEQ ] D  |- V d 0 ; d 1 :  0 [  1 ]  |- V d 0 :  0  [  0 ] |- V  DV{  0} d 1 :  1 [ AND ] D  |- V d 0 and d 1 :  0  1  |- V d 0 :  0  |- V d 1 :  1 [ IN ] D  |- V d 0 in d 1 :  1  |- V d 0 :  0  [  0 ] |- V  DV{  0} d 1 :  1 DV( d 0 )  DV( d 1 ) = Ø Note: combined environment Note: only last environment Note: disjoint environment Note: type check

48 C LAUS B RABRAND [ 48 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics: Let B ++ Type Environment (Compile-time): Type = { bool, int } Environment (Runtime): Val = B  Z, B = { tt, ff } Define type correspondence relation ‘~’: Note:  v  TEnv V = V  Type  v  Env V = V  Val  v ~  v   x  V:  v ( x ) = bool   v ( x )  B  v ( x ) = int   v ( x )  Z (  0 ~  0   1 ~  1 )   0 [  1 ] ~  0 [  1 ]

49 C LAUS B RABRAND [ 49 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exp. Transition System for Let B ++ Let++ Expression Configurations: Let B ++ Expression Configurations:   V  Type: Env  := i.e., “only type corresponding runtime environments”  V = { |   Env V  FV( e )  V  |- wfe e } T V = { |   Env V  z  Z } only well-formed exps   = { |   Env   FV( e )  V   :  |- V e :  } T  = { |   Env   r  B  Z } {   ( V  B  Z ) |  ~  }

50 C LAUS B RABRAND [ 50 ] S EMANTICS (Q1,’06) S EP 21, 2006 Def. Transition System for Let B ++ Let++ Definition Configurations: Let B ++ Definition Configurations:   V  Type: Env  := i.e., “only type corresponding runtime environments”  V = { |   Env V  FV( d )  V  |- wfd d } only well-formed defs T V = { |   Env V }   = { |   Env   FV( d )  V   :  |- V d :  } T  = { |   Env  } {   ( V  B  Z ) |  ~  }

51 C LAUS B RABRAND [ 51 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exp. Dynamic Semantics: Let B ++ SOS of Expressions for Let B ++: E.g. [LET]: - Basically substituting  for V (from dyn. sem. of Let++) [ LET 2 ] [ LET 3 ] [ LET 1 ]   Env   |- let d in e   let d’ in e  |- d   d’  |- let  0 in r   r  |- let  0 in e   let  0 in e’  [  0 ] |- e   [  0] e’ 0 ~ 00 ~ 0

52 C LAUS B RABRAND [ 52 ] S EMANTICS (Q1,’06) S EP 21, 2006 Def. Dynamic Semantics: Let B ++ SOS of Definitions for Let B ++: E.g [SEQ]: - Again, basically substituting  for V (from dyn. sem. of Let++) [ SEQ 2 ] [ SEQ 3 ] [ SEQ 1 ]  |- d 0 ; d 1   d 0 ’ ; d 1  |- d 0   d 0 ’  |-  0 ;  1    0 [  1 ]  |-  0 ; d 1    0 ; d 1 ’  [  0 ] |- d 1   [  0] d 1 ’   Env  0 ~ 00 ~ 0

53 C LAUS B RABRAND [ 53 ] S EMANTICS (Q1,’06) S EP 21, 2006 "Three minutes paper" Please spend three minutes writing down the most important things that you have learned today (now). After 1 day After 1 week After 3 weeks After 2 weeks Immediately

54 C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 Next week (CCS): Concurrency and Communication Any Questions?


Download ppt "C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © 2005--2006, University of Aarhus [ ] ["

Similar presentations


Ads by Google