1 / 16

Classi:

Classi:. variabili di istanza :. class Foo { public int x; public int y; public void swap (boolean z) { if (z) {int temp = x; x = y; y = temp;}; }; }. metodi: operazioni sugli oggetti. Ambienti per le classi: Cenv

Download Presentation

Classi:

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. Classi: variabili di istanza: class Foo { public int x; public int y; public void swap (boolean z) { if (z) {int temp = x; x = y; y = temp;}; }; } metodi: operazioni sugli oggetti Ambienti per le classi: Cenv Cenv = {Ide  Menv x  x Menv} c ={<Foo , (,{x->, y->} , m)>} m={<swap,<z,if(z){int temp=x; x=y;y=temp;}>>

  2. Oggetti: • istanze di classe • ogni oggetto una differente istanza: • istanze differiscono per:: • i valori nel frame • i metodi non cambiamo ({x->, y->} , m) Class Foo {....}; Foo obj1 = new Foo; Foo obj2 = new Foo; .... frame per obj1: 1 = {x->, y->} frame per obj2: 2 = {x->, y->} Heap per gli oggetti: Heap Heap = {Loc  Ide x }

  3. Valori, Classi e Oggetti: una vista grafica oj1 Foo oj2 b tt altri frames dello stato Fie  y x y x x y        Class Foo {public int x; public int y; public void swap (boolean z){ if (z) {int temp = x; x = y; y = temp;}; }; } Class Fie { public int y;} } Foo oj1 = new Foo; Fiepp oj2 = new Fie; boolean b = true; .... Foo L1 foo  L2 Fie fie  c Il Nuovo Stato: Class_Env x  x Heap < c ,  ,  >

  4. Sistema di transizioni per: Semantica dei Comandi S com={< com , Tcom , com } com= {<C ,<c ,, >| C Com,  , c Cenv,   Heap}  {<,>| , Heap} Tcom = {<,>| , Heap} com = {(=), ..., tutte le regole che vedremo }

  5. Comandi (nuova semantica) <E, <c ,  , > > expv (x)≠ <x=E; <c,,> > com <[v/x], > (=) <StmtList, <c , . , > > com < .’, ’> <{StmtList}, <c ,  , > > com <’, ’> <S, <c,,> > com<”,”> <StmtList , <c,”,”> com <’,’> <S StmtList , <c ,  , > > com <’, ’> (Block) (StmL)

  6. Condizionale <E , <c ,  , > > exp tt <C1,> cmd <’ ,’> <if(E) C1 else C2 , <c ,  , > > com <’, ’> <E , <c ,  , > > exp ff <C2,> cmd <’, ’> <if(E) C1 else C2 , <c ,  , > > com <’ ’> (if-tt) (if-ff)

  7. Iterazione (while) <E , <c ,  , > > exp ff <while(E) C, <c ,  , > > com< , > <E , <c ,  , > > exp tt <C, <c ,  , >> cmd<” ”> <while(E) C, <c, ”, ”> >com <’,’> <while(E) C, <c ,  , > > com<’,’> (W-ff) (W-tt)

  8. La sintassi del nucleo Progr::=prog {ClassDeclList {StmtList}} ClassDecl_List::=ClassDecl | ClassDecl ClassDeclList ClassDecl::=class Ide {StatMetDecList InstVarDecList MetDecList} InstVarDecList::=InstVarDec | InstVarDec InstVarDecList InstVarDec::=public Type Ide StmtList::= Stmt | Stmt StmtList Stmt::= Com | Decl Decl::= Type Ide | Type Ide= Exp; | Type ide = new Ide(); Type::= int | boolean | char | Ide Block::= {StmtList} Exp::= Ide.Ide | Ide | NumExp | BoolExp | Ide.Idem(Exp)

  9. La sintassi del nucleo MetDecList::= MetDec MetDecList |  MetDec::=public void Ide(T Ide){StmtList} StatMetDecList::= StatMetDec StaticMetDecList |  StatMetDec::=public static TypeR Ide(Type Ide){StmtList} TypeR::=Type | void Com::= Ide= Exp; | Ide.Ide=Exp; | Ide = new Ide(); | Block |Ide.Idem(Exp) | if (BoolExp) Com else Com; | while (BoolExp) Com;

  10. Esempio programma Java publicclass volume { publicstaticclass Foo { public int x ; public int y;} publicstaticclass Fie { public int x ;} publicstatic void main (String [ ] args) { Foo oj1=new Foo(); Fie oj2=new Fie(); oj1.x=5; oj1.y=oj1.x+4; oj2.x=oj1.x+oj1.y; }} prog{ class Foo { public int x; public int y;} class Fie { public int x;} {Foo oj1= new Foo(); Fie oj2= new Fie(); oj1.x=5; oj1.y=oj1.x+4; oj2.x=oj1.x+oj1.y;}}

  11. Semantica: il programma <ClassDeclList,  >classdeclc <StmtList,<c , . , >> com<,> <prog {ClassDecList {StmtList} }> classdecl<,> (prog)

  12. Semantica: classi <ClassDecl , c>  c’<ClassDecList , c’> c” <ClassDecl ClassDecList,c  c” <SMDL,>istdecls <InsVarDecLis, >istdecl <MetDefLis,>mdlm <class c {SMDL InsVarDecLis MetDefLis}, c>  c[< s,, m>/c] (classdeclList) (classdecl)

  13. Semantica: istanza e metodi d’istanza <public Typer m(Type x) B,s> s[<x,B>/m] <MetDef,s>  s’ < MetDefList , s’> s” < MetDef MetDefList,s  s” <public T x;, > istdecl [ /x] <InstVarDecl, >  ’ <InstVarDecList, ’ >  ” <InstVarDecl InstVarDecList,  >  ” (MetDef) (MDL) (instdecl) (instdeclist)

  14. Semantica: dichiarazioni di oggetti c(c) =< s,, m>l =newloc ( ) <new c(),<c,,>>  <l ,[<c,>/l]> <new c(),<c,,>>  <l ,’>= .’ <c x= new c(); <c,,>>  < [l /x]. ’,’> = .’ <c x;<c,,>>  < [null/x]. ’,> new (declnew) (declnonew)

  15. Semantica: assegnamento ed espressioni <new c(),<c,,>>  <l ,’> <x=new c();,<c,,>>  <  [l /x],’> <E,<c,,>> v  (o)=l(l)=<c, > ’= [v/x] <o.x= E; <c,,>>  <,[<c, ’/l ]>  (o)=l(l)=<c, > <o.x;<c,,>> (x) (com=new) (como.x=) exp o.x

  16. Semantica: metodi d’istanza invocazione (Ipotesi che le espressioni non modifichino lo stato) <Exp,<c,,>> v  (o)=l(l)=<c, ’> c(c)=< s,, m> m(m)=<x,B> <B, < c ,[l / this, v/x]. , > <’,’> <o.m(Exp);, <c,,>> <,’> invoc

More Related