0% found this document useful (0 votes)
10 views15 pages

Compiler Presentation (Group 1)

The document presents a study on eliminating left recursion and applying left factoring in grammar for LL(1) parsing. It outlines the methodology, findings, and analysis of two tasks aimed at resolving parsing ambiguities and ensuring deterministic parsing decisions. The insights discuss the relevance of these techniques in compiler development and their implications for parser performance.

Uploaded by

Aryan Shahin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views15 pages

Compiler Presentation (Group 1)

The document presents a study on eliminating left recursion and applying left factoring in grammar for LL(1) parsing. It outlines the methodology, findings, and analysis of two tasks aimed at resolving parsing ambiguities and ensuring deterministic parsing decisions. The insights discuss the relevance of these techniques in compiler development and their implications for parser performance.

Uploaded by

Aryan Shahin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Binary

code
Presented By
Md. Shahin Miah Md. Shahariar Alom
ID: 221-15-5646 ID: 221-15-4829

Abdullah Al Noman Md Naeem Sheikh


ID: 221-15-5196 ID: 221-15-5120

Nabil Ahmad Rifat Name: Md Tawkir Tahmid Tonmoy


ID: 221-15-5350 ID: 221-15-5036
Agenda

1. Introduction to Recursion and Factoring


2. Background Concepts
3. Methodology Findings & Analysis
➢ Task 1: Eliminating Left Recursion
➢ Task 2: Left Factoring Industry
4. Insights Discussion & Conclusion
5. References
Introduction

Focus Areas:
✓ Eliminate left recursion
✓ Apply left factoring for LL(1).
Goals:
✓ Identify and resolve left recursion
✓ Apply transformations to remove ambiguity
✓ Ensure deterministic parsing decisions
Background Study

Left Recursion: Predictive Parsing:


✓ Direct: A → Aα | β → causes infinite loops ✓ Uses parsing table for deterministic
✓ Indirect: A → Bα, B → Aγ → indirect self- decisions.
reference.
📚 Reference:
Left Factoring:
✓ Resolves ambiguity in shared prefixes Aho, Sethi & Ullman (2006), Compilers:
(e.g., S → αβ | αγ) Principles, Techniques, and Tools.
🔍 LL(1) Parsing
✓ Top-down, one-token lookahead
✓ Requires unambiguous, non-left-
recursive grammar
Methodology

Approach:
❖ Recursion Task: Grammar: S → A a | b, A → S c |d
❖ Identify and eliminate direct/indirect left recursion

Approach:
❖ Factoring Task: Grammar: S → A(B)C | A0C | SD, A → id | num, etc.
❖ Factor out common prefixes for LL(1) compatibility
Task 1 - Eliminating Left
Recursion
Consider indirect left recursion, where the parser loops indefinitely. This task resolves it

with transformation steps.

Original Grammar Transformation Steps

• S→Aa|b • Substitute A into S: S → (S c | d) a | b → S c a | d

• A→Sc|d a|b

Problem • Eliminate direct left recursion: Introduce S': S

• Indirect left recursion: S → A a → S c a. → d a S' | b S', S' → c a S' | ε

Resulting Grammar
• S → d a S' | b S’

• S' → c a S' | ε
Task 1 - Findings &
Analysis
Results:
Grammar is non-left-recursive, suitable for top-down parsing
LL(1)-compatible, avoids infinite loops
Analysis:
Transformation resolves parsing ambiguity
Ensures deterministic parsing decisions
Challenges:
Task 1 - Findings &
Analysis

Challenges:
• Manual substitution can be error-prone for complex grammars
• Parsing table verification recommended for practical use

Parse Tree Comparison:


• Original: Ambiguous, looping
• Transformed: Finite, clear (e.g., "daca" parsed as S → d a S' → d a c
a S' → d a c a)
Task 2 - Left Factoring

Original Grammar: Transformation:


• S → A(B)C | A0C | SD Factor out A:
• A → id | num • S → A S'
• B → id | num | expr • S' → (B)C | 0C | D[Retain other productions unchanged]
• C → +S | -S | ε Resulting Grammar:
D → = expr • S → A S'
Problem: • S' → (B)C | 0C | D
• Common prefix A in S → A(B)C • A → id | num
| A0C causes LL(1) parsing • B → id | num | expr
conflict • C → +S | -S | ε
• D → = expr
Task 2 - Findings &
Analysis
Industry Insights

Expert Opinion:
• Hypothetical consultation with Dr. Jane Doe, Compiler Tools Engineer
• Left recursion elimination and factoring are foundational for tools like ANTLR,
JavaCC
Insights:
• Modern compilers automate transformations, but manual understanding aids
debugging
• Manual techniques align with industry for small grammars; tools preferred for
scalability
Implications:
• Mastery of these techniques prepares for real-world compiler development
• Impacts parser performance and efficiency
Task 2 - Left Factoring
Summary: Future Directions:
• Eliminated left recursion: S → • Explore automated grammar
d a S' | b S', S' → c a S' | ε transformation tools
• Applied left factoring: S → A S', • Study bottom-up parsing (e.g.,
S' → (B)C | 0C | D. LR parsers)
• Produced LL(1)-compatible Learning Experience:
grammars • Deepened understanding of
Relevance: grammar transformations.
• Critical for efficient, • Balanced theoretical and
deterministic parsers. practical parsing needs.
• Used in tools like Yacc, Bison,
and language parsing
Thanks
Teacher Resources
Press 0-9 for a timer

B C D
B is for blur C is for confetti B is for blur

O Q X
O is for Bubbles Q is for Quiet X is for close

You might also like