110 likes | 176 Views
Ex.1 - Semantica dell’Assegnamento. Com := Path Ide = Expr (assegnamento) Com * Cenv * Heap * Astack com Heap * Astack * Cenv Una soluzione parziale: <e, r , z , s > expr <v, z ’, s ’>
E N D
Ex.1 - Semantica dell’Assegnamento • Com := Path Ide = Expr (assegnamento) • Com * Cenv * Heap * Astack com Heap * Astack * Cenv • Una soluzione parziale: • <e, r, z, s> expr <v, z’,s’> • top(s’) = (x, t) j = top(t) defined(j, i) j’=update (j, i, v) • s”=push(pop(s’),(x,push(pop(t), j’) • _________________________________________________ • <i = e, r, z, s> com < z’,r,s”> • Con 2 problemi: • update: frame*ide*val non è una funzione • discesa ricorsiva della struttura
Assegnamento: una soluzione Com := Path Ide = Expr (assegnamento) Com * Cenv * Heap * Astack com Heap * Astack * Cenv <p, met, r, z , s > path c <e, r, z, s> expr <v, z”, s”> <i, v, c, r, z”,s”> update<z’,r’,s’> _____________________________ <p i = e, r, z, s> com < z’,r’,s’> Ide * Val * (Ide | Loc | met) * Cenv * Heap * Astack update Heap * Astack * Cenv
Update: frame in s Ide * Val * (Ide | Loc | met) * Cenv * Heap * Astack update Heap * Astack top(s) = (x, t) j = top(t) defined(j, i) s’:update (j, i, v) __________________________________________________________ <i, v, met, r,z ,s> update < r,z ,s’> top(s) = (x, t) j = top(t) not defined(j, i) s’ =pop(s ) <i, v, met, r,z ,s’> update <r”,z”,s”> _____________________________________________ <i, v, met, r, z , s > update <r”,z”,s”> top(s) = (x, t) empty(t) <i, v, x, r, z , s > update <r’,z’,s’> _____________________________________________ <i, v, met, r, z , s > update <r’,z’,s’> Notazione: r’:update (j, i, v) indica che la modifica su j provoca la modifica del componente corrente in un nuovo componente r’
Update: frame in z Ide * Val * (Ide | Loc | met) * Cenv * Heap * Astack update Heap * Astack z(l) = (c, j, _) defined(j, i) z’: update (j, i, v) _____________________________________________ <i, v, l:Loc, r, z , s > update < r,z’,s > z(l) = (c, j, _) not defined(j, i) <i, v, c, r, z ,s> update <r,z’,s’> _____________________________________________ <i, v, l:Loc, r, z , s > update <r,z’, s’>
Update: frame in r Ide * Val * (Ide | Loc | met) * Cenv * Heap * Astack update Heap * Astack * Cenv r(c) = (c1, j, _, _, _) defined(j, i) r’:update (j, i, v) _____________________________________________ <i, v, c:Ide, r, z , s> update <r’,z,s> r(c) = (c1, j, _, _, _) not defined(j, i) <i, v, c1, r, z , s> update <r’,z’,s’> _____________________________________________ <i, v, c:Ide, r, z , s> update <r’,z’,s’>
Ex.2 - this.this: applichiamo le regole top(s) = (o, _) ____________________________ <this., met, r, z , s > path o top(s) = (o, _) ____________________________ <this, met, r, z , s > naming o p’=o=met Ma: o≠met <P, met,r, z ,s > path p’ <o, p’, r, z , s > naming v ___________________________________________________ <P o, r, z , s > expr<v, z >
Ex.3 - Comando Return: semantica Com := return (terminazione valutazione) Com * Cenv * Heap * Astack com Heap * Astack * Cenv top(s) = (x, t) _____________________________________ <return, r, z, s> com <z’, pop(s), r’>
Ex.4 - Return: semantica come espressione Expr := return e Expr * Cenv * Heap * Astack expr Val * Heap (* Astack) <e, r, z ,s > expr <v, z’> _______________________________________ <return e, r, z , s > expr<v, z’,pop(s)>
Ex.5 - Un programma: semantica public class A{ public static int x; public int y; public void P1(int y){ this.y=y+x; x=P2(this); } public int P2(A z){ z.y = y+ A.x; return x; } public A(){ x = 7; y = x; }} class B extends A{ public static int z; public static int w; public int P2(A z){ z.x = y + w; return B.z; } public B(){ z = x+1; w = 0; }} class Princ{ public static void main(String[] args){ B o = new B(); int m = o.P2(o); }}
Parte dinamica: Astack r, heap z • struttura iniziale: • <emptystack() - free> • il primo record di attivazione • … graficamente • valutando espressione new B() • … graficamente