GRAMMAIRE ATTRIBUÉE - Université de...

Post on 20-Jan-2021

58 views 4 download

Transcript of GRAMMAIRE ATTRIBUÉE - Université de...

GRAMMAIRE ATTRIBUÉE IFT580 – Compilation et interprétation des langages

1

Grammaire attribuée • Une grammaire attribuée est une grammaire hors

contexte à laquelle on a ajouté des attributs sur les

nœuds

• La grammaire attribuée contient un ensemble de règles

d’évaluation pour les attributs qui sont associés aux

règles de production

2

Grammaire attribuée • Attributs

• Associés à chaque symbole de V et T

• Règles d’évaluation (règles sémantiques)

• A→X1X2…Xi…Xn

• A.att = f(attributs de A et de X1 à Xn)

• Xi.att = g(attributs de A et de X1 à Xn)

3

Grammaire attribuée • Il y a trois types d’attributs

• Attributs intrinsèques

• Associé à chaque symbole terminal et calculé par l’analyseur lexical

• Attributs synthétisés (pour A)

• Calculé en fonction des attributs de A et des X (A→X1X2…Xi…Xn)

• Attributs hérités (pour X)

• Calculé en fonction des attributs de A et des X (A→X1X2…Xi…Xn)

4

Grammaire attribuée

• Une grammaire attribuée est réputée bien formée si

• Les attributs sont divisés en groupe distinct (hérités et synthétisés)

• Les règles sémantiques sont cohérentes dans toute la grammaire

• La grammaire attribuée est complète

• Pour toutes les règles d’une même variable, les mêmes attributs sont

calculés

• La grammaire est WAG (Well-formed attribute grammar)

5

Grammaire attribuée • Lorsqu’une grammaire attribuée contient des attributs

hérités et synthétisés, il n’y a aucune garantie qu’il n’y a

pas de cycles dans le calcul

• Il existe des classes de grammaire attribuée qui ne

contiennent pas de cycles

• On va y revenir plus tard!

6

Grammaire attribuée

• L’utilisation d’une grammaire attribuée nous permet de

faire l’analyse sémantique dirigée par la syntaxe!

7

Grammaire attribuée • Il existe plusieurs types de grammaires attribuées

8

m-APAG (m-Alternating Passes Attribute Grammar)

Calcul des attributs :

• m passes en profondeur, en alternance

de gauche à droite et de droite à

gauche

Grammaire attribuée • Il existe plusieurs types de grammaires attribuées

9

m-APAG (m-Alternating Passes Attribute Grammar)

n-PAG (n-Passes Attribute Grammar)

Calcul des attributs :

• n passes en profondeur de gauche à

droite

Grammaire attribuée • Il existe plusieurs types de grammaires attribuées

10

m-APAG (m-Alternating Passes Attribute Grammar)

n-PAG (n-Passes Attribute Grammar)

L-AG (L-Attributed Grammar)

Calcul des attributs :

• en profondeur de gauche à

droite

Grammaire attribuée • Il existe plusieurs types de grammaires attribuées

11

m-APAG (m-Alternating Passes Attribute Grammar)

n-PAG (n-Passes Attribute Grammar)

L-AG (L-Attributed Grammar)

S-AG (S-Attributed Grammar)

Calcul des attributs :

• de bas en haut

Grammaire S-Attribuée • Grammaire attribuée contenant seulement des attributs

synthétisés

• Grammaire attribuée avec les règles les plus simples

• Le calcul des attributs peut se faire simplement à l’aide

d’un parcours en profondeur dans l’arbre abstrait

12

Grammaire S-Attribuée

• Chaque attribut associé à la partie gauche de la règle de

production est calculé en utilisant seulement les attributs

des composantes de la partie droite

• S’utilise bien avec un analyseur syntaxique LR

• Il n’y aura aucun cycle, c’est garanti

13

Grammaire S-Attribuée

14

Production Règles sémantiques

1) L → En L.val = E.val

2) E → E1+T E.val = E1.val + T.val

3) E → T E.val = T.val

4) T → T1*F T.val = T1.val * F.val

5) T → F T.val = F.val

6) F → (E) F.val = E.val

7) F → chiffre F.val = chiffre.vallex

Une calculatrice simplifiée

15

3*5+4n

L

Production Règles sémantiques

E

val = ?

val = ? n

E val = ? + T

F

chiffre

T

T F *

chiffre F

chiffre

val = ?

val = ?

val = ?

vallex = 3

val = ?

vallex = 5 vallex = 4

val = ?

val = ?

16

3*5+4n

L

Production Règles sémantiques

7) F → chiffre F.val = chiffre.vallex

E

val = ?

val = ? n

E val = ? + T

F

chiffre

T

T F *

chiffre F

chiffre

val = ?

val = ?

val = 3

vallex = 3

val = ?

vallex = 5 vallex = 4

val = ?

val = ?

17

3*5+4n

L

Production Règles sémantiques

5) T → F T.val = F.val

E

val = ?

val = ? n

E val = ? + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = ?

val = 3

vallex = 3

val = ?

vallex = 5 vallex = 4

val = ?

val = ?

18

3*5+4n

L

Production Règles sémantiques

7) F → chiffre F.val = chiffre.vallex

E

val = ?

val = ? n

E val = ? + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = ?

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = ?

val = ?

19

3*5+4n

L

Production Règles sémantiques

4) T → T1*F T.val = T1.val*F.val

E

val = ?

val = ? n

E val = ? + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = ?

val = ?

20

3*5+4n

L

Production Règles sémantiques

3) E → T E.val = T.val

E

val = ?

val = ? n

E val = 15 + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = ?

val = ?

21

3*5+4n

L

Production Règles sémantiques

7) F → chiffre F.val = chiffre.vallex

E

val = ?

val = ? n

E val = 15 + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = 4

val = ?

22

3*5+4n

L

Production Règles sémantiques

5) T → F T.val = F.val

E

val = ?

val = ? n

E val = 15 + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = 4

val = 4

23

3*5+4n

L

Production Règles sémantiques

2) E → E1+T E.val = E1.val+T.val

E

val = ?

val = 19 n

E val = 15 + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = 4

val = 4

24

3*5+4n

L

Production Règles sémantiques

1) L → En L.val = E.val

E

val = 19

val = 19 n

E val = 15 + T

F

chiffre

T

T F *

chiffre F

chiffre

val = 3

val = 15

val = 3

vallex = 3

val = 5

vallex = 5 vallex = 4

val = 4

val = 4

Grammaire L-Attribuée • Une grammaire est L-attribuée si les attributs sont

• Synthétisés

• Hérités, avec des restrictions

• Un attribut hérité Xi.a, de la règle A→X1…Xi…Xn ne peut être calculé

qu’avec

• Les attributs hérités de A

• Les attributs hérités ou synthétisés de X1 à Xi-1 (à gauche de Xi)

• Les attributs hérités ou synthétisés de Xi, mais seulement si ça ne crée pas

de cycles

25

Grammaire L-Attribuée

26

Production Règles sémantiques

1) A → BC A.s = B.b

B.i = f(C.c, A.s)

La grammaire n’est pas L-attribuée car

• L’attribut hérité B.i est calculé avec un frère à

droite de B

Grammaire L-Attribuée

27

Production Règles sémantiques

1) T → FT’ T’.h = F.val

T.val = T’.s

2) T’ → *FT’1 T’1.h = T’.h*F.val

T’.s = T’1.s

3) T’ → ε T’.s = T’.h

4) F → chiffre F.val = chiffre.vallex

Synthétisé Hérité

28

3*5

Production Règles sémantiques

T val = ?

F val = ?

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = ? vallex = 3 val = ?

vallex = 5

h = ?

h = ?

29

3*5

Production Règles sémantiques

4) F → chiffre F.val = chiffre.vallex

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = ? vallex = 3 val = ?

vallex = 5

h = ?

h = ?

30

3*5

Production Règles sémantiques

1) T → FT’ T’.h = F.val

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = ? vallex = 3 val = ?

vallex = 5

h = ?

h = 3

31

3*5

Production Règles sémantiques

4) F → chiffre F.val = chiffre.vallex

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = ? vallex = 3 val = 5

vallex = 5

h = ?

h = 3

32

3*5

Production Règles sémantiques

2) T’ → *FT’1 T’1.h = T’.h*F.val

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = ? vallex = 3 val = 5

vallex = 5

h = 15

h = 3

33

3*5

Production Règles sémantiques

3) T’ → ε T’.s = T’.h

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = ?

s = 15 vallex = 3 val = 5

vallex = 5

h = 15

h = 3

34

3*5

Production Règles sémantiques

2) T’ → *FT’1 T’.s = T’1.s

T val = ?

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = 15

s = 15 vallex = 3 val = 5

vallex = 5

h = 15

h = 3

35

3*5

Production Règles sémantiques

1) T’ → FT’ T.val = T’.s

T val = 15

F val = 3

*

T’

ε

F T’

chiffre

chiffre

s = 15

s = 15 vallex = 3 val = 5

vallex = 5

h = 15

h = 3

Grammaire n-PAG • Le calcul des attributs doit se faire en plusieurs parcours

• Chaque parcours est une passe

• Un attribut synthétisé peut dépendre d’un attribut hérité du nœud

• Un attribut hérité peut être calculé en fonction d’un attribut synthétisé sur le nœud courant • On doit parcourir en plusieurs passes pour calculer les noeuds

36

37

Première passe

Attributs synthétisés

Attributs hérités

38

Première passe

Attributs synthétisés

Attributs hérités

39

Première passe

Attributs synthétisés

Attributs hérités

40

Première passe

Attributs synthétisés

Attributs hérités

41

Première passe

Attributs synthétisés

Attributs hérités

42

Première passe

Attributs synthétisés

Attributs hérités

43

Première passe

Attributs synthétisés

Attributs hérités

44

Première passe

Attributs synthétisés

Attributs hérités

45

Première passe

Attributs synthétisés

Attributs hérités

46

Première passe

Attributs synthétisés

Attributs hérités

47

Première passe

Attributs synthétisés

Attributs hérités

48

Première passe

Attributs synthétisés

Attributs hérités

49

Deuxième passe

Attributs synthétisés

Attributs hérités

50

Deuxième passe

Attributs synthétisés

Attributs hérités

51

Deuxième passe

Attributs synthétisés

Attributs hérités

52

Deuxième passe

Attributs synthétisés

Attributs hérités

53

Deuxième passe

Attributs synthétisés

Attributs hérités

54

Deuxième passe

Attributs synthétisés

Attributs hérités

55

Deuxième passe

Attributs synthétisés

Attributs hérités

56

Deuxième passe

Attributs synthétisés

Attributs hérités

57

Deuxième passe

Attributs synthétisés

Attributs hérités

58

Deuxième passe

Attributs synthétisés

Attributs hérités

59

Deuxième passe

Attributs synthétisés

Attributs hérités

Grammaire m-APAG • Le calcul des attributs doit se faire en plusieurs parcours

• Chaque parcours est une passe

• Chaque passe alterne le calcul des attributs hérités (ceux utilisant les frères de gauche, l’autre en utilisant les frères de droite)

• Un attribut synthétisé peut dépendre d’un attribut hérité du nœud

• Un attribut hérité peut être calculé en fonction d’un attribut synthétisé sur le nœud courant

• Un attribut hérité peut dépendre d’un frère de gauche ou de droite

60

61

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

62

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

63

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

64

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

65

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

66

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

67

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

68

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

69

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

70

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

71

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

72

Première passe

Gauche à droite

Attributs synthétisés

Attributs hérités

73

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

74

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

75

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

76

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

77

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

78

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

79

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

80

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

81

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

82

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

83

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

84

Deuxième passe

Droite à gauche

Attributs synthétisés

Attributs hérités

Écriture des règles sémantiques

• Il peut y avoir plusieurs façons d’écrire les règles

sémantiques pour un problème

• Voici un exemple de grammaire attribuée permettant de

calculer la valeur d’un nombre binaire

85 Exemple produit par Richard St-Denis

Écriture des règles sémantiques

86 Exemple produit par Richard St-Denis

Production Description

S → L,L Une partie entière et fractionnaire

L → LB Une suite d’au moins un bit

L → B Un bit

B → 0 Un bit à 0

B → 1 Un bit à 1

Solution 0

87 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.val + L2.val

L → L1B ???

L → B L.val = B.val

B → 0 B.val = 0

B → 1 B.val = 1

Attributs synthétisés seulement

• Grammaire S-Attribuée

Solution 0

88 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.val + L2.val

L → L1B ???

L → B L.val = B.val

B → 0 B.val = 0

B → 1 B.val = 1

S

L1 , L2

B B

1 1

val = 1 val = 1

val = 1 val = 1

val = 2

Solution 1

89 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.e + L2.f

L → L1B L.e = 2 * L1.e + B.val

L.f = L1.f + ½L1.pos+1 * B.val

L.pos = L1.pos + 1

L → B L.e = B.val

L.f = ½B.val

L.pos = 1

B → 0 B.val = 0

B → 1 B.val = 1

• Tous les attributs sont

synthétisés

• On calcule toujours la partie

entière et fractionnaire (travail

fait en double)

• Les attributs :

• L.e : La partie entière

• L.f : La partie fractionnaire

• L.pos : La position du bit

• B.val :La valeur du bit

• S.val : La valeur du nombre

90 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1,L2

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

91 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

92 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

93 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

94 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ? val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

95 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.pos = 1

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = ?

pos = 1 val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

96 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½B.val

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = ?

f = 0,5

pos = 1 val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

97 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.e = B.val

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1 val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

98 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = ?

f = ?

pos = ? e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

99 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.pos = L1.pos + 1

e = ?

f = ?

pos = ? e = ?

f = ?

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

100 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f + ½L1.pos+1 * B.val

e = ?

f = ?

pos = ? e = ?

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

101 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2*L1.e + B.val

e = ?

f = ?

pos = ? e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

102 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 0 B.val = 0

e = ?

f = ?

pos = ? e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

103 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.pos = L1.pos + 1

e = ?

f = ?

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

104 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f + ½L1.pos+1 * B.val

e = ?

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

105 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

106 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

107 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

108 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

109 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = ?

110 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.pos = 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

pos = ?

e = ?

f = ?

pos = 1

e = ?

f = ?

pos = ?

111 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

pos = ?

e = ?

f = 0,5

pos = 1

e = ?

f = ?

pos = ?

112 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.e = B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = ?

f = ?

pos = ?

113 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = ?

f = ?

pos = ?

114 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.pos = L1.pos + 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = ?

f = ?

pos = 2

115 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f + ½L1.pos+1 * B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = ?

f = 0,75

pos = 2

116 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

117 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = ?

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

118 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.pos = L1.pos + 1

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

pos = 3

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

119 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f + ½L1.pos+1 * B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = ?

f = 0,875

pos = 3

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

120 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = 7

f = 0,875

pos = 3

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

121 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val =

6,875

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2 S.val = L1.e + L2.f

e = 6

f = 0,75

pos = 3 e = 3

f = 0,75

pos = 2

e = 1

f = 0,5

pos = 1 val = 1

val = 1 val = 1

val = 1

e = 7

f = 0,875

pos = 3

e = 1

f = 0,5

pos = 1

e = 3

f = 0,75

pos = 2

Solution 2

122 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.val + ½L2.lg*L2.val

L → L1B L.val = 2 * L1.val + B.val

L.lg = L1.lg + 1

L → B L.val = B.val

L.lg = 1

B → 0 B.val = 0

B → 1 B.val = 1

• Tous les attributs sont

synthétisés

• On ne calcule plus en double la

partie entière et fractionnaire,

seulement la longueur

• Les attributs :

• L.val : La valeur de la

chaîne de bits

• L.lg : La longueur de la

chaîne de bits

• B.val :La valeur du bit

• S.val : La valeur du nombre

123 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ? val = ?

val = ? val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

124 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ? val = ?

val = ? val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

125 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ? val = ?

val = ? val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

126 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ? val = ?

val = ? val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

127 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ? val = ?

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

128 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.lg = 1

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = 1 val = ?

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

129 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.val = B.val

val = ?

lg = ?

val = ?

lg = ?

val = 1

lg = 1 val = ?

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

130 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

val = ?

lg = ?

val = ?

lg = ?

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

131 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.lg = L1.lg + 1

val = ?

lg = ?

val = ?

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

132 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.val = 2 * L1.val + B.val

val = ?

lg = ?

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

133 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 0 B.val = 0

val = ?

lg = ?

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

134 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.lg = L1.lg + 1

val = ?

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

135 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.val = 2 * L1.val + B.val

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

136 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

137 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

138 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = ?

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

139 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = ?

val = ?

lg = ?

val = ?

lg = ?

val = ?

lg = ?

140 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.lg = 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = ?

val = ?

lg = ?

val = ?

lg = 1

val = ?

lg = ?

141 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.val = B.val

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = ?

val = ?

lg = ?

val = 1

lg = 1

val = ?

lg = ?

142 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = ?

lg = ?

val = 1

lg = 1

val = ?

lg = ?

143 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.lg = L1.lg + 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = ?

lg = ?

val = 1

lg = 1

val = ?

lg = 2

144 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.val = 2 * L1.val + B.val

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = ?

lg = ?

val = 1

lg = 1

val = 3

lg = 2

145 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = ?

lg = ?

val = 1

lg = 1

val = 3

lg = 2

146 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.lg = L1.lg + 1

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = ?

lg = 3

val = 1

lg = 1

val = 3

lg = 2

147 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.val = 2 * L1.val + B.val

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 1 val = 1

val = 1 val = 1

val = 1

val = 7

lg = 3

val = 1

lg = 1

val = 3

lg = 2

148 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val =

6,875

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2 S.val = L1.val + ½L2.lg L2.val

val = 6

lg = 3

val = 3

lg = 2

val = 1

lg = 0,5 val = 1

val = 1 val = 1

val = 1

val = 7

lg = 3

val = 1

lg = 1

val = 3

lg = 2

Solution 3

149 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.e + L2.f

L1.h = 0

L2.h = 0

L → L1B L1.h = ½L.h + ½B.val

L.e = 2 * L1.e + B.val

L.f = L1.f

L → B L.e = B.val

L.f = ½L.h + ½B.val

B → 0 B.val = 0

B → 1 B.val = 1

• Il y a des attributs synthétisés

et hérités!

• Les calculs sont encore faits en

double

• Les attributs :

• L.e : La partie entière

• L.f : La partie fractionnaire

• L.h : L’attribut hérité

• B.val :La valeur du bit

• S.val : La valeur du nombre

• La solution est simple à

calculer

150 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2

e = ?

f = ?

h = ? e = ?

f = ?

h = ?

e = ?

f = ?

h = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

151 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2 L1.h = 0

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = ?

f = ?

h = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

152 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = ?

f = ?

h = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

!

153 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = ?

f = ?

h = ? val = ?

val = ? val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

!

154 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = ?

f = ?

h = ? val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

155 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.e = B.val

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = 1

f = ?

h = ? val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

156 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½L.h + ½B.val

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = 1

f = ?

h = ? val = ?

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

!

157 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = ?

f = ?

h = 0 e = ?

f = ?

h = ?

e = 1

f = ?

h = ? val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

158 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = ?

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = ?

f = ?

h = 0 e = 3

f = ?

h = ?

e = 1

f = ?

h = ? val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

159 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 0 B.val = 0

e = ?

f = ?

h = 0 e = 3

f = ?

h = ?

e = 1

f = ?

h = ? val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

160 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = ?

h = 0 e = 3

f = ?

h = ?

e = 1

f = ?

h = ? val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

161 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = ?

h = 0 e = 3

f = ?

h = 0

e = 1

f = ?

h = ? val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

162 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = ?

h = 0 e = 3

f = ?

h = 0

e = 1

f = ?

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

163 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½L.h + ½B.val

e = 6

f = ?

h = 0 e = 3

f = ?

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

164 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f

e = 6

f = ?

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

165 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

166 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1,L2 L1.h = 0

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = 0

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

167 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = 0

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

!

168 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = ?

val = ?

e = ?

f = ?

h = 0

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

!

169 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

h = 0

e = ?

f = ?

h = ?

e = ?

f = ?

h = ?

170 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.e = B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

h = 0

e = 1

f = ?

h = ?

e = ?

f = ?

h = ?

171 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = ?

e = ?

f = ?

h = 0

e = 1

f = ?

h = ?

e = ?

f = ?

h = ?

!

172 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

h = 0

e = 1

f = ?

h = ?

e = ?

f = ?

h = ?

173 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = ? L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

h = 0

e = 1

f = ?

h = ?

e = 3

f = ?

h = ?

174 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

B → 1 B.val = 1

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = ?

f = ?

h = 0

e = 1

f = ?

h = ?

e = 3

f = ?

h = ?

175 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.e = 2 * L1.e + B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = ?

h = 0

e = 1

f = ?

h = ?

e = 3

f = ?

h = ?

176 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = ?

h = 0

e = 1

f = ?

h = ?

e = 3

f = ?

h = 0,5

177 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L1.h = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = ?

h = 0

e = 1

f = ?

h = 0,75

e = 3

f = ?

h = 0,5

178 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → B L.f = ½L.h + ½B.val

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = ?

h = 0

e = 1

f = 0,875

h = 0,75

e = 3

f = ?

h = 0,5

179 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = ?

h = 0

e = 1

f = 0,875

h = 0,75

e = 3

f = 0,875

h = 0,5

180 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val = ?

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

L → L1B L.f = L1.f

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = 0,875

h = 0

e = 1

f = 0,875

h = 0,75

e = 3

f = 0,875

h = 0,5

181 Exemple produit par Richard St-Denis

S

L1 , L2

B

0

val = 0

val =

6,875

L

B L

B

B

1

val = 1 L

B

L

B

1

1

1

1

Production Règles sémantiques

S → L1, L2 S.val = L1.e + L2.f

e = 6

f = 0,75

h = 0 e = 3

f = 0,75

h = 0

e = 1

f = 0,75

h = 0,5 val = 1

val = 1 val = 1

val = 1

e = 7

f = 0,875

h = 0

e = 1

f = 0,875

h = 0,75

e = 3

f = 0,875

h = 0,5

Solution 4

182 Exemple produit par Richard St-Denis

Production Règles sémantiques

S → L1,L2 S.val = L1.val + L2.val

L1.m = 2

L1.p = 1

L2.m = 1

L1.p = ½

L → L1B L.val = L1.val + B.val

L.c = B.p

L1.m = L.m

L1.p = L.p * L.m

B.p = ½L1.c

L → B L.val = B.val

L.c = B.p

B.p = L.p

B → 0 B.val = 0

B → 1 B.val = B.p

• Les attributs sont synthétisés et

hérités

• Le travail n’est plus fait en

double, mais la solution est

complexe

• Les attributs :

• L.m : Multiplicateur

• L.p : Poids

• L.c : Poids du bit de la liste

• L.val : Valeur de la liste

• B.p : Le poids du bit

• B.val :Le poids du bit

• S.val : La valeur du nombre

Solution 4

• Le calcul des attributs est à faire en exercices!

183