Compilation क्या है? | what is Compilation in Hindi

Arpit Nageshwar
⏰ 6 min read

Compilation क्या है? What is Compilation in Hindi

Table of Contents

Introduction to Compilation in Hindi – Compiler क्या है?

  • जब भी हम कोई program C, C++ या Java जैसी किसी high-level language में लिखते हैं, तो computer उसको सीधा समझ नहीं पाता, क्योंकि computer सिर्फ binary language (0 और 1) ही समझता है।

  • यहीं पर Compiler का role आता है — Compiler एक ऐसा special software tool होता है जो हमारे लिखे हुए source code को machine-understandable code (object code या machine code) में convert कर देता है।

  • इस पूरी process को ही Compilation कहते हैं, यानी source code को target code (usually machine code) में बदलने का process।

  • सबसे important बात यह है कि Compiler पूरे program को एक साथ पढ़ता है, फिर उसमें errors check करता है, और अगर कोई error न मिले तो तभी वो पूरे program का equivalent machine code generate करता है।

  • इसका मतलब यह हुआ कि compilation एक "translate first, run later" वाली strategy follow करता है — जब तक translation successfully complete नहीं होती, program run ही नहीं होता।

  • रोज़-मर्रा की life में इसका example समझना हो तो सोचो कि आप एक Hindi किताब को पूरी तरह English में translate करा रहे हो, और translator पूरी किताब पढ़कर ही final English version देता है, chapter-by-chapter तुरंत translate करके नहीं सुनाता — Compiler भी कुछ ऐसा ही करता है।

  • Exam की language में definition याद रखनी हो तो: "Compilation is the process of translating source code written in a high-level language into machine-level (or intermediate) code, so that the computer's hardware can execute it."

  • GCC, Turbo C, Javac जैसे tools compiler के ही real-world examples हैं जिनका use programmers रोज़-मर्रा में करते हैं।

  • यह समझना भी ज़रूरी है कि compiler खुद program को run नहीं करता — वो सिर्फ translation करता है, actual execution CPU और operating system के through होती है जब final executable file load की जाती है।

  • Compiler की term अक्सर exams में Interpreter के साथ confuse होती है, इसलिए शुरू में ही यह clear रखना चाहिए कि दोनों का काम translation का ही है, बस उनका तरीका अलग होता है — यह detail हम आगे difference वाले section में देखेंगे।

Functions of Compilation in Hindi – Compiler के काम

  • 1. Source Code को पढ़ना (Reading Source Code):
    सबसे पहला काम compiler का यह होता है कि वो programmer द्वारा लिखे गए पूरे source code को character-by-character read करे।

  • 2. Code को Analyse करना (Analysis):
    Compiler code को छोटी-छोटी units में तोड़कर यह check करता है कि grammar (syntax) सही है या नहीं, और meaning (semantics) सही बन रहा है या नहीं।

  • 3. Errors को Detect करना:
    अगर code में कोई spelling mistake, missing semicolon, या wrong data type जैसी गलती हो, तो compiler उसको तुरंत detect करके error message देता है।

  • 4. Code को Translate करना:
    सबसे core function यही है — high-level language के code को machine-level या intermediate code में convert करना, ताकि hardware उसे execute कर सके।

  • 5. Code को Optimize करना:
    Compiler सिर्फ translate ही नहीं करता, बल्कि generated code को ऐसा बनाने की कोशिश भी करता है कि वो कम time और कम memory में चले।

  • 6. Symbol Table Maintain करना:
    पूरी compilation के दौरान compiler एक internal table बनाता है जिसमें variables, functions, और उनके types की जानकारी store रहती है, ताकि बाद के phases में reference करना आसान हो।

  • 7. Final Executable बनाना:
    सबसे आख़िर में compiler (linker की मदद से) एक ऐसी executable file बनाता है जिसे directly run करके program का output देखा जा सकता है।

  • 8. Portability Provide करना:
    कुछ compilers intermediate या platform-independent code भी generate करते हैं (जैसे Java का bytecode), जिससे एक ही program अलग-अलग operating systems पर बिना दोबारा लिखे चल सकता है।

इनमें से पहले तीन functions — reading, analysis और error detection — को मिलाकर अक्सर "Analysis Phase" भी कहा जाता है, जबकि translation, optimization और final code बनाने वाले part को "Synthesis Phase" कहा जाता है। Exam में यह दो-हिस्सों वाली division (Analysis और Synthesis) भी काफ़ी बार पूछी जाती है, इसलिए इसे याद रखना helpful रहता है।

Phases of Compilation in Hindi – Compiler के Phases

Phases of Compilation 1. Lexical Analysis Source code को tokens में तोड़ना 2. Syntax Analysis (Parsing) Grammar check करके Parse Tree बनाना 3. Semantic Analysis Meaning और type-checking verify करना 4. Intermediate Code Generation एक बीच का simple code बनाना 5. Code Optimization Code को fast और efficient बनाना 6. Code Generation Final machine/target code बनाना Symbol Table हर phase से जुड़ कर update होती रहती है Error Handler हर phase पर गलती पकड़ता और report करता है Exam में ये 6 phases sequence के साथ याद रखना important है
  • 1. Lexical Analysis (Scanning):
    यह compilation का सबसे पहला phase होता है, जिसमें source code को character-by-character पढ़कर छोटी-छोटी meaningful units में तोड़ा जाता है, जिन्हें "tokens" कहा जाता है (जैसे keywords, identifiers, operators, constants)।

    इस phase को करने वाले part को Lexical Analyzer या Scanner भी कहते हैं, और अगर कोई invalid character मिलता है तो यहीं पर सबसे पहले error पकड़ा जाता है।

  • 2. Syntax Analysis (Parsing):
    इस phase में tokens को language के grammar rules के against check किया जाता है, और एक tree-जैसी structure बनाई जाती है जिसे Parse Tree या Syntax Tree कहते हैं।

    अगर statement की grammar गलत हो, जैसे bracket का missing होना, तो यहीं पर syntax error report होता है।

  • 3. Semantic Analysis:
    सिर्फ grammar सही होना काफ़ी नहीं होता, statement का "meaning" भी सही होना चाहिए — जैसे दो अलग data types को directly add करने की कोशिश करना गलत semantic है।

    इस phase में type-checking, variable declaration check, और scope-related rules verify किए जाते हैं।

  • 4. Intermediate Code Generation:
    इस step में source code का एक ऐसा intermediate (बीच का) form बनाया जाता है जो न तो पूरी तरह high-level होता है, न ही पूरी तरह machine-level — जैसे Three-Address Code।

    इससे आगे optimization और target-code generation करना आसान हो जाता है।

  • 5. Code Optimization:
    इस phase में intermediate code को इस तरह improve किया जाता है कि final program कम time ले और कम memory use करे, बिना उसके original meaning को बदले।

    जैसे repeated calculations को हटा देना या unused variables को remove करना इस phase के under आता है।

  • 6. Code Generation:
    यह आख़िरी phase होता है, जिसमें optimized intermediate code को actual target machine code (जैसे assembly या binary) में convert कर दिया जाता है, जो hardware directly समझ सके।

इन सभी phases के साथ दो supporting components भी लगातार काम करते रहते हैं — Symbol Table Manager, जो हर नए variable या function की entry symbol table में add या update करता है, और Error Handler, जो किसी भी phase में गलती मिलते ही उसे detect करके user को meaningful error message देता है। ये दोनों components पूरी compilation के दौरान background में active रहते हैं, इसलिए इन्हें diagram में अलग से side boxes के रूप में दिखाया गया है।

Compilation Process in Hindi – Step by Step Process

  • 1. Source Program लिखना:
    सबसे पहले programmer एक high-level language (जैसे C या C++) में source code लिखता है और उसे .c या .cpp जैसी file में save करता है।

  • 2. Preprocessing:
    Preprocessor source file में दी गई directives (जैसे #include, #define) को process करता है और एक expanded source code तैयार करता है।

  • 3. Compilation (Phases Run करना):
    यहाँ पर ऊपर बताए गए 6 phases (Lexical से लेकर Code Generation तक) एक के बाद एक चलते हैं और target/assembly code तैयार होता है।

  • 4. Assembly:
    Assembler generated assembly code को object code (machine-readable binary form, जैसे .obj file) में convert कर देता है।

  • 5. Linking:
    Linker अलग-अलग object files को और required library functions को आपस में जोड़ता है, ताकि एक complete executable program बन सके।

  • 6. Loading और Execution:
    Loader final executable file को memory में load करता है, और उसके बाद CPU उस program को step-by-step execute करके output देता है।

Exam में अक्सर पूछा जाता है कि "Compile-time" और "Run-time" में क्या फ़र्क है। Simple तरीके से याद रखना हो तो — जब तक ऊपर वाले steps 1 से 5 तक चल रहे हैं, उसे Compile-time कहा जाता है, और जब step 6 में program actually execute हो रहा होता है, उसे Run-time कहा जाता है। बहुत सारी errors (जैसे syntax या semantic errors) compile-time पर ही पकड़ी जाती हैं, जबकि कुछ errors (जैसे divide by zero) सिर्फ run-time पर ही पता चलती हैं — यही वजह है कि compilation और execution को दो अलग stages माना जाता है।

Compilation Errors in Hindi – Compiler Errors के Types

  • 1. Lexical Errors:
    जब source code में कोई ऐसा character या symbol लिखा हो जो language के tokens में fit ही नहीं होता, जैसे गलत symbol का use, तो Lexical Analysis phase में ही यह error पकड़ा जाता है।

  • 2. Syntax Errors:
    यह सबसे common error type है, जब code language के grammar rules follow नहीं करता — जैसे semicolon missing होना, bracket match न होना, या keyword गलत जगह लिखना।

  • 3. Semantic Errors:
    यह तब होती हैं जब syntax तो सही हो, पर statement का meaning गलत हो — जैसे किसी undeclared variable को use करना या incompatible data types को आपस में operate करना।

  • 4. Logical Errors:
    यह error compiler कभी पकड़ ही नहीं पाता, क्योंकि program syntactically और semantically सही होता है, लेकिन उसका logic ही गलत होता है जिससे output expected से different आता है।

  • 5. Linker Errors:
    Compilation के बाद, linking step के दौरान अगर कोई function या library reference नहीं मिल पाता, तो linker error आता है — जैसे "undefined reference" message।

  • 6. Runtime Errors:
    यह compilation के बाद, program को actually run करते वक़्त आती हैं — जैसे zero से divide करना या array की limit से बाहर access करना।

एक helpful tip यह है कि Lexical, Syntax, Semantic और Linker errors को collectively "Compile-time Errors" कहा जाता है, क्योंकि इन्हें compiler execution शुरू होने से पहले ही पकड़ लेता है। इसके against, Runtime और Logical errors को "Post-compilation Errors" की category में रखा जा सकता है, क्योंकि इनका पता सिर्फ program चलने के बाद ही चलता है। Exam के objective-type questions में यह categorization अक्सर directly पूछी जाती है।

Advantages of Compiler over Interpreter in Hindi

  • Compiler पूरे program को एक साथ translate करके machine code बना देता है, इसलिए final execution interpreter के comparison में काफ़ी fast होता है।

  • एक बार compile हो जाने के बाद, program को बार-बार translate करने की ज़रूरत नहीं पड़ती — direct executable file ही run हो जाती है।

  • Compiler पूरे code को पहले ही check कर लेता है, इसलिए program run होने से पहले ही maximum errors पकड़ लिए जाते हैं, जिससे debugging का काफ़ी काम पहले ही हो जाता है।

  • Compilation के दौरान code optimization भी possible होता है, जिससे final program memory और time दोनों में efficient बन जाता है।

  • एक बार generated executable file को उस source code के बिना भी बार-बार distribute और run किया जा सकता है, जो security और portability के लिए फ़ायदेमंद है।

  • Large-scale software projects में, जहाँ लाखों lines of code होती हैं, compiler जैसा approach ज़्यादा practical होता है क्योंकि पूरे project का behavior एक ही बार में verify हो जाता है, interpreter की तरह हर बार step-by-step check नहीं करना पड़ता।

इसका मतलब यह नहीं कि interpreter हमेशा कमज़ोर होता है — interpreter अपनी जगह फ़ायदेमंद है जब quick testing, debugging या scripting जैसा काम करना हो, जहाँ program को तुरंत-तुरंत modify करके चलाना हो। लेकिन जब बड़े, performance-critical applications बनानी हों (जैसे operating systems, games या system software), तब compiler का approach ज़्यादा suitable माना जाता है।

Difference Between Compiler and Interpreter in Hindi

Compiler vs Interpreter Compiler • पूरा program एक साथ translate करता है • Execution fast होता है • Errors एक साथ (end में) दिखाता है • Separate executable file बनती है • Source code बाद में ज़रूरी नहीं • Memory ज़्यादा use होती है • Example: GCC, Turbo C Interpreter • Line-by-line translate और execute करता है • Execution comparatively slow होता है • Error मिलते ही तुरंत रोक देता है • कोई separate executable नहीं बनती • Source code हमेशा चाहिए होता है • Memory कम use होती है • Example: Python, JavaScript

यह table format में भी देख सकते हैं, जो exam में लिखने के लिए सबसे convenient होता है:

Point Compiler Interpreter
Translation पूरा program एक साथ translate करता है हर line को अलग-अलग translate करता है
Speed Execution fast होता है Execution थोड़ा slow होता है
Error Reporting सारे errors एक साथ, program end में जैसे ही error मिले, तुरंत रोक देता है
Output अलग से executable file बनती है कोई अलग executable file नहीं बनती
Source Code Dependency बाद में source code की ज़रूरत नहीं हर बार source code चाहिए होता है
Example C, C++ (GCC, Turbo C) Python, JavaScript

Frequently Asked Questions (FAQ) – Compiler in Hindi

Compiler एक software tool होता है जो high-level language में लिखे गए source code को machine-level code में translate करता है, ताकि computer उसे execute कर सके।

Compilation के मुख्य 6 phases होते हैं — Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code Generation, Code Optimization और Code Generation।

Compiler पूरे program को एक साथ translate करके executable file बनाता है, जबकि Interpreter program को line-by-line translate और execute करता है।

मुख्य रूप से Lexical, Syntax, Semantic, Logical, Linker और Runtime errors — ये compilation और execution के दौरान आने वाले common error types हैं।

Symbol table compilation के दौरान variables, functions और उनके data types की जानकारी store करती है, जिससे compiler के अलग-अलग phases उसे reference कर सकें।

Compile-time errors (जैसे syntax या semantic errors) program run होने से पहले ही compiler द्वारा पकड़ी जाती हैं, जबकि run-time errors (जैसे divide by zero) program actually execute होते वक़्त सामने आती हैं।

Analysis phase में source code को पढ़कर, tokens बनाकर और errors check करके उसका structure समझा जाता है, जबकि Synthesis phase में उस समझे हुए structure से target code generate किया जाता है।

Arpit Nageshwar

✍️ Arpit Nageshwar

Post-graduated | Web Developer | +3 yr Experience | IIT Kharagpur Certified