Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exercises on Parsing and Analysis of Grammars, Summaries of Immigration Law

A series of exercises focused on analyzing both bottom-up and top-down parsing techniques, with a specific emphasis on analyzing chains of symbols using these methods. The exercises involve the analysis of various grammars, including their nullable, first, and following sets, as well as demonstrating the elimination of recursion in certain grammars. The document also includes the construction of a table for a given grammar to determine if it is ll(1).

Typology: Summaries

2023/2024

Uploaded on 01/09/2024

kallab-aya
kallab-aya 🇩🇿

1 document

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Exercises on Parsing and Analysis of Grammars and more Summaries Immigration Law in PDF only on Docsity! Série d’exercices N°03 Les analyseurs descendants et ascendants Exercice 01 : Soit G2 (T, N, S, P), tel que : T = {a, b, d, c, e}, N = {S, A, B, C} et S : est l’axiome de départ. 𝑃 ∶ 𝑆 → 𝐴𝐵 | 𝑎𝑆𝑏 |𝐶𝑆𝐵 𝐴 → 𝑏𝐴 | 𝜖 𝐵 → 𝑑𝐵 | 𝜖 𝐶 → 𝑐𝐶 | 𝑒 Analyser les chaines suivantes : bbdd ,abbdb, abcd par la décente avec retour arrière. Chaine Analyse par la décente avec retour arrière bbdd 𝑆 → 𝐴𝐵 → 𝑏𝐴𝐵 → 𝑏𝑏𝐴𝐵 → 𝑏𝑏𝑏𝐴𝐵 → 𝑏𝑏𝐵 → 𝑏𝑏𝑑𝐵 → 𝑏𝑏𝑑𝑑𝐵 → 𝑏𝑏𝑑𝑑𝑑𝐵 → 𝑏𝑏𝑑𝑑 abbdb 𝑆 → 𝐴𝐵 → 𝑏𝐴𝐵 → 𝐵 → 𝑑𝐵 → 𝜖 → 𝑎𝑆𝑏 → 𝑎𝐴𝐵𝑏 → 𝑎𝑏𝐴𝐵𝑏 → 𝑎𝑏𝑏𝐴𝐵𝑏 → 𝑎𝑏𝑏𝑏𝐴𝐵𝑏 → 𝑎𝑏𝑏𝐵𝑏 → 𝑎𝑏𝑏𝑑𝐵𝑏 → 𝑎𝑏𝑏𝑑𝑑𝐵𝑏 → 𝑎𝑏𝑏𝑑𝑏 abcd 𝑆 → 𝐴𝐵 → 𝑏𝐴𝐵 → 𝐵 → 𝑑𝐵 → 𝜖 → 𝑎𝑆𝑏 → 𝐶𝑆𝐵 → 𝑐𝐶𝑆𝑉 → 𝑒𝑆𝐵 Exercice 02 : Soit G (T, N, E, P), tel que : T : {+, -, *, /, (,), nb}, N= {E, T, E’, T’, F} et E : est l’axiome de départ. nb : est une unité lexicale. 𝑝 ∶ ⎩ ⎪ ⎨ ⎪ ⎧ 𝐸 → 𝑇𝐸 𝐸 → +𝑇𝐸 |−𝑇𝐸 |𝜖 𝑇 → 𝐹𝑇 𝑇 →∗ 𝐹𝑇 | /𝐹𝑇 | 𝜖 𝐹 → (𝐸)| 𝑛𝑏 - Calculer les fonctions Nullable, Premier et Suivant de : E, T, E’, T’et F. Non terminal Null Premier Suivant E Faux {(, nb} {#, )} E’ Vrai {+,-} {#, ) } T Faux {(, nb} {+, -, #, ) } T’ Vrai {*, /} {+, -, #, ) } F Faux {(, nb} {*, /, +, -, #, ) } Exercice 03 : Soit les trois grammaires suivantes : Grammaire 1 Grammaire 2 Grammaire 3 𝑺 → 𝒂𝑺𝒃 | 𝒄𝒅 | 𝑺𝑨𝒆 𝑨 → 𝒂𝑨𝒅𝑩 | 𝝐 𝑩 → 𝒃𝒃 ⎩ ⎪ ⎨ ⎪ ⎧ 𝑺 → 𝑨𝑩𝑪𝑫 𝑨 → 𝒂 | 𝝐 𝑩 → 𝑪𝑫 | 𝒃 𝑪 → 𝒄 | 𝝐 𝑫 → 𝑨𝒂 | 𝒅 |𝝐 𝑺 → 𝑨𝑩𝑺𝒃 | 𝝐 𝑨 → 𝒂𝑩𝒃 | 𝒃 𝑩 → 𝒃𝑩 | 𝒄𝑺 |𝝐 1. Donner la définition de chacune de ces grammaires. Grammaire Terminal Non terminal Axiome G1 {a, b, c, d, e} {S, A, B} S G2 {a, b, c, d} {S, A, B, C, D} S G3 {a, b, c} {S, A, B} S 2. Calculer les fonctions Nullable, Premier et Suivant pour chacune de ces grammaires. Grammaire Non terminal Null Premier Suivant G1 S Faux {a, c} {#, a, b, e} A Vrai {a} {d, e} B Faux {b} {d, e} G2 S Vrai {a, b, c, d} {#} A Vrai {a} {#, a, b, c, d} B Vrai {a, b, c, d} {#, a, c, d} C Vrai {c} {#, a, c, d} D Vrai {a, d} {#, a, c, d} G3 S Vrai {a, b} {#, a, b} A Faux {a, b} {a, b, c} B Vrai {b, c} {a, b} 3. Démontrer que la première grammaire n'est pas LL (k) sans effectuer aucun calcul. Cette première grammaire a une récursivité directe à gauche alors qu'une grammaire LL(k) ne doit pas avoir une récursivité à gauche. 4. Eliminer la récursivité dans la première grammaire (G'). 𝐺 : 𝑆 → 𝑎𝑆𝑏𝑆 | 𝑐𝑑𝑆 𝑆 → 𝐴𝑒𝑆 | 𝜖 𝐴 → 𝑎𝐴𝑑𝐵 | 𝜖 𝐵 → 𝑏𝑏 5. Démontrer que les trois grammaires G', G2 et G3 sont LL (1). Propriété 1 Propriété 2 Propriété 3 LL(1) ? G’ 𝑃𝑟𝑒(𝑎𝑆𝑏𝑆 ) ∩ 𝑃𝑟𝑒 (𝑐𝑑𝑆 ) = ∅ 𝑃𝑟𝑒(𝐴𝑒𝑆 ) ∩ 𝑃𝑟𝑒(𝜖) = ∅ 𝑃𝑟𝑒(𝑎𝐴𝑑𝐵) ∩ 𝑃𝑟𝑒(𝜖) = ∅ 𝑁𝑢𝑙𝑙(𝑎𝑆𝑏𝑆 ) = 𝑁𝑢𝑙𝑙(𝑐𝑑𝑆 ) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝐴𝑒𝑆 ) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝑎𝐴𝑑𝐵) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝑏𝑏) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙 (𝑎𝑆𝑏𝑆 ) = 𝑁𝑢𝑙𝑙 (𝑐𝑑𝑆 ) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣, 𝑃𝑟𝑒(𝐴𝑒𝑆 ) ∩ 𝑆𝑢𝑖𝑣(𝑆 ) = ∅ 𝑁𝑢𝑙𝑙(𝜖) = 𝑣, 𝑃𝑟𝑒(𝑎𝐴𝑑𝐵) ∩ 𝑆𝑢𝑖𝑣(𝐴) = ∅ 𝑁𝑢𝑙𝑙(𝑏𝑏) = 𝑓 Oui G2 𝑃𝑟𝑒(𝐶𝐷) ∩ 𝑃𝑟𝑒(𝑏) = ∅ 𝑃𝑟𝑒(𝐴𝑎) ∩ 𝑃𝑟𝑒(𝑑) = ∅ 𝑁𝑢𝑙𝑙 (𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝑎) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝐶𝐷) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝑏) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝐴𝑎) = 𝑁𝑢𝑙𝑙(𝑑) = 𝑣𝑟𝑎𝑖 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖 𝑃𝑟𝑒(𝑎) ∩ 𝑆𝑢𝑖𝑣(𝐴) = {𝑎} Arrêter ici NON G3 𝑃𝑟𝑒(𝐴𝐵𝑆𝑏) ∩ 𝑃𝑟𝑒(𝜖) = ∅ 𝑃𝑟𝑒(𝑎𝐵𝑏) ∩ 𝑃𝑟𝑒(𝑏) = ∅ 𝑃𝑟𝑒(𝑏𝐵) ∩ 𝑃𝑟𝑒(𝑐𝑆) ∩ 𝑃𝑟𝑒(𝜖) = ∅ 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝐴𝐵𝑆𝑏) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝑎𝐵𝑏) = 𝑁𝑢𝑙𝑙(𝑏) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖, 𝑁𝑢𝑙𝑙(𝑏𝐵) = 𝑁𝑢𝑙𝑙(𝑐𝑆) = 𝑓𝑎𝑢𝑥 𝑁𝑢𝑙𝑙(𝜖) = 𝑣𝑟𝑎𝑖 𝑃𝑟𝑒(𝐴𝐵𝑆𝑏) ∩ 𝑆𝑢𝑖𝑣(𝑆) = {𝑎, 𝑏} Arrêter ici NON 6. Démontrer que les trois grammaires G', G2 et G3 sont LL (1) par la construction de la table LL (1). G’ : N T a b c d e # S S→aSbS’ / S→csS’ / / / S’ S’→AeS’ S’→ 𝜖 / / / S’→ 𝜖 A A→aAdB / / A→ 𝜖 A→ 𝜖 / B / B→bb / / / / D’après le tableau G’ est LL(1). G2 : N T a b c d # S S→ABCD S→ABCD S→ABCD S→ABCD S→ABCD A A→a, A→ 𝝐 A→ 𝜖 A→ 𝜖 A→ 𝜖 A→ 𝜖 B B→CD B→b B→CD B→CD B→CD C C → 𝜖 / C→c, C → 𝝐 C → 𝜖 C→ 𝜖 D D→Aa,D→ 𝝐 / D → 𝜖 D→d,D → 𝝐 D → 𝜖 La table d’analyse de Grammaire G2 contient beaucoup de cellules qui comportent plus d'une règle donc la grammaire n'est pas LL(1).
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved