1 / 8

LW - Grammatica CF

LW - Grammatica CF. Prog ::= Decs main () Stats. Decs ::= Dec | Dec Decs. Dec ::= VDec | FDec. VDec ::= PDec | Type Id = Exp; PDec ::= Type Id; FDec ::= Type Id(PDecs) {[ with Decs do ] Stats result Exp} | void Id(PDecs) {[ with Decs do ] Stats} PDecs ::= PDec | PDec PDecs.

milla
Download Presentation

LW - Grammatica CF

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. LW - Grammatica CF Prog ::= Decs main() Stats. Decs ::= Dec | Dec Decs. Dec ::= VDec | FDec. VDec ::= PDec | Type Id = Exp; PDec ::= Type Id; FDec ::= Type Id(PDecs) {[with Decs do] Stats result Exp} | void Id(PDecs) {[with Decs do] Stats} PDecs ::= PDec | PDec PDecs. Type ::= int | bool. Stats ::= Stat | Stat Stats. Stat ::= Exp; | while (Exp) {Stats} | if (Exp) {Stats} else {Stats}| ?Id | !Exp. Exp ::= Id | Id = Exp | Id(Exps) | Exp + Exp | … Exps ::= Exp | Exp Exps.

  2. Funzioni di Semantica Statica [_]sProg : LProg(LW) P {*} [_]sDecs : LDecs(LW)  Envs  Envs PEnvs [_]sDec : LDec(LW)  Envs  Envs PEnvs [_]sDec(d,r,rl) = [_]sDecs(d,r,rl) [_]sVDec : LVDec(LW)  Envs  Envs PEnvs [_]sVDec(d,r,rl) = [_]sDecs(d,r,rl) [_]sPDecs : LPDecs(LW)  Envs  Envs PEnvs [_]sPDecs(d,r,rl) = [_]sDecs(d,r,rl) [_]sPDec : LPDec(LW)  Envs  Envs PEnvs [_]sPDec(d,r,rl) = [_]sDecs(d,r,rl) [_]sFDec : LFDec(LW)  Envs  Envs PEnvs [_]sFDec(d,r,rl) = [_]sDecs(d,r,rl) [_]sStats : LStats(LW)  Envs P {*} [_]sStat : LStat(LW)  Envs P {*} [_]sStat(st,r) = [_]sStats(st,r) [_]sExp : LExp(LW)  Envs P Types [_]sExp(e,r) = [_]sExps(e,r) [_]sExps : LExps(LW)  Envs P Types+ Envs = [LId(LW) PTypes]Fin, dove Types = BTypes  (BTypes+ RTypes), dove BTypes = {int, bool} e RTypes = BTypes  {void} Notazione per funzioni parziali a dominio finito f[X PA]Fin se f è [], Dom(f) = Ø se f è [a1/x1,…, an/xn] con tutte le xidistinte, Dom(f) = {x1,…,xn } e f(xi)=(ai ) se f è g[a/x], Dom(f) = Dom(g) {x} e f(x)= g(x) se x  x, altrimenti f(x)=a se f è g[h], Dom(f) = Dom(g)Dom(h) e f(x)= h(x) se x Dom(h), altrimenti f(x)= g(x) se f è g\X, Dom(f) = Dom(g)\X e f(x)= g(x)

  3. Regole della Sem. Statica per Decs [d]s(r, rl) = rloc [ds]s(r, rloc) = r0 _____________________________________________________ [d ds]s(r, rl) = r0 [e]s(r[rl])=t _________________________________ idDom(rl) [t id = e;]s(r,rl) = rl[t/id] ______________________________ idDom(rl) [t id;]s(r,rl) = rl[t/id] [pl](r[rl],[(lt,void)/f]) = rloc[sts](r[rl] [rloc]) = * lt=types(pl) __________________________________________________________________ fDom(rl) [void f(pl) {sts}](r,rl) = rl[(lt,void)/f] [pl](r[rl],[(lt,t)/f]) = rloc[sts](r[rl] [rloc]) = * [e](r[rl] [rloc]) = t lt=types(pl) _____________________________________________________________________________________ fDom(rl) [t f(pl) {sts result e}](r,rl) = rl[(lt,t)/f] t ≠ void [pl](r[rl],[(lt,void)/f]) = rloc[ds](r[rl], rloc) = r’loc[sts](r”) = * lt=types(pl) ________________________________________________________________________________ fDom(rl) [void f(pl) {with ds do sts}](r,rl) = rl[(lt,void)/f]r” = r[rl] [r’loc] [pl](r[rl],[(lt,t)/f]) = rloc[ds](r[rl], rloc) = r’loc[sts](r”) = * [e](r”) = t lt=types(pl) __________________________________________________________________________________________ fDom(rl) [t f(pl) {with ds do sts result e}](r,rl) = rl[(lt,t)/f]r” = r[rl] [r’loc] t ≠ void

  4. Regole della Sem. Statica per Exps, Stats e Prog [e]s(r) = t[es]s(r) = lt ____________________________________ [e es]s(r) = t lt ________________________ id Dom(r) [id]s (r) = r(id) r(id) BTypes [e]s(r) = t __________________________ r(id) = t [id = e]s (r) = t [es](r) = lt _____________________ r(id) = (lt,t) [id(es)](r) = t [e1](r) = int [e2](r) = int ____________________________________ [e1+ e2](r) = int etc... [e]s(r) = t ________________ [e;]s (r) = * [e]s(r) = bool [sts]s (r) = * _________________________________________ [while (e) {sts}]s (r) = * [e]s(r) = t ________________ [!e]s (r) = * ____________________ r(id)  BTypes [?id]s (r) = * [e]s(r) = bool [sts1]s (r) = * [sts2]s (r) = * ______________________________________________________________ [if (e) {sts1} else{sts2} ]s (r) = * [ds]([],[]) = r [sts]s(r) = * ________________________________________________ [ds main() sts]s (r) = *

  5. Funzioni di Semantica Denotazionale [_]Prog : LProg(LW)  InputP Output [_]Decs : LDecs(LW)  Env States PEnv States [_]Dec : LDec(LW)  Env States PEnv States [_]Dec(d,r,s) = [_]Decs(d,r,s) [_]VDec : LVDec(LW)  Env States PEnv States [_]VDec(d,r,s) = [_]Decs(d,r,s) [_]PDecs : LPDecs(LW)  Env States PEnv States [_]PDecs(d,r,s) = [_]Decs(d,r,s) [_]PDec : LPDec(LW)  Env States PEnv States [_]PDec(d,r,s) = [_]Decs(d,r,s) [_]FDec : LFDec(LW)  Env States PEnv States [_]FDec(d,r,s) = [_]Decs(d,r,s) [_]Type:LType(LW)  Set [_]Stats : LStats(LW)  Env States PStates [_]Stat : LStat(LW)  Env States PStates [_]Stat(st,r,s) = [_]Stats(st,r,s) [_]Exp : LExp(LW)  Env States P Value States [_]Exp(e,r,s) = [_]Exps(e,r,s) [_]Exps : LExps(LW)  Env States P Value+ States Env = [LId(LW) p FunLoc]Fin, dove Loc = TBTypesLocT Fun = [Arg pRes], Arg = [Z| B]+  States e Res = [Z| B|{*}]  States States = Input  Output  [Loc p Value]Fin, dove Value = TBTypes[T] e [int] = Z, [bool] = B, [void] = {*} Input = Output = Value* Nuova  Loc  Env  States definito da Nuova(l,r,s) sse l (Im(r)  Dom(s))

  6. Regole della Sem. Denot. per Decs 1 F è definita induttivamente da tutte le regole della semantica più le seguenti 2 A [Aw se c’è il with] e B, per leggibilità riportate nel riquadro ______________________________________ [void f(T x) {[with ds do]sts}](r,s) = (r[F/f],s) [sts](r[/f,lx/x],sc[v/lx] ) = s’ A _____________________________________ Nuova(lx,r,sc) F(v,sc) = (*,s’\{lx}) [e](r0[/f],s0) = (u ,s’) F(u,s’) = (*,s”) B __________________________________________________ [f(e)](r0[/f],s0) = (*,s”) [ds](r[/f,lx/x],sc[v/lx] ) = r1,s1 [sts](r1,s1) = s’ Aw________________________________________________________ Nuova(lx,r,sc) F(v,sc) = (*,s’\{lx}) F è definita induttivamente da tutte le regole della semantica più le seguenti 2 A [Aw se c’è il with] e B, per leggibilità riportate nel riquadro ____________________________________________ [RT f(T x) {[with ds do]sts return e}](r,s) = (r[F/f],s) [sts](r[/f,lx/x],sc[v/lx] ) = s1 [e](r [/f,lx/x],s1) = (u ,s’) A ________________________________________________________ Nuova(lx,r,sc) F(v,sc) = (u,s’\{lx}) [ds](r[/f,lx/x],sc[v/lx] ) = r1,s1 [sts](r1,s1) = s2 [e](r1,s2) = (u ,s’) Aw_____________________________________________________________________________ Nuova(lx,r,sc) F(v,sc) = (u,s’\{lx}) [e](r0[/f],s0) = (v ,s’) F(v,s’) = (u,s”) B __________________________________________________ [f(e)](r0[/f],s0) = (u,s”)

  7. Regole della Sem. Denot. per Decs ed Exps [d](r,s) = (r’,s’) [ds](r’,s’) = (r”,s”) ___________________________________________________ [d ds] (r,s) = (r”,s”) [e](r,s) = (v,s’) ______________________________________ Nuova(l,r,s’) [t x = e](r,s) = (r[l/x],s’[v/l]) lLocT ________________________________ Nuova(l,r,s) [t x](r,s) = (r[l/x],s[/l]) lLocT [e](r,s) = (v,s’) [es](r,s’) = (lv,s”) ___________________________________________________ [e es] (r,s) = (v lv,s”) [e](r,s) = (v,s’) ______________________________________ [x = e](r,s) = (v,s’[v/r(x)]) [es](r,s) = (lv ,s’) ______________________________ [f(es)](r,s) = r(f)(lv,s’) ___________________________r(x) Loc [x](r,s) = (s(r(x)),s) [e](r,s) = (v,s’) [e’](r,s’) = (v’,s”) __________________________________________________ v + v’ = a [e + e’] (r,s) = (a,s”) etc...

  8. Regole della Sem. Denot. per Stats e Prog [st](r,s) = s’ [sts](r,s’) = s” __________________________________________ [st sts ] (r,s) = s” [e](r,s) = (v ,s’) _______________________ [e;](r,s) =s’ [e](r,s) = (tt ,s’) [sts](r,s’) = s” ____________________________________________ [if (e) {sts} else {sts’}](r,s) = s” [e](r,s) = (ff ,s’) [sts’](r,s’) = s” ____________________________________________ [if (e) {sts} else {sts’}](r,s) = s” [e](r,s) = (ff ,s’) ___________________________________ [while (e) {sts}](r,s) = s’ [e](r,s) = (tt ,s’) [sts](r,s’) = s” [while (e) {sts}](r,s”) = s0 ___________________________________________________________________________________ [while (e) {sts}](r,s) = s0 [ds]([],(i,l,[])) = (r ,s) [sts](r,s) = (i’,o,m) __________________________________________________________ [ds main() sts](i) = o

More Related