Intermediate Code Generation: Boolean Expressions | इंटरमीडिएट कोड जनरेशन में बूलियन अभिव्यक्तियाँ
इंटरमीडिएट कोड जनरेशन में बूलियन अभिव्यक्तियाँ (Boolean Expressions in Intermediate Code Generation)
Boolean Expressions Compiler Design के Intermediate Code Generation चरण में अत्यंत महत्वपूर्ण भूमिका निभाती हैं। किसी भी प्रोग्राम में निर्णय-निर्माण (decision-making) जैसे if, while, for आदि स्टेटमेंट्स Boolean Expressions पर आधारित होते हैं। Compiler इन Boolean Expressions को Intermediate Representation (IR) में बदलता है ताकि वे बाद में Machine Code में प्रभावी रूप से अनुवादित की जा सकें।
परिचय (Introduction)
Boolean Expression वे अभिव्यक्तियाँ हैं जिनका परिणाम true या false होता है। Compiler इन Expressions का मूल्यांकन Conditional Jumps और Logical Operations के माध्यम से करता है।
उदाहरण:
if (a < b)
c = a;
else
c = b;
Intermediate Representation में इसे Conditional Jump Instructions के रूप में लिखा जाता है।
Boolean Expression के प्रकार
- Relational Expressions — जैसे a < b, x >= y आदि।
- Logical Expressions — जैसे (a < b) && (c > d), (a != 0) || (b == 1)।
- Negation Expressions — जैसे !(a > b)।
Boolean Expressions के लिए Intermediate Representation
Compiler Boolean Expressions को Jump-Based Representation या Boolean Variables Representation के रूप में व्यक्त करता है।
1️⃣ Jump-Based Representation:
Boolean Expression का परिणाम Control Flow द्वारा नियंत्रित किया जाता है।
उदाहरण:
if (a < b)
x = 1;
else
x = 0;
Intermediate Code:
if a < b goto L1 x = 0 goto L2 L1: x = 1 L2:
2️⃣ Boolean Variable Representation:
Compiler एक Boolean Variable को 1 (true) या 0 (false) असाइन करता है।
b = (a < b)
Intermediate Code:
if a < b goto L1 b = 0 goto L2 L1: b = 1 L2:
Relational Operators और उनका Intermediate Code
| Operator | Meaning | Intermediate Form |
|---|---|---|
| < | Less than | if a < b goto L1 |
| > | Greater than | if a > b goto L1 |
| == | Equal to | if a == b goto L1 |
| != | Not equal to | if a != b goto L1 |
| <= | Less than or equal | if a <= b goto L1 |
| >= | Greater than or equal | if a >= b goto L1 |
Logical Operators और Short-Circuit Evaluation
Compiler Boolean Expressions के Evaluation में Short-Circuit नियमों का उपयोग करता है। इसका अर्थ है कि अगर किसी लॉजिकल एक्सप्रेशन का परिणाम पहले ही तय हो गया है, तो बाकी हिस्से को Evaluate नहीं किया जाता।
उदाहरण:
if (a < b && c < d)
x = 1;
else
x = 0;
Intermediate Code:
if a < b goto L1 goto L4 L1: if c < d goto L2 goto L4 L2: x = 1 goto L3 L4: x = 0 L3:
Boolean Expressions के लिए Backpatching
Backpatching एक तकनीक है जो Boolean Expressions में Jump Addresses को Compile-Time पर Placeholder के रूप में रखती है और बाद में उन्हें Final Addresses से बदल देती है।
उदाहरण:
if (a < b || c > d)
x = 1;
else
x = 0;
Intermediate Code:
if a < b goto L1 if c > d goto L1 goto L2 L1: x = 1 goto L3 L2: x = 0 L3:
Boolean Expressions और Control Flow Graphs
Compiler Boolean Expressions को Control Flow Graphs (CFG) में Nodes और Edges के रूप में प्रदर्शित करता है। True Branch और False Branch अलग-अलग Flow Paths को दर्शाते हैं।
Flow Graph:
- Node 1 → Evaluate (a < b)
- True Edge → Execute True Block
- False Edge → Execute False Block
Intermediate Code Optimization
Boolean Expressions के लिए Compiler कई Optimization Techniques लागू करता है:
- Dead Code Elimination — अनावश्यक Jump हटाना।
- Constant Folding — Constant Conditions पहले से Evaluate करना।
- Short Circuit Simplification — && और || ऑपरेटर्स के अनावश्यक Evaluations हटाना।
Boolean Expressions में Type Conversion
Boolean Expressions में Type Mismatch होने पर Compiler Implicit Conversion करता है ताकि Integer और Float Values को Logical रूप में बदला जा सके।
उदाहरण:
if (x) y = 1; else y = 0;
Intermediate Code:
if x != 0 goto L1 y = 0 goto L2 L1: y = 1 L2:
निष्कर्ष (Conclusion)
Compiler Design में Boolean Expressions का Intermediate Code Generation चरण प्रोग्राम के नियंत्रण प्रवाह (control flow) को परिभाषित करता है। इन Expressions के माध्यम से Conditional Statements और Loop Constructs को मशीन-स्वतंत्र रूप में व्यक्त किया जाता है। Jump Instructions, Backpatching, और Short-Circuit Evaluation जैसी तकनीकें Compiler को अधिक कुशल और विश्वसनीय कोड बनाने में सक्षम बनाती हैं।
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 | ऑप्टिमाइज़्ड कोड का प्रतीकात्मक डीबगिंग