Sintassi: Programma e classi - PowerPoint PPT Presentation

About This Presentation
Title:

Sintassi: Programma e classi

Description:

Title: Nucleo di Java: Struttura e Semantica Author: Eugenia Occhiuto Last modified by: Eugenia Occhiuto Created Date: 10/25/2004 12:05:18 PM Document presentation format – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 12
Provided by: Eugen165
Category:

less

Transcript and Presenter's Notes

Title: Sintassi: Programma e classi


1
Sintassi Programma e classi
Programprog ClassDeclList StatList ClassDec
lListClassDecl ClassDeclList
? ClassDeclclass Idec StaticMetDefList Static
MetDefListStaticMetDef StaticMetDefList
? StaticMetDefpublic static TypeR Idem (Type
Idea) StatList Command ...
Idec.Idem(Exp) ... Exp... Idec.Idem(Exp)
TypeR Type void Typeint
boolean ...
2
Esempio
programma nel linguaggio didattico
programma Java
prog class Num public static int fact
(int p) if (p0) return 1
else return p fact(p-1) int y int x5
if (xgt0) yNum.fact(x)
public class Num public static int fact (int p)
if (p0) return 1 else
return p fact(p-1) public static void main
(String args) int y int x5 if
(xgt0) yNum.fact(x)
3
Classi
metodi statici main e operazioni di uso
generale
class Num public static int fact (int p)
if (p0) return 1 else return
pfact(p-1) public static void main
(String args)...
Ambienti delle classi Cenv Cenv Ide
? Menv x ? x Menv Menv Ide ? Ide x Block
?c Num -gt lt?s , ?, ?gt ?s fact -gt ltp, if
(p0) ... gt, main -gt ltargs,..gt
Il Nuovo Stato Cenv x ?
4
Sistema di transizioni per Semantica dei Comandi
S comlt ?com , Tcom , ?com ?com ltC ,lt?c ,?gt
C ?Com, ? ??, ?c? Cenv ? lt?gt? ??
Tcom lt?gt? ?? ?com (), ..., tutte le
regole che vedremo
5
Semantica il programma
ltClassDeclList , ? gt?classdecl ?c
ltStatList,lt?c , ?. ? gtgt ?com ?
ltprog ClassDeclList StatList
gt ?prog ?

(prog)
6
Semantica classi
ltClassDecl , ?cgt ? ?c
ltClassDelList , ?cgt ? ?c
ltClassDecl
ClassDeclList, ?c ? ?c lt
StaticMetDefList, ?gt ?cmd ?s
ltclass c StaticMetDefList, ?c gt ? ?c lt ?s, ?,
? gt/c
(classdecllist)
(classdecl)
7
Semantica metodi statici (che non calcolano un
risultato)

ltpublic static Typer m(Type x) B, ?sgt ?
?sltx,Bgt/m
ltStaticMetDef,?sgt ? ?s lt StaticMetDefList , ?sgt
? ?s lt
StaticMetDef StaticMetDefList, ?s ? ?s
(SMD)
(SMDLl)
8
Semantica metodi statici (che non calcolano un
risultato) invocazione

ltExp,lt?c,?gtgt ? v ?c(ideC)lt ?s ,?, ?mgt
?s(m)ltx,Bgt ltB, lt ?c ,?v/x.?gtgt ??
ltideC.m(Exp), lt?c,? gtgt ? ?
invoc
9
Ambiente del metodo(ovvero Identificatori noti
nel metodo)
  • Si desume dallo stato di valutazione del Blocco
    corpo del metodo, e cioè
  • lambiente delle classi ?c
  • lo stack contenente il(i) parametro(i) ?v/x.?
    f
  • La politica di scoping di Java è statica e
    pertanto le variabli definite nello stato di
    invocazione del metodo risultano NON accessibili.
  • Linguaggi in cui, invece, le variabili definite
    nello stato di invocazioni sono accessibili sono
    linguaggi a scoping dinamico. Linguaggi a scoping
    dinamico esistono anche se non sono molto
    diffusi (Lisp), perchè di difficile comprensione

10
Semantica metodi statici (che calcolano un
risultato)

ltExp,lt?c,?gtgt ? v ?c(ideC)lt ?s ,?, ?mgt
?s(m)ltx,Bgt ltB, lt ?c ,?v/x, ? /retVal.?gt
?? ltideC.m(Exp), lt?c,?
gtgt ? ? (retVal) ltExp,lt?c,?gtgt ? v
ltreturn Exp,lt?c,?gtgt ? ?v/retVal
invoc (Exp)
(return)
11
Espressioni semantica
ltE, ltr,sgt gt?exp b ltE, ltr,sgt gt
?exp b b op b b
ltE op E, ltr,sgt gt ?exp b
ltE, ltr,sgt gt?exp b ltE, ltr,sgt gt ?exp b
b b b
ltE E, ltr,sgt gt ?exp b ltE,
ltr,sgt gt ?exp b ltE, s gt ?exp b b b
b ltE
E, ltr,sgt gt?exp b ltE, ltr,sgt gt ?exp
b not b b s(x) b ! E ?exp b
ltx, ltr,sgt gt
?exp b lttrue, ltr,sgt gt ?exp tt
ltfalse, ltr,sgt gt ?exp ff
(BEop)
(B)
(B)
(B())
(B!)
(BIde)
(Btrue)
(Btrue)
(Bfalse)
Write a Comment
User Comments (0)
About PowerShow.com