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)

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
6.2 © and ® 2011 Vista Higher Learning, Inc There are many ways to express negation (la negazione) in Italian. The simplest way is to place the.
Laboratorio di Linguaggi lezione X Marco Tarini Università dellInsubria Facoltà di Scienze Matematiche, Fisiche e Naturali di Varese Corso di Laurea in.
7878 1,3 8 1,3 4 1,3 4,6 1,3 7,8 1,3 4,5 6 4,5 6 7,8 7 4,6 5,6 7,8 5,6 4 I cicli grigio e verdino sono semplici, quello bianco no Ogni operazione è assegnata.
2000 Prentice Hall, Inc. All rights reserved Oggetti const e funzioni membro const 2. Composizione: oggetti come membri di classi 3. Funzioni friend.
2000 Prentice Hall, Inc. All rights reserved. 1 Capitolo 8 – Overloading di operatori 1.Introduzione 2.Fondamenti sulloverloading di operatori 3.Restrizioni.
His Life… Graduated from Now working for Ci è niente di più difficile prendere a disposizione, più perilous a comportamento, o più incerto nel relativo.
JDBC. Eseguire una query String query = "SELECT * FROM COFFEES"; Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while.
For(int i = 1; i
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1 OCAML §nucleo funzionale puro l funzioni (ricorsive) l tipi e pattern matching l primitive utili: liste l trascriviamo pezzi della semantica denotazionale.
Closures & Environments CS153: Compilers Greg Morrisett.
LYNBROOK COMPUTER SCIENCE CLUB MONDAY, OCTOBER 26, 2009 POWERPOINT CREATED BY: RITIK MALHOTRA PRESENTATION BY: KARTHIK VISWANATHAN Intro to USACO.
SFTW241 Group A4 Presentation of Grouping Process.
Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
Lab 8 User Defined Function.
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
Algebraic Optimization CS153: Compilers Greg Morrisett.
INF 3110/ INF INF Oppgave 6.7 Grammar RuleSemantic Rule decl → var-list : type var-list 1 → var-list 2 ; id var-list.
Dr. Faiyaz Gadiwalla Hinduja College. Q 2 A) a) Wages calc. b) Sort c) Output Q3 A) a) Series b) Display result c) Output.
Date: in 12 pts 28 th Meeting EQF Advisory Group Brussels 2 -3 December 2014.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 7 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE WITH ENVIRONMENTS : INTERPRETATION.
CS 140 Lecture 8 Professor CK Cheng 4/26/02. Part II. Sequential Network 1.Memory SR, D, T, JK, 2.Specification S XY s i t+1 = g i (S t, X t )
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Stacks.
1 OCAML nucleo funzionale puro – funzioni (ricorsive) – tipi e pattern matching – trascriviamo pezzi della semantica operazionale – primitive utili: liste.
Ingegneria del software Modulo 1 -Introduzione al processo software Unità didattica 3 - Modelli di fase d’analisi Ernesto Damiani Università degli Studi.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Lesson 3 Two topics 1. Semantic Analysis 2. Translation to intermediate code Presented as separated topics but can be implemented together.
Cs7100(Prasad)L8Proc1 Procedures. cs7100(Prasad)L8Proc2 Primitive procedures  etc User-defined procedures –Naming a sequence of operations.
$100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 $100 $200 $300.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
Vaughan Knight Vaughan Knight Bit
CSE-321 Programming Languages (So Many Topics) POSTECH May 29, 2006 박성우.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Class Method Read class Student { private: string id; string firstName, lastName; float gpa; public: // Will the method change any data members? // Yes!
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Scanning & Regular Expressions CPSC 388 Ellen Walker Hiram College.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
CSE 3341/655; Part 3 35 This is all very wrong! What would the SW1/SW2 (RESOLVE) people say if they saw this? Problem: Lack of data abstraction; What would.
8/2/00SEM107- © Kamin and ReddyClass 5 - Lists - 1 Class 5 - Lists r The list data type r Recursive methods on lists.
1 Advanced Programming Examples. using System; class Test { static void Main( string[] args ) { int a = 7; int b = 3; int c = 5; int d = 9; Console.WriteLine(!(d.
Quiz
Comparative and superlative adjectives
Sum of natural numbers class SumOfNaturalNumbers {
Core Core: Simple prog. language for which you will write an interpreter as your project. First define the Core grammar Next look at the details of how.
. - t !!l t. - 1f1f J - /\/\ - ' I __.
CS 1430: Programming in C++.
CS 1430: Programming in C++.
Semantics of PLs via Interpreters: Getting Started
Default Argument.
TO COMPLETE THE FOLLOWING:
Stack Memory 2 (also called Call Stack)
Quality in statistics: the BR case
Lecture 10.
Data validation in the 2006/2007 data collection
.. '.. ' 'i.., \. J'.....,....., ,., ,,.. '"'". ' · · f.. -··-·· '.,.. \...,., '.··.. ! f.f.
State of legal transposition (1)
Early Denver Model Curriculum Checklist- Versione modificata
Standard Input/Output Stream
Recursive GCD Demo public class Euclid {
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
If Statements.
class PrintOnetoTen { public static void main(String args[]) {
Main() { int fact; fact = Factorial(4); } main fact.
Recursion Yikes!. Recursion Yikes! What is this? RACECAR.
EXP file structure.
Presentation transcript:

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.

Funzioni di Semantica Statica [_] s Prog :L Prog (LW) P {*} [_] s Decs :L Decs (LW) Env s Env s P Env s [_] s Dec :L Dec (LW) Env s Env s P Env s [_] s Dec (d,, l ) = [_] s Decs (d,, l ) [_] s VDec :L VDec (LW) Env s Env s P Env s [_] s VDec (d,, l ) = [_] s Decs (d,, l ) [_] s PDecs :L PDecs (LW) Env s Env s P Env s [_] s PDecs (d,, l ) = [_] s Decs (d,, l ) [_] s PDec :L PDec (LW) Env s Env s P Env s [_] s PDec (d,, l ) = [_] s Decs (d,, l ) [_] s FDec :L FDec (LW) Env s Env s P Env s [_] s FDec (d,, l ) = [_] s Decs (d,, l ) [_] s Stats :L Stats (LW) Env s P {*} [_] s Stat :L Stat (LW) Env s P {*} [_] s Stat (st, ) = [_] s Stats (st, ) [_] s Exp :L Exp (LW) Env s P Types [_] s Exp (e, ) = [_] s Exps (e, ) [_] s Exps :L Exps (LW) Env s P Types + Env s = [L Id (LW) P Types] Fin, dove Types = BTypes (BTypes + RTypes), dove BTypes = {int, bool} e RTypes = BTypes {void} Notazione per funzioni parziali a dominio finito f [X P A] Fin se f è [], Dom(f) = Ø se f è [a 1 /x 1,…, a n /x n ] con tutte le x i distinte, Dom(f) = {x 1,…,x n } e f(x i )=(a i ) 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)

Regole della Sem. Statica per Decs [d] s ( l ) = loc [ds] s ( loc ) = 0 _____________________________________________________ [d ds] s ( l ) = 0 [e] s ( l )=t _________________________________ id Dom( l ) [t id = e;] s ( l ) = l [t/id] ______________________________ id Dom( l ) [t id;] s ( l ) = l [t/id] [pl] ( l ],[(lt,void)/f]) = loc [sts] ( l ] loc ]) = * lt=types(pl) __________________________________________________________________ f Dom( l ) [void f(pl) {sts}] ( l ) = l [(lt,void)/f] [pl] ( l ],[(lt,t)/f]) = loc [sts] ( l ] loc ]) = * [e] ( l ] loc ]) = tlt=types(pl) _____________________________________________________________________________________ f Dom( l ) [t f(pl) {sts result e}] ( l ) = l [(lt,t)/f]t void [pl] ( l ],[(lt,t)/f]) = loc [ds] ( l ], loc ) = loc [sts] ( ) = * [e] ( ) = t lt=types(pl) __________________________________________________________________________________________ f Dom( l ) [t f(pl) {with ds do sts result e}] ( l ) = l [(lt,t)/f] = l ] loc ] t void [pl] ( l ],[(lt,void)/f]) = loc [ds] ( l ], loc ) = loc [sts] ( ) = *lt=types(pl) ________________________________________________________________________________ f Dom( l ) [void f(pl) {with ds do sts}] ( l ) = l [(lt,void)/f] = l ] loc ]

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

Funzioni di Semantica Denotazionale [_] Prog :L Prog (LW) Input P Output [_] Decs :L Decs (LW) Env States P Env States [_] Dec :L Dec (LW) Env States P Env States [_] Dec (d,r,s) = [_] Decs (d,r,s) [_] VDec :L VDec (LW) Env States P Env States [_] VDec (d,r,s) = [_] Decs (d,r,s) [_] PDecs :L PDecs (LW) Env States P Env States [_] PDecs (d,r,s) = [_] Decs (d,r,s) [_] PDec :L PDec (LW) Env States P Env States [_] PDec (d,r,s) = [_] Decs (d,r,s) [_] FDec :L FDec (LW) Env States P Env States [_] FDec (d,r,s) = [_] Decs (d,r,s) [_] Type :L Type (LW) Set [_] Stats :L Stats (LW) Env States P States [_] Stat :L Stat (LW) Env States P States [_] Stat (st,r,s) = [_] Stats (st,r,s) [_] Exp :L Exp (LW) Env States P Value States [_] Exp (e,r,s) = [_] Exps (e,r,s) [_] Exps :L Exps (LW) Env States P Value + States Env = [L Id (LW) p Fun Loc ] Fin, dove Loc = T BTypes Loc T Fun = [Arg p Res], 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))

Regole della Sem. Denot. per Decs 1 ____________________________________________ [RT f(T x) {[with ds do]sts return e}](r,s) = (r[F/f],s) ______________________________________ [void f(T x) {[with ds do]sts}](r,s) = (r[F/f],s) F è definita induttivamente da tutte le regole della semantica più le seguenti 2 A [A w se cè il with] e B, per leggibilità riportate nel riquadro [sts] (r[ /f,l x /x],s c [v/l x ] ) = s A _____________________________________ Nuova(l x,r,s c ) F(v,s c ) = ( *,s\{l x }) [e](r 0 [ /f],s 0 ) = (u,s) F(u,s) = ( *,s) B __________________________________________________ [f(e)] (r 0 [ /f],s 0 ) = ( *,s) [ds](r[ /f,l x /x],s c [v/l x ] ) = r 1,s 1 [sts] (r 1,s 1 ) = s A w ________________________________________________________ Nuova(l x,r,s c ) F(v,s c ) = ( *,s\{l x }) F è definita induttivamente da tutte le regole della semantica più le seguenti 2 A [A w se cè il with] e B, per leggibilità riportate nel riquadro [sts] (r[ /f,l x /x],s c [v/l x ] ) = s 1 [e](r [ /f,l x /x],s 1 ) = (u,s) A ________________________________________________________ Nuova(l x,r,s c ) F(v,s c ) = (u,s\{l x }) [e](r 0 [ /f],s 0 ) = (v,s) F(v,s) = (u,s) B __________________________________________________ [f(e)] (r 0 [ /f],s 0 ) = (u,s) [ds](r[ /f,l x /x],s c [v/l x ] ) = r 1,s 1 [sts] (r 1,s 1 ) = s 2 [e](r 1,s 2 ) = (u,s) A w _____________________________________________________________________________ Nuova(l x,r,s c ) F(v,s c ) = (u,s\{l x })

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

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) ___________________________________ [ while (e) {sts} ] (r,s) = s [e](r,s) = (tt,s) [sts] (r,s) = s [ while (e) {sts} ] (r,s) = s 0 ___________________________________________________________________________________ [ while (e) {sts} ] (r,s) = s 0 [e](r,s) = (ff,s) [sts] (r,s) = s ____________________________________________ [ if (e) {sts} else {sts} ] (r,s) = s [ds]([],(i,,[])) = (r,s) [sts] (r,s) = (i,o,m) __________________________________________________________ [ ds main() sts ] (i) = o