टॉप-डाउन पार्सिंग क्या है? | Top-Down Parsing in Compiler Design in Hindi
टॉप-डाउन पार्सिंग क्या है? (What is Top-Down Parsing in Compiler Design?)
टॉप-डाउन पार्सिंग (Top-Down Parsing) कंपाइलर डिज़ाइन में उपयोग की जाने वाली **पार्सिंग तकनीक** है, जिसमें पार्स ट्री (Parse Tree) का निर्माण **रूट (Root) से लेकर लीफ (Leaf) नोड तक** किया जाता है। यह विधि स्टार्ट सिंबॉल (Start Symbol) से शुरू होती है और धीरे-धीरे इनपुट स्ट्रिंग का मिलान करके टोकन्स को संसाधित करती है।
1. टॉप-डाउन पार्सिंग की विशेषताएँ (Characteristics of Top-Down Parsing)
- यह **Recursive Descent** या **Predictive Parsing** पर आधारित हो सकती है।
- यह **Leftmost Derivation** (बाएं से दाएं व्युत्पत्ति) का अनुसरण करता है।
- इनपुट स्ट्रिंग के **पहले टोकन्स** से पार्सिंग शुरू होती है।
- यह एक **Predictive Parser Table** का उपयोग कर सकता है।
2. टॉप-डाउन पार्सिंग के प्रकार (Types of Top-Down Parsing)
मुख्य रूप से टॉप-डाउन पार्सिंग को निम्नलिखित दो प्रकारों में विभाजित किया जाता है:
1. रिकर्सिव डिसेंट पार्सिंग (Recursive Descent Parsing)
इस पार्सिंग तकनीक में प्रत्येक नॉन-टर्मिनल (Non-Terminal) के लिए एक **रिकर्सिव फंक्शन** होता है, जो टोकन्स का मिलान करता है और पार्स ट्री का निर्माण करता है।
उदाहरण:
मान लीजिए कि हमारे पास निम्नलिखित व्याकरण (Grammar) है:
E → T + E | T T → id
यदि इनपुट स्ट्रिंग id + id
है, तो रिकर्सिव डिसेंट पार्सिंग निम्नलिखित **रिकर्सिव फंक्शन्स** का उपयोग करेगा:
void E() { T(); if (nextToken == "+") { match("+"); E(); } } void T() { match("id"); }
2. प्रिडिक्टिव पार्सिंग (Predictive Parsing)
प्रिडिक्टिव पार्सिंग में **रिकर्सन को हटाकर** **पार्सिंग टेबल** (Parsing Table) का उपयोग किया जाता है। यह **LL(1) Parsing** तकनीक पर आधारित होता है।
Parsing Table का उदाहरण:
नॉन-टर्मिनल | id | + | $ |
---|---|---|---|
E | E → T + E | E → T | |
T | T → id |
3. टॉप-डाउन पार्सिंग के चरण (Steps in Top-Down Parsing)
टॉप-डाउन पार्सिंग को निम्नलिखित चरणों में निष्पादित किया जाता है:
- **इनपुट स्ट्रिंग** को टोकन्स में विभाजित किया जाता है।
- **स्टार्ट सिंबॉल** से पार्सिंग शुरू होती है।
- हर नॉन-टर्मिनल के लिए **रिकर्सिव कॉल या टेबल लुकअप** किया जाता है।
- इनपुट से मेल खाने वाले टोकन्स को स्वीकार (Accept) किया जाता है।
- गलत टोकन्स मिलने पर **सिंटैक्स एरर** जनरेट किया जाता है।
4. टॉप-डाउन पार्सिंग का उदाहरण (Example of Top-Down Parsing)
मान लीजिए कि हमें निम्नलिखित व्याकरण (Grammar) को पार्स करना है:
S → a A A → b | ε
और इनपुट **"ab"** है, तो **टॉप-डाउन पार्सिंग** का निष्पादन कुछ इस प्रकार होगा:
S | a A | b
5. टॉप-डाउन पार्सिंग बनाम बॉटम-अप पार्सिंग (Top-Down vs Bottom-Up Parsing)
विशेषता | टॉप-डाउन पार्सिंग | बॉटम-अप पार्सिंग |
---|---|---|
व्युत्पत्ति | **Leftmost Derivation** का अनुसरण करता है। | **Rightmost Derivation in Reverse** का अनुसरण करता है। |
पार्स ट्री निर्माण | रूट से शुरू होता है और लीफ नोड्स तक जाता है। | लीफ नोड्स से शुरू होता है और रूट तक जाता है। |
एप्रोच | Recursive Descent या Predictive Parsing | Shift-Reduce या LR Parsing |
उदाहरण | LL(1) पार्सर | LR(0), SLR(1), LALR(1) पार्सर |
6. टॉप-डाउन पार्सिंग की सीमाएँ (Limitations of Top-Down Parsing)
- यह **Left Recursion** को सीधे तौर पर नहीं संभाल सकता।
- यदि व्याकरण **Ambiguous** है, तो यह सही से कार्य नहीं करता।
- LL(1) व्याकरण में केवल एक टोकन की Lookahead सुविधा होती है।
7. टॉप-डाउन पार्सिंग के फायदे (Advantages of Top-Down Parsing)
- यह **आसान और सरलीकृत** होता है।
- रिकर्सिव डिसेंट पार्सर को **मैन्युअली कोड किया जा सकता है**।
- Predictive Parsing **टेबल-बेस्ड एपरोच** का उपयोग करता है, जिससे यह तेज़ और कुशल होता है।
8. निष्कर्ष (Conclusion)
टॉप-डाउन पार्सिंग कंपाइलर डिज़ाइन की एक महत्वपूर्ण तकनीक है, जिसका उपयोग **लेफ्टमॉस्ट व्युत्पत्ति** (Leftmost Derivation) को लागू करने के लिए किया जाता है। यह **Recursive Descent** और **Predictive Parsing** विधियों के माध्यम से किया जाता है। हालाँकि, यह केवल **LL(1) व्याकरण** के लिए उपयुक्त है और **Left Recursion** को सीधे संभाल नहीं सकता।
Related Post
- कंपाइलर क्या है? | Introduction of Compiler in Hindi
- Compiler में उपयोग किए जाने वाले प्रमुख डेटा संरचनाएं | Major Data Structures in Compiler in Hindi
- कंपाइलर के प्रकार | Types of Compiler in Compiler Design in Hindi
- कंपाइलर का फ्रंटएंड और बैकएंड | Frontend and Backend of Compiler in Compiler Design in Hindi
- एनालिसिस-सिंथेसिस मॉडल ऑफ़ कंपाइलेशन | Analysis-Synthesis Model of Compilation in Hindi
- कंपाइलर के विभिन्न चरण | Various Phases of a Compiler in Hindi
- लेक्सिकल एनालिसिस क्या है? | Lexical Analysis in Compiler Design in Hindi
- इनपुट बफरिंग क्या है? | Input Buffering in Compiler Design in Hindi
- लेक्सिकल एनालाइज़र जनरेटर का डिज़ाइन | Design of a Lexical Analyzer Generator in Compiler Design in Hindi
- Lex क्या है? | Lex in Compiler Design in Hindi
- सिंटैक्स एनालिसिस क्या है? | Syntax Analysis in Compiler Design in Hindi
- कॉन्ठेक्स्ट-फ्री व्याकरण (CFG) क्या है? | Context-Free Grammar in Compiler Design in Hindi
- टॉप-डाउन पार्सिंग क्या है? | Top-Down Parsing in Compiler Design in Hindi
- ब्रूट फोर्स एप्रोच क्या है? | Brute Force Approach in Compiler Design in Hindi
- Bottom-Up Parsing in Compiler Design in Hindi - बॉटम-अप पार्सिंग क्या है?
- Operator Precedence Parsing in Compiler Design in Hindi - ऑपरेटर प्रेसीडेंस पार्सिंग क्या है?
- LR Parsers (SLR, LALR, LR) in Compiler Design in Hindi - एलआर पार्सर क्या है?
- Parser Generation in Compiler Design in Hindi - पार्सर जेनरेशन क्या है?
- Construction of Syntax Tree in Compiler Design in Hindi - सिंटैक्स ट्री का निर्माण
- Bottom-Up Evaluation of S-Attributed Definition in Hindi - एस-अट्रिब्यूटेड परिभाषा का बॉटम-अप मूल्यांकन
- व्याकरण में परिवर्तन | Transformation on the Grammars in Compiler Design in Hindi
- Bottom-Up Evaluation of Inherited Attributes in Compiler Design in Hindi - इनहेरिटेड अट्रिब्यूट्स का बॉटम-अप मूल्यांकन
- Analysis of Syntax Directed Definition in Compiler Design in Hindi - सिंटैक्स डायरेक्टेड डिफिनिशन का विश्लेषण
- Type System in Compiler Design in Hindi - टाइप सिस्टम क्या है?
- Specification of Simple Type Checker in Compiler Design in Hindi - सिंपल टाइप चेकर का विवरण
- L-Attribute Definition in Compiler Design in Hindi - एल-अट्रिब्यूटेड परिभाषा क्या है?
- Top-Down Translation in Compiler Design in Hindi - टॉप-डाउन ट्रांसलेशन क्या है?
- Equivalence of Expression in Compiler Design in Hindi - एक्सप्रेशन की समकक्षता
- Type Conversion in Compiler Design in Hindi - टाइप कन्वर्ज़न क्या है?
- Overloading of Functions and Operations in Compiler Design in Hindi - फंक्शंस और ऑपरेशंस का ओवरलोडिंग
- Polymorphic Functions in Compiler Design in Hindi - पॉलीमॉर्फिक फंक्शंस क्या हैं?
- Run Time Environment in Compiler Design in Hindi - रन-टाइम एनवायरनमेंट क्या है?
- Storage Organization in Compiler Design in Hindi - स्टोरेज ऑर्गेनाइजेशन क्या है?
- Storage Allocation Strategies in Compiler Design in Hindi | स्टोरेज एलोकेशन रणनीतियाँ
- Parameter Passing in Compiler Design in Hindi | पैरामीटर पासिंग की रणनीतियाँ
- Dynamic Storage Allocation in Compiler Design in Hindi | डायनामिक स्टोरेज एलोकेशन
- Symbol Table in Compiler Design in Hindi | सिंबल टेबल
- Error Detection and Recovery in Compiler Design in Hindi | एरर डिटेक्शन और रिकवरी
- Ad-hoc and Systematic Methods in Compiler Design in Hindi | ऐड-हॉक और सिस्टमेटिक विधियाँ
- Intermediate Code Generation in Compiler Design in Hindi | इंटरमीडिएट कोड जेनरेशन
- Declarations in Compiler Design in Hindi | डिक्लेरेशन
- Assignment Statements in Compiler Design in Hindi | असाइनमेंट स्टेटमेंट्स
- Case Statements in Compiler Design in Hindi | केस स्टेटमेंट्स
- Back Patching in Compiler Design in Hindi | बैक पैचिंग
- Procedure Calls Code Generation in Compiler Design in Hindi | प्रोसीजर कॉल कोड जेनरेशन
- Issues in the Design of Code Generator in Compiler Design in Hindi | कोड जेनरेटर डिजाइन की समस्याएँ
- Basic Block and Flow Graphs in Compiler Design in Hindi | बेसिक ब्लॉक और फ्लो ग्राफ
- Register Allocation and Assignment in Compiler Design in Hindi | रजिस्टर एलोकेशन और असाइनमेंट
- DAG Representation of Basic Blocks in Compiler Design in Hindi | DAG रिप्रेजेंटेशन
- Peephole Optimization in Compiler Design in Hindi | पीपहोल ऑप्टिमाइजेशन
- Generating Code from DAG in Compiler Design in Hindi | DAG से कोड जेनरेशन
- Introduction to Code Optimization in Compiler Design in Hindi | कोड ऑप्टिमाइजेशन का परिचय
- Sources of Optimization of Basic Blocks in Compiler Design in Hindi | बेसिक ब्लॉक्स ऑप्टिमाइजेशन के स्रोत
- Loops in Flow Graphs in Compiler Design in Hindi | फ्लो ग्राफ्स में लूप्स
- Dead Code Elimination in Compiler Design in Hindi | डेड कोड एलिमिनेशन
- Loop Optimization in Compiler Design in Hindi | लूप ऑप्टिमाइजेशन
- Introduction to Global Data Flow Analysis in Compiler Design in Hindi | ग्लोबल डेटा फ्लो एनालिसिस का परिचय
- Code Improving Transformations in Compiler Design in Hindi | कोड इंप्रूविंग ट्रांसफॉर्मेशन