27
Introduction ` a la S´ emantique Luigi Santocanale Laboratoire d’Informatique Fondamentale, Centre de Math´ ematiques et Informatique, 39, rue Joliot-Curie - F-13453 Marseille Luigi Santocanale Introduction ` a la S´ emantique 1

Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Introduction a la Semantique

Luigi Santocanale

Laboratoire d’Informatique Fondamentale,Centre de Mathematiques et Informatique,

39, rue Joliot-Curie - F-13453 Marseille

Luigi Santocanale Introduction a la Semantique 1

Page 2: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Plan

1 Exemples

Luigi Santocanale Introduction a la Semantique 2

Page 3: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Introduction a la Semantique

Luigi Santocanale

Laboratoire d’Informatique Fondamentale,Centre de Mathematiques et Informatique,

39, rue Joliot-Curie - F-13453 Marseille

Luigi Santocanale Introduction a la Semantique 3

Page 4: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Plan

1 Exemples

Luigi Santocanale Introduction a la Semantique 4

Page 5: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Premier exemple (langage C)

x = STARTX ; y = STARTY ; z=0;if(x) {

y+=2;while(x){

for(;y;y--) z++;x--;y+=2;

}}

Valeur de z a la ligne 18 ?

Luigi Santocanale Introduction a la Semantique 5

Page 6: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Solution

Valeur de z :STARTY + 2*STARTX (STARTX > 0, STARTY >= 0)

Le code est equivalent a :

x = STARTX ; y = STARTY ; z=0;for(x = STARTX;x != 0;x--)

for(y+=2;y != 0;y--) z++;y+=2;

Luigi Santocanale Introduction a la Semantique 6

Page 7: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Solution

Valeur de z :STARTY + 2*STARTX (STARTX > 0, STARTY >= 0)

Le code est equivalent a :

x = STARTX ; y = STARTY ; z=0;for(x = STARTX;x != 0;x--)

for(y+=2;y != 0;y--) z++;y+=2;

Luigi Santocanale Introduction a la Semantique 6

Page 8: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – I

Test sur la condition booleenne :

if( x ) -> if( x != 0 )

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

y+=2;while(x != 0){

for(;y != 0;y--) z++;x--;y+=2;

}}

Luigi Santocanale Introduction a la Semantique 7

Page 9: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – I

Test sur la condition booleenne :

if( x ) -> if( x != 0 )

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

y+=2;while(x != 0){

for(;y != 0;y--) z++;x--;y+=2;

}}

Luigi Santocanale Introduction a la Semantique 7

Page 10: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – II

(( Rolling )) :

c1; while(cond){while(cond ){ -> c1;c2;

c2;c1; }} c1;

Luigi Santocanale Introduction a la Semantique 8

Page 11: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – II

(( Rolling )) :

c1; while(cond){while(cond ){ -> c1;c2;

c2;c1; }} c1;

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

y+=2;while(x != 0){

for(;y != 0;y--) z++;x--;y+=2;

}}

Luigi Santocanale Introduction a la Semantique 8

Page 12: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – II

(( Rolling )) :

c1; while(cond){while(cond ){ -> c1;c2;

c2;c1; }} c1;

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

while(x != 0){y+=2;for(;y != 0;y--) z++;x--;

}y+=2;

}

Luigi Santocanale Introduction a la Semantique 8

Page 13: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – III

Initialisation boucle for :

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

while(x != 0){y+=2;for(;y != 0;y--) z++;x--;

}y+=2;

}

Luigi Santocanale Introduction a la Semantique 9

Page 14: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – III

Initialisation boucle for :

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

while(x != 0){for(y+=2;y != 0;y--) z++;x--;

}y+=2;

}

Luigi Santocanale Introduction a la Semantique 9

Page 15: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – IV

Simplification while :

if(condition ) while(condition)while(condition ) -> command;

command;

Luigi Santocanale Introduction a la Semantique 10

Page 16: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – IV

Simplification while :

if(condition ) while(condition)while(condition ) -> command;

command;

x = STARTX ; y = STARTY ; z=0;if(x != 0) {

while(x != 0){for(y+=2;y != 0;y--) z++;x--;

}y+=2;

}

Luigi Santocanale Introduction a la Semantique 10

Page 17: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – IV

Simplification while :

if(condition ) while(condition)while(condition ) -> command;

command;

x = STARTX ; y = STARTY ; z=0;while(x != 0){

for(y+=2;y != 0;y--) z++;x--;

}y+=2;

Luigi Santocanale Introduction a la Semantique 10

Page 18: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – V

Simplification while -> for :

Luigi Santocanale Introduction a la Semantique 11

Page 19: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – V

Simplification while -> for :

x = STARTX ; y = STARTY ; z=0;while(x != 0){

for(y+=2;y != 0;y--) z++;x--;

}y+=2;

Luigi Santocanale Introduction a la Semantique 11

Page 20: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – V

Simplification while -> for :

x = STARTX ; y = STARTY ; z=0;for(;x != 0;x--)

for(y+=2;y != 0;y--) z++;y+=2;

Luigi Santocanale Introduction a la Semantique 11

Page 21: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Transformations – V

Simplification while -> for :

x = STARTX ; y = STARTY ; z=0;for(x = STARTX;x != 0;x--)

for(y+=2;y != 0;y--) z++;y+=2;

Luigi Santocanale Introduction a la Semantique 11

Page 22: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Deuxieme exemple (langages fonctionnels)

Transformation code fonctionnel enforme recursive terminale.

let rec length = function[] -> 0

| testa ::coda -> 1 + length coda;;

let length l =let rec

length_acc lista acc = match lista with[] -> acc

| testa::coda -> length_acc coda (acc + 1)in

length_acc l 0;;

Luigi Santocanale Introduction a la Semantique 12

Page 23: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Deuxieme exemple (langages fonctionnels)

Transformation code fonctionnel enforme recursive terminale.

let rec length = function[] -> 0

| testa ::coda -> 1 + length coda;;

let length l =let rec

length_acc lista acc = match lista with[] -> acc

| testa::coda -> length_acc coda (acc + 1)in

length_acc l 0;;

Luigi Santocanale Introduction a la Semantique 12

Page 24: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Deuxieme exemple (langages fonctionnels)

Transformation code fonctionnel enforme recursive terminale.

let rec length = function[] -> 0

| testa ::coda -> 1 + length coda;;

let length l =let rec

length_acc lista acc = match lista with[] -> acc

| testa::coda -> length_acc coda (acc + 1)in

length_acc l 0;;

Luigi Santocanale Introduction a la Semantique 12

Page 25: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Qui intervient dans le processus de transformation ?

Programmeur, dont les objectifs sontrendre le code lisible, efficace.

Compilateur, optimise le code.

Definition du langage de programmation.Etabli les transformation acceptables.

Luigi Santocanale Introduction a la Semantique 13

Page 26: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Qui intervient dans le processus de transformation ?

Programmeur, dont les objectifs sontrendre le code lisible, efficace.

Compilateur, optimise le code.

Definition du langage de programmation.Etabli les transformation acceptables.

Luigi Santocanale Introduction a la Semantique 13

Page 27: Introduction `a la S´emantique · Exemples Deuxi`eme exemple (langages fonctionnels) Transformation code fonctionnel en forme r´ecursive terminale. let rec length = function []

Exemples

Qui intervient dans le processus de transformation ?

Programmeur, dont les objectifs sontrendre le code lisible, efficace.

Compilateur, optimise le code.

Definition du langage de programmation.Etabli les transformation acceptables.

Luigi Santocanale Introduction a la Semantique 13