1 / 11

Ex.1 - Semantica dell’Assegnamento

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 ’>

danno
Download Presentation

Ex.1 - Semantica dell’Assegnamento

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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

  3. 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’

  4. 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’>

  5. 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’>

  6. 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 >

  7. 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’>

  8. 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)>

  9. 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); }}

  10. Parte statica: ambiente r

  11. Parte dinamica: Astack r, heap z • struttura iniziale: • <emptystack() - free> • il primo record di attivazione • … graficamente • valutando espressione new B() • … graficamente

More Related