Bottom-Up Parsing and Operator Precedence Parsing | बॉटम-अप पार्सिंग और ऑपरेटर प्रीसीडेंस पार्सिंग - Compiler Design Notes 2025
बॉटम-अप पार्सिंग और ऑपरेटर प्रीसीडेंस पार्सिंग (Bottom-Up Parsing and Operator Precedence Parsing)
Syntax Analysis में दो प्रमुख पार्सिंग तकनीकें होती हैं — Top-Down Parsing और Bottom-Up Parsing। जहाँ Top-Down Parsing पार्स ट्री को ऊपर से नीचे बनाती है, वहीं Bottom-Up Parsing leaves से शुरू होकर root की ओर बढ़ती है। यह तकनीक सबसे शक्तिशाली और आमतौर पर प्रयोग की जाने वाली विधि है।
📘 Bottom-Up Parsing क्या है?
Bottom-Up Parsing वह प्रक्रिया है जिसमें input string को grammar rules के अनुसार धीरे-धीरे reduce करते हुए start symbol में बदला जाता है। इस प्रक्रिया को Shift-Reduce Parsing भी कहा जाता है।
मुख्य सिद्धांत:
- Parsing process leaves से root की ओर चलता है।
- Input को symbols के समूह में divide करके reductions किए जाते हैं।
- Parse Tree को धीरे-धीरे ऊपर की ओर build किया जाता है।
⚙️ Shift-Reduce Parsing:
Shift-Reduce Parser सबसे सामान्य Bottom-Up Parser है। यह input string को stack और input buffer का उपयोग करके parse करता है। चार मुख्य क्रियाएँ होती हैं:
- 🔹 Shift: Input symbol को stack पर push करना।
- 🔹 Reduce: Stack के symbols को grammar के production rule से match करके non-terminal में बदलना।
- 🔹 Accept: जब stack में केवल start symbol रह जाए और input समाप्त हो जाए।
- 🔹 Error: कोई valid reduction संभव न हो।
📗 उदाहरण:
Grammar:
E → E + T | T T → T * F | F F → (E) | id
Input: id + id * id
Parsing Table (Simplified):
| Step | Stack | Input | Action |
|---|---|---|---|
| 1 | $ | id + id * id$ | Shift |
| 2 | $ id | + id * id$ | Reduce F → id |
| 3 | $ F | + id * id$ | Reduce T → F |
| 4 | $ T | + id * id$ | Reduce E → T |
| 5 | $ E | + id * id$ | Shift |
| 6 | $ E + | id * id$ | Shift |
| 7 | $ E + id | * id$ | Reduce F → id |
| 8 | $ E + F | * id$ | Reduce T → F |
| 9 | $ E + T | * id$ | Shift |
| 10 | $ E + T * | id$ | Shift |
| 11 | $ E + T * id | $ | Reduce F → id |
| 12 | $ E + T * F | $ | Reduce T → T * F |
| 13 | $ E + T | $ | Reduce E → E + T |
| 14 | $ E | $ | Accept ✅ |
🧩 Handle Pruning (Handle Concept):
Handle input string का वह भाग होता है जिसे grammar के production rule से replace किया जा सकता है। Shift-Reduce Parsing का उद्देश्य हर चरण में सही handle को पहचानना और reduce करना होता है।
📘 Handle Example:
E + E * E → Handle: E * E → Reduced to T → Handle: E + T → Reduced to E
⚙️ Operator Precedence Parsing:
Operator Precedence Parsing Bottom-Up Parsing का एक विशेष रूप है जो उन grammars पर लागू होता है जिनमें operators (+, -, *, /) की precedence और associativity स्पष्ट रूप से परिभाषित होती है।
📘 Operator Precedence Grammar:
ऐसी grammar जिसमें:
- कोई ε-productions न हों।
- कोई दो adjacent non-terminals न हों।
उदाहरण:
E → E + E | E * E | (E) | id
📊 Operator Precedence Table:
| Operator | + | * | ( | ) | id | $ |
|---|---|---|---|---|---|---|
| + | > | < | < | > | < | > |
| * | > | > | < | > | < | > |
| ( | < | < | < | = | < | |
| ) | > | > | > | > | ||
| id | > | > | > | > | ||
| $ | < | < | < | < |
📗 Parsing Example (Operator Precedence):
Input: id + id * id
Stack | Input | Action ----------------------------------------- $ id | + id * id $ | Shift $ id + | id * id $ | Shift $ id + id | * id $ | Reduce E → id $ E + | * id $ | Shift $ E + * | id $ | Shift $ E + * id | $ | Reduce E → id $ E + E * E | $ | Reduce E → E + E * E Accept ✅
🚀 आधुनिक उपयोग (Bottom-Up Parsing in 2025):
- 🔹 LR(1) Parser Generators जैसे YACC, Bison।
- 🔹 Machine Learning आधारित Error Recovery।
- 🔹 Cloud Compiler Tools में optimized parsing engines।
📙 निष्कर्ष:
Bottom-Up Parsing सबसे शक्तिशाली parsing तकनीक है जो large-scale compilers में प्रयोग होती है। Operator Precedence Parsing arithmetic expressions के लिए तेज़ और प्रभावी विधि है। 2025 में, AI-सक्षम parser generators ने इन तकनीकों को और अधिक स्मार्ट व error-tolerant बना दिया है।
Related Post
- Introduction of Compiler | कंपाइलर का परिचय - Working, Structure, and Importance in Compiler Design
- Major Data Structures in Compiler | कंपाइलर में उपयोग होने वाले प्रमुख डेटा स्ट्रक्चर
- Bootstrapping and Porting in Compiler Design | बूटस्ट्रैपिंग और पोर्टिंग क्या है? कार्य, चरण और उदाहरण सहित
- Compiler Structure: Analysis–Synthesis Model of Compilation | कंपाइलर की संरचना और विश्लेषण-संश्लेषण मॉडल
- Various Phases of a Compiler | कंपाइलर के विभिन्न चरण और उनका कार्य (With Diagram & Examples)
- Lexical Analysis in Compiler Design | लेक्सिकल एनालिसिस क्या है? प्रक्रिया, टोकन, बफरिंग और उदाहरण सहित
- Input Buffering in Compiler Design | इनपुट बफरिंग क्या है? डबल बफरिंग तकनीक और उदाहरण सहित
- Specification and Recognition of Tokens in Compiler Design | टोकन की स्पेसिफिकेशन और पहचान - रेगुलर एक्सप्रेशन एवं फाइनाइट ऑटोमाटा सहित
- LEX in Compiler Design | LEX टूल क्या है? संरचना, कार्यप्रणाली और उदाहरण सहित पूर्ण व्याख्या
- Syntax Analysis and Context-Free Grammars (CFGs) | वाक्य विश्लेषण और संदर्भ-मुक्त व्याकरण - Compiler Design Notes 2025
- Top-Down Parsing (Brute Force & Recursive Descent) | टॉप-डाउन पार्सिंग - सिद्धांत, एल्गोरिथ्म और उदाहरण सहित
- Grammar Transformations and Predictive Parsing | व्याकरण रूपांतरण एवं प्रेडिक्टिव पार्सिंग - Compiler Design Notes 2025
- Bottom-Up Parsing and Operator Precedence Parsing | बॉटम-अप पार्सिंग और ऑपरेटर प्रीसीडेंस पार्सिंग - Compiler Design Notes 2025
- LR Parsers (SLR, LALR, Canonical LR) | एलआर पार्सर्स - सिद्धांत, निर्माण प्रक्रिया और उदाहरण सहित
- Parser Generation | पार्सर निर्माण प्रक्रिया - Compiler Design Notes 2025 (Hindi + English)
- Syntax Directed Definitions (SDD) and Construction of Syntax Trees | सिंटैक्स निर्देशित परिभाषाएँ और सिंटैक्स वृक्ष निर्माण - Compiler Design Notes 2025
- Bottom-Up Evaluation of S-Attributed Definitions | एस-एट्रीब्यूटेड डेफिनिशन्स का बॉटम-अप मूल्यांकन - Compiler Design Notes 2025
- L-Attributed Definitions and Top-Down Translation | एल-एट्रीब्यूटेड डेफिनिशन्स और टॉप-डाउन अनुवाद - Compiler Design Notes 2025
- Bottom-Up Evaluation of Inherited Attributes | इनहेरिटेड एट्रीब्यूट्स का बॉटम-अप मूल्यांकन - Compiler Design Notes 2025
- Recursive Evaluation and Syntax Directed Definition Analysis | रिकर्सिव मूल्यांकन और सिंटैक्स निर्देशित परिभाषा विश्लेषण - Compiler Design Notes 2025
- Type System | टाइप सिस्टम क्या है?
- Specification of Simple Type Checker | सरल टाइप चेकर का विश्लेषण
- Equivalence of Expressions and Types in Compiler Design | कंपाइलर डिज़ाइन में अभिव्यक्तियों और टाइप्स की समानता
- Type Conversion in Compiler Design | कंपाइलर डिज़ाइन में टाइप रूपांतरण
- Overloading of Functions and Operations in Compiler Design | कंपाइलर डिज़ाइन में फ़ंक्शन और ऑपरेशन का ओवरलोडिंग
- Polymorphic Functions in Compiler Design | कंपाइलर डिज़ाइन में बहुरूपी फ़ंक्शन
- Storage Organization in Compiler Design | कंपाइलर डिज़ाइन में स्टोरेज संगठन
- Storage Allocation Strategies in Compiler Design | कंपाइलर डिज़ाइन में स्टोरेज आबंटन रणनीतियाँ
- Parameter Passing in Compiler Design | कंपाइलर डिज़ाइन में पैरामीटर पासिंग
- Dynamic Storage Allocation in Compiler Design | कंपाइलर डिज़ाइन में डायनेमिक स्टोरेज आबंटन
- Symbol Table in Compiler Design | कंपाइलर डिज़ाइन में सिंबल टेबल
- Intermediate Code Generation: Declarations | इंटरमीडिएट कोड जनरेशन में घोषणाएँ
- Intermediate Code Generation: Assignment Statements | इंटरमीडिएट कोड जनरेशन में असाइनमेंट स्टेटमेंट्स
- Intermediate Code Generation: Boolean Expressions | इंटरमीडिएट कोड जनरेशन में बूलियन अभिव्यक्तियाँ
- Intermediate Code Generation: Case Statements | इंटरमीडिएट कोड जनरेशन में केस स्टेटमेंट्स
- Intermediate Code Generation: Backpatching | इंटरमीडिएट कोड जनरेशन में बैकपैचिंग
- Intermediate Code Generation: Procedure Calls | इंटरमीडिएट कोड जनरेशन में प्रोसीजर कॉल्स
- Code Generation: Issues in the Design of Code Generator | कोड जनरेटर के डिज़ाइन में समस्याएँ
- Basic Blocks and Flow Graphs | बेसिक ब्लॉक्स और फ्लो ग्राफ़्स
- Register Allocation and Assignment | रजिस्टर आबंटन और असाइनमेंट
- DAG Representation of Basic Blocks | बेसिक ब्लॉक्स का DAG प्रतिनिधित्व
- Peephole Optimization | पीपहोल ऑप्टिमाइज़ेशन
- Generating Code from DAG | DAG से कोड जनरेशन
- Introduction to Code Optimization | कोड ऑप्टिमाइज़ेशन का परिचय
- Sources of Optimization of Basic Blocks | बेसिक ब्लॉक्स के ऑप्टिमाइज़ेशन के स्रोत
- Loops in Flow Graphs | फ्लो ग्राफ़्स में लूप्स
- Dead Code Elimination | डेड कोड एलिमिनेशन
- Loop Optimization | लूप ऑप्टिमाइज़ेशन
- Introduction to Global Data Flow Analysis | ग्लोबल डेटा फ्लो एनालिसिस का परिचय
- Code Improving Transformations in Compiler Design | कोड सुधार परिवर्तन की उन्नत तकनीकें
- Data Flow Analysis of Structured Flow Graph | स्ट्रक्चर्ड फ्लो ग्राफ का डेटा फ्लो विश्लेषण
- Symbolic Debugging of Optimized Code | ऑप्टिमाइज़्ड कोड का प्रतीकात्मक डीबगिंग