Lexical Analyzer | Lexical Analysis | Compiler Design

THE GATEHUB
6 Jan 202414:53

Summary

TLDRThe provided script discusses the role of the lexical analyzer, the first phase of a compiler, in detail. It explains how the lexical analyzer, also known as the scanner, scans the source program and converts it into meaningful tokens such as identifiers, keywords, operators, and constants. The script further delves into the process of syntax analysis, error handling, and the importance of the lexical analyzer in providing error messages with line and column numbers, which is crucial for debugging. It also touches upon the concept of semantic analysis and type checking in the context of a compiler.

Takeaways

  • 📘 The Lexical Analyzer, also known as the Scanner, is the first phase of the compiler which divides the given program into meaningful words called tokens.
  • 🔍 The Lexical Analyzer scans the program and converts it into tokens such as identifiers, keywords, operators, constants, and special symbols.
  • 🔑 Identifiers can be variable names and keywords are predefined words in a programming language like 'if', 'else', 'while', 'for', etc.
  • ➗ The Lexical Analyzer eliminates white space characters like blank spaces and tabs, which are not significant in the program.
  • 👀 The script discusses the importance of the Lexical Analyzer in providing error messages with line and column numbers, which help in debugging.
  • 🌐 The process of the Lexical Analyzer involves accessing the symbol table to understand the context of tokens and identifiers within the program.
  • 🔄 The script mentions the iterative process of the compiler, where each phase like the parser and semantic analyzer builds upon the tokens provided by the Lexical Analyzer.
  • 🔍 The Parser, as part of the compiler, constructs a syntax tree based on the tokens received from the Lexical Analyzer and defined grammar rules.
  • 📊 The Semantic Analyzer checks for type matching and other semantic rules after the syntax tree is constructed by the Parser.
  • 🛠️ The script explains the interaction between the Lexical Analyzer, Parser, and Semantic Analyzer in the context of compiling a program.
  • ⚠️ The Compiler does not stop at syntax errors; it scans the entire program and lists all errors, which is crucial for understanding the compilation process.

Q & A

  • What is the role of a Lexical Analyzer in a compiler?

    -The Lexical Analyzer, also known as the scanner, is the first phase of a compiler. It reads the source code and converts it into meaningful tokens, which are the smallest units of the programming language that carry meaning.

  • What are tokens in the context of lexical analysis?

    -Tokens are the meaningful sequences of characters identified by the lexical analyzer. They can represent identifiers, keywords, symbols, operators, and constants from the source code.

  • How does the Lexical Analyzer process the input program?

    -The Lexical Analyzer scans the input program character by character, groups them into tokens, and eliminates whitespace characters such as spaces and tabs.

  • What are the different types of tokens that a Lexical Analyzer can generate?

    -The types of tokens include identifiers, keywords, operators, constants (like numeric values), and special symbols (like commas and semicolons).

  • What is the purpose of the Syntax Analyzer in a compiler?

    -The Syntax Analyzer, also known as the parser, checks the sequence of tokens to ensure they follow the grammar rules of the programming language, constructing a parse tree or syntax tree in the process.

  • How does the Syntax Analyzer interact with the Lexical Analyzer?

    -The Syntax Analyzer requests tokens from the Lexical Analyzer using a function like 'Get Token'. Based on the current context and the token received, the Syntax Analyzer decides which production rule to apply.

  • What happens if there is a mismatch between expected and actual tokens during syntax analysis?

    -If a mismatch occurs, it indicates a syntax error. The compiler typically has an error handler that records the error, provides information about the location of the error, and may continue parsing the rest of the program.

  • Why is it important for the Lexical Analyzer to provide line and column information for errors?

    -Line and column information is crucial for developers as it helps them locate and fix syntax errors in the source code more easily.

  • Can you explain the implicit type conversion that the Semantic Analyzer checks for?

    -Implicit type conversion is when the compiler automatically converts one data type to another without explicit programmer instruction. The Semantic Analyzer checks for situations like assigning a smaller integer value to a floating-point variable, which can be done without data loss.

  • What is the role of the Semantic Analyzer in the compilation process?

    -The Semantic Analyzer is responsible for checking the semantic validity of the program, including type checking, scope resolution, and other semantic rules defined by the programming language.

  • How does the compiler handle syntax errors during the compilation process?

    -The compiler does not stop the compilation process upon encountering a syntax error. Instead, it records the error, provides details about the location, and continues to scan and analyze the rest of the program to identify additional errors.

Outlines

00:00

📘 Compiler Phases and Lexical Analyzer

The script introduces the concept of compiler phases, focusing on the lexical analyzer. It explains the role of the lexical analyzer in dividing the source code into meaningful words or tokens, such as identifiers, keywords, operators, and constants. The lexical analyzer scans the program and converts it into tokens, which are then used by subsequent compiler phases. The script also briefly mentions syntax analyzers and parsers, indicating they will be discussed in more detail later.

05:01

🔍 Parsing and Syntax Analysis

This paragraph delves deeper into the parsing process, where the syntax analyzer generates a syntax tree based on grammar rules. It describes how the parser requests tokens from the lexical analyzer and matches them against production rules to construct the parse tree. The script also discusses error handling during parsing, explaining how syntax errors are reported and managed without stopping the compilation process, ensuring the entire program is scanned for errors.

10:04

🔧 Semantic Analysis and Error Reporting

The final paragraph discusses semantic analysis, where the semantic analyzer checks for type matching and other semantic rules after the syntax tree has been constructed. It explains how the semantic analyzer interacts with the symbol table and how it handles type mismatches, reporting semantic errors to the error handler, which records the error details, including line and column numbers, to provide meaningful error messages to the user without halting the compilation process.

Mindmap

Keywords

💡Compiler

A compiler is a specialized program that translates source code written in a particular programming language into machine code that a computer can execute. In the video, the compiler's role is central as it processes the source program through various stages, including lexical analysis, syntax analysis, and semantic analysis.

💡Lexical Analyzer

The lexical analyzer, also referred to as the scanner in the script, is the first phase of the compiler. It reads the source code and converts the sequence of characters into meaningful tokens. The script explains that it divides the given program into meaningful words, which are essential for further processing.

💡Tokens

Tokens are the atomic units identified by the lexical analyzer. They represent meaningful symbols in the source code, such as identifiers, keywords, operators, and constants. The script provides examples of tokens like identifiers (variable names), keywords (reserved words in a language like 'if', 'while'), and operators.

💡Syntax Analyzer

The syntax analyzer, also known as the parser in the script, takes the stream of tokens from the lexical analyzer and checks if they conform to the language's grammar rules. It constructs a parse tree or syntax tree that represents the grammatical structure of the code, which is crucial for understanding the program's logic.

💡Semantic Analyzer

The semantic analyzer is responsible for checking the meaning of the syntax tree generated by the syntax analyzer. It ensures that the program is semantically correct, such as type checking and symbol table management. The script mentions it in the context of type mismatches and implicit conversions.

💡Identifiers

Identifiers are names given to program elements such as variables, functions, or classes. The lexical analyzer recognizes these as tokens during the scanning process. The script discusses identifiers in the context of variable names and their attributes like type.

💡Keywords

Keywords are reserved words in a programming language that have special meanings and cannot be used as identifiers. The script mentions keywords in the context of predefined words in a language like 'if', 'else', 'while', which are used to define the flow of control in a program.

💡Operators

Operators are symbols that represent operations in a programming language, such as arithmetic operations (+, -, *, /) or logical operations (&&, ||). The lexical analyzer converts these symbols into tokens that the syntax analyzer can process.

💡Constants

Constants are fixed values that do not change during program execution, such as numeric literals (e.g., 100, 100.3). The lexical analyzer identifies these and converts them into tokens, which are then used by subsequent compiler phases.

💡Special Symbols

Special symbols, such as commas (,) and semicolons (;), are punctuation marks used in programming languages to separate statements or declare boundaries. The lexical analyzer recognizes these and converts them into tokens, which are important for the syntax analysis.

💡Syntax Error

A syntax error occurs when the code does not conform to the language's grammar rules. The script discusses how the syntax analyzer detects such errors and communicates them to the error handler, which then provides feedback to the programmer about the location and nature of the error.

💡Error Handler

The error handler is responsible for managing errors detected during the compilation process. It receives error reports from the compiler's various stages and records the errors, including their location in the source code, to provide meaningful error messages to the programmer.

Highlights

The first phase of the compiler is the lexical analyzer, also known as a scanner.

The lexical analyzer divides the given program into meaningful words called tokens.

Tokens can be identifiers, keywords, operators, constants, or special symbols.

The lexical analyzer scans the source program and converts it into tokens.

Identifiers can be variable names, array names, etc.

Keywords are predefined words in a programming language like 'if', 'else', 'while', etc.

Operators include assignment operators, comparison operators, relational operators, etc.

Constants are constant values like 100, 100.3, etc.

Special symbols include characters like commas, semicolons, etc.

The lexical analyzer removes whitespace characters like blanks and tabs.

Syntax analyzer (parser) starts after the lexical analyzer and constructs a syntax tree.

The parser verifies the tokens received from the lexical analyzer based on production rules.

The parser generates an error message if a syntax error is found, reporting it to the error handler.

The error handler notes down the error with the row and column numbers provided by the lexical analyzer.

Semantic analyzer checks for type mismatches and other semantic errors during compilation.

The compilation process continues even if errors are found, scanning the entire program.

Lexical analyzer helps in giving error messages by providing row and column numbers of errors.

The entire compilation process involves six phases that are executed simultaneously as needed.

Transcripts

play00:00

सो अब डिस्कस करते हैं कंपाइलर का फर्स्ट

play00:02

फेज जो कि है आपका लेक्सिक एनालाइजर ओके

play00:05

फेजेस ऑफ कंपाइलर ऑलरेडी हम लोग डिस्कस कर

play00:07

चुके हैं कि किस तरीके से हर एक फेज का

play00:08

क्या काम होता है अब हर एक फेज के बारे

play00:10

में हम लोग डिटेल में डिस्कस करेंगे तो

play00:12

लेक्सिक एनालाइजर क्या होता है तो फर्स्ट

play00:14

लाइन देखते हैं लेक्सिक एनालाइजर डिवाइड्स

play00:17

द गिवन प्रोग्राम इनटू मीनिंगफुल वर्ड्स

play00:20

व्हिच इज नोन एज स्टोकन तो लेक्सिक

play00:22

एनालाइजर क्या करता है लेक्सिक एनालाइजर

play00:23

जो भी आपका प्रोग्राम दिया हुआ है ठीक है

play00:25

उसको क्या करता है स्कैन करता है इसलिए एक

play00:27

एनालाइजर को हम स्कैनर भी कहते हैं ओके तो

play00:30

प्रोग्राम को स्कैन करेगा और उसके बाद

play00:31

इसको मीनिंगफुल वर्ड्स में कन्वर्ट कर

play00:33

देगा जिसको हम टोकन कहते हैं ओके टोकन

play00:36

क्या होता है बेसिकली टोकेंस आर नॉर्मली

play00:38

आइडेंटिफिकेशन

play00:42

सिंबल

play00:44

आइडेंटिफिकेशन

play00:46

नेम हो सकता है एरे नेम ये सारे क्या होते

play00:49

हैं आपके आइडेंटिफिकेशन

play00:50

होता है नेक्स्ट क्या है कीवर्ड तो कीवर्ड

play00:54

वो सारे वर्ड्स होते हैं किसी भी जैसे मान

play00:55

लीजिए अगर सी प्रोग्रामिंग की बात करें तो

play00:56

उसमें कुछ प्री डिफाइंड वर्ड्स होते हैं

play00:58

जैसे इफ हो गया एल्स हो गया वाइल हो गया

play00:59

हो गया फॉर लूप हो ये सारे क्या होते हैं

play01:01

कीवर्ड्स होते हैं तो वो भी क्या होता है

play01:03

आपका टोकन होता है नेक्स्ट ऑपरेटर तो बहुत

play01:06

सारे ऑपरेटर होते हैं अगर आपका असाइनमेंट

play01:08

ऑपरेटर है कंपैरिजन ऑपरेटर है रिलेशनल

play01:10

ऑपरेटर ये सारे ऑपरेटर तो ये सब भी क्या

play01:12

आएंगे टोकेंस ही होंगे कांस्टेंट कोई भी

play01:15

कांस्टेंट वैल्यू हो गई लेट्स सपोज है 100

play01:18

100.3 ये सारे कांस्टेंट वैल्यू हो गई

play01:20

स्पेशल सिंबल का मतलब ये हुआ कि जैसे आपका

play01:22

कॉमा हो गया सेमी कॉलन हो ग ये सारे

play01:24

स्पेशल सिंबल में आ गए तो लेक्सिक

play01:27

एनालाइजर को क्या कहते हैं स्कैनर उसका

play01:28

काम क्या होता है प्रोग्राम को स्कैन

play01:30

करेगा और उसको मीनिंगफुल वर्ड्स में

play01:31

कन्वर्ट करेगा जिसको हम टोकन कहते हैं ओके

play01:34

अब बाकी जो पॉइंट्स है वो अभी बाद में

play01:35

डिस्कस करते हैं अब आते हैं इस डायग्राम

play01:37

पे ये डायग्राम क्या है ये आपका लेक्सिक

play01:39

एनालाइजर है तो लेक्सिक एनालाइजर के लिए

play01:41

क्या होगा ये आपका इनपुट जो होगा वो क्या

play01:43

होगा आपका सोर्स प्रोग्राम ओके लेट्स सपोज

play01:46

हम एप कोई भी आपका सी प्रोग्राम है वो

play01:48

सोर्स प्रोग्राम किसके लिए होगा लेक्सिक

play01:49

एनालाइजर के लिए अब यहां क्या है दूसरे

play01:52

बॉक्स में क्या लिखा हुआ है पार्सर पार्सर

play01:53

का मतलब सिंटेक्स एनालाइजर कहीं अगर

play01:55

सिंटेक्स एनालाइजर लिखा हुआ है या पार्सल

play01:57

लिखा हुआ है बोथ आर सेम ओके अब देखो

play02:00

और अभी हम लोग जो फेजस ऑफ कंपाइलर में

play02:02

डिस्कस किए कि हर एक फेज जो कंपाइलर का

play02:04

होता है वो सिंबल टेबल को एक्सेस करता कोई

play02:06

अगर डटा स्टोर करना है स्टोर कर सकता है

play02:08

या उसको यूज करना है तो यूज कर सकता है

play02:10

ओके इसलिए हमने दोनों तरफ एरो दिखाई हु है

play02:12

कि मतलब इसमें हम डाटा स्टोर भी कर रहे

play02:15

हैं और उसको एक्सेस भी कर रहे अब देखो

play02:17

कैसे यह काम करेगा तो सबसे पहले सबसे पहला

play02:21

जो कंपाइलर का फेज है पहले चीज ये हम लोग

play02:24

पहले क्लियर कर लेते हैं कंपाइलर के जो

play02:26

फेजेस होते हैं वो वन बाय वन एग्जीक्यूट

play02:28

नहीं होते जैसे ही र आपका एग्जीक्यूट होगा

play02:30

कोई भी प्रोग्राम है अगर उसको हम कंपाइल

play02:32

करेंगे तो उसमें टोटल छह फेजस होते हैं तो

play02:35

छह फंक्शन है लेट्स अजूम तो वो सारे क्या

play02:37

हो जाएंगे एक्टिवेट हो जाएंगे मतलब वो रन

play02:39

करना शुरू हो जाएंगे और यह साइमल नियस रन

play02:42

करते हैं जब जिसकी जहां जरूरत पड़ती है वो

play02:44

वहां पहुंच जाता है ओके मतलब पहुंच जाता

play02:46

मतलब फेजेस की बात कर रहे हैं तो ऐसा नहीं

play02:48

कि पहले लेक्सिक आपका कंप्लीट हो जाएगा

play02:50

उसके बाद फिर सिंटेक्स स्टार्ट होगा फिर

play02:51

सेटक नहीं जब जहां जिसकी रिक्वायरमेंट

play02:54

होगी वो आपका एग्जीक्यूट होगा तो सबसे

play02:56

पहले कौन एग्जीक्यूट होता है सबसे पहले

play02:58

सिंटेक्स एनालाइजर स्टार्ट होता है कैसे

play03:00

होता है पहले हम एक एग्जांपल ले लेते हैं

play03:01

लेट्स सपोज यह आपका एक प्रोग्राम है ओके

play03:04

यह आपका प्रोग्राम है लेट्स सपोज लाइन

play03:06

नंबर वन लाइन नंबर टू लाइन नंबर थ्री एंड

play03:09

सो ऑन लाइन नंबर लेट्स सपोज 10 एंड सो ऑन

play03:12

लाइन नंबर 100 ओके लेट्स सपोज 100 रो दैट

play03:15

मींस 100 लाइन का मतलब 100 रो है और यह

play03:18

आपका क्या हो गया फर्स्ट कॉलम सेकंड कॉलम

play03:20

थर्ड कॉलम एंड सो ऑन लेट्स सपोज यह आपका

play03:23

10थ कॉलम हो गया और यह हो गया आपका लेट्स

play03:26

सपोज 50 तो इसका मतलब 50 कॉलम है और 100

play03:30

रो का प्रोग्राम ये अंपन लेके चल रहे है

play03:32

तो सबसे पहले क्या करेगा पार्सर पार्सर

play03:34

क्या है सिंटेक्स एनालाइजर तो सिंटेक्स

play03:35

एनालाइजर का काम क्या होता है सिंटेक्स

play03:37

ट्री ड्र करना तो सिंटेक्स ड्र करने के

play03:40

लिए लेट्स सपोज हमने कुछ ग्रामर्स लिख दिए

play03:41

एस राइव्स मतलब यहां कुछ लिख नहीं रहे ओके

play03:44

यहां कुछ प्रोडक्शन है ओके ये सारी

play03:47

प्रोडक्शन

play03:48

है तो अब क्या होगा सिंटेक्स एनालाइजर दैट

play03:51

मींस पार्सर क्या करेगा लेक्सिक एनालाइजर

play03:53

को पूछेगा गेट टोकन दैट मींस वो क्या

play03:56

करेगा हमको कोई टोकन देक हमें पासरी जनरेट

play03:58

करनी है और वो इनिशियली कहां होगा स्टार्ट

play04:00

सिंबल पे और आपका स्कैनर दैट मी वो कहां

play04:03

से स्टार्ट करेगा यहां पे तो अभी करंट

play04:05

सिचुएशन में पार्सर कहां है स्टार्टिंग

play04:07

सिंबल पे है और जो आपका स्कैनर दैट मींस

play04:10

लेक्सिक एलाइजर वो क्या है फर्स्ट रो

play04:12

फर्स्ट कॉलम यानी फर्स्ट सिंबल वो रीड कर

play04:13

रहा है तो पहला पहला जो फेज एक्टिवेट होगा

play04:16

दैट मीस पहला जो फेज रन होगा कंपाइलर का

play04:19

वो क्या होगा पार्सर होगा ना कि लेक्स

play04:21

लाइजर ये क्या करेगा ये एक फंक्शन कॉल है

play04:23

फंक्शन कॉल का मतलब गेट टोकन का मतलब ये

play04:26

लेक्स एनालाइजर से पूछेगा कि टोकन मुझे

play04:28

सेंड करो दैट मींस इस इसकी तरफ से जो एरो

play04:30

दिखाया सेंड टोकन तो लेक्सिक एनालाइजर

play04:33

क्या करेगा पार्सर को टोकन सेंड करेगा

play04:35

उसके बेसिस पे वो क्या करेगा पार्स जनरेट

play04:36

करेगा पार्सर का काम क्या है पास रि जनरेट

play04:39

करना तो पार्सर यहां आपका स्टार्टिंग

play04:41

सिंबल पे अभी है इस टाइम अब इसमें बहुत

play04:45

सारी प्रोडक्शन है कौन सी प्रोडक्शन चूज

play04:46

करेगा वो डिपेंड करेगा कि यहां से लेक्स

play04:48

एलाइजर कौन सा टोकन भेज रहा है लेट्स सपोज

play04:51

इसने यहां स्कैन करते हुए यहां पहुंचा और

play04:53

तीन सिंबल रीट कि और एक कोई टोकन जनरेट हो

play04:55

गया ओके तो लेट्स सपोज वो टोकन आपका क्या

play04:58

है आईडी है फॉर एग्जांपल

play05:00

ओके तो अब यहां पर एक लेट्स सपोज आपका एक

play05:03

कोई प्रोडक्शन है आईडी च इज इक्वल टू e

play05:06

फॉर एग्जांपल तो क्या करेगा ये आईडी च इज

play05:10

इक्वल टू e करके ये आपका एक्सपेंड कर देगा

play05:13

पास्ट ट्री एक बार और रिपीट कर दे रहे हैं

play05:15

इस चीज को पार्सर का काम क्या है पार्सर

play05:17

का मतलब सिंटेक्स एलेजर पार्सर का काम यह

play05:19

है कि वो पास जनरेट करेगा तो पास वो कैसे

play05:22

जनरेट कर उसको उसको क्या चाहिए टोकन इसका

play05:24

मतलब ये है कि इसके पास बहुत सारे रूल है

play05:27

कौन सा वो प्रोडक्शन रूल पिक करेगा वो

play05:29

करेगा लेक्स एनालाइजर कौन सा टोकन भेज रहा

play05:32

है तो पहले क्या होगा पार्सल लेक्सिक

play05:35

एनालाइजर को बोलेगा कि टोकन सेंड करो जैसे

play05:38

ही टोकन सेंड हुआ उसके करेस्पॉन्डिंग्ली

play05:49

यह वेरीफाई करेगा अच्छा यहां आईडी है पहला

play05:52

और यहां आईडी है मैच कर गया अब क्या करेगा

play05:55

नेक्स्ट टोकन भेजो क्योंकि जो इसने

play05:56

प्रोडक्शन चूज किया वो करेक्ट है या नहीं

play05:58

और जो क्योंकि ये क्या करना आईडी भी चेक

play06:00

करेगा इक्वल भी चेक करेगा और कैपिटल ई भी

play06:02

चेक करेगा कैपिटल ई नहीं मतलब ई अभी

play06:04

एक्सपेंड होगा अब लेट्स सपोज यहां से फ से

play06:07

स्टार्ट किया और 10 तक पहुंचा ओके और यहां

play06:10

पर इसको मिल गया प्लस फ अब नया

play06:13

इंटरेस्टिंग पॉइंट य आने वाला है ये क्या

play06:15

आपको मिल गया ने नेक्स्ट टोकन लेटस सपोज

play06:17

प्लस है अब यहां क्या आ रहा है देखो यहां

play06:19

क्या इक्वल टू क्या हो गया यहां पे मिसमैच

play06:22

तो मिसमैच होगा तो क्या होगा ये किसको

play06:26

इफॉर्म करेगा एरर हैंडलर को अगर डायग्राम

play06:29

याद होगा तो इस तरीके से मैंने हर एक

play06:30

उसमें जो है एरो दिखाई थी कि लेफ्ट हैंड

play06:32

साइड में एरर हैंडल था राइट में क्या था

play06:34

सिंबल टेबल या लेफ्ट राइट कोई सा भी हो तो

play06:36

उसमें क्या होगा वो एरर हैंडलर को रिपोर्ट

play06:38

करेगा कि यहां पे क्या हो रहा था कि मैं

play06:40

ये एक्सपेक्ट कर रहा था लेक्स एनालाइजर से

play06:43

कि मुझे कौन सा टोकन मिलना चाहिए

play06:44

असाइनमेंट ऑपरेट दैट मींस इक्वल टू लेकिन

play06:47

मिला क्या प्लस तो ये कौन सी एरर होगी

play06:49

सिंटेक्स एरर लेकिन यहां कोई भी एरर आए

play06:52

आपका जो कंपाइलेशन का प्रोसेस है वो स्टॉप

play06:54

नहीं होगा क्योंकि कंपाइलर की डेफिनेशन

play06:56

क्या होती है कंपाइलर पूरे प्रोग्राम को

play06:58

स्कैन करके जो हैरर शो करता है ओके तो

play07:00

यहां प्रोग्राम स्टॉप नहीं होगा अब वो

play07:03

नेक्स्ट उस पे जाएगा तो दैट मींस और उसके

play07:05

बाद हां एक इंपॉर्टेंट चीज जो बहुत ही

play07:07

इंपॉर्टेंट है वो लेट्स सपोज यहां कोई

play07:09

सिंटेक्स एरर आ गई ओके ये फिर पार्सर क्या

play07:12

करेगा एरर हैंडल को इफॉर्म करेगा कि यहां

play07:15

पे एक एरर आई है तो ये बताएगा अभी कि

play07:16

अच्छा कौन सी एरर है एरर ये है कि मैं

play07:19

यहां एक्सपेक्ट कर रहा था कि मुझे इक्वल

play07:20

टू ऑपरेटर मिले लेकिन यहां क्या मिला आपका

play07:23

प्लस तो एरर हैंडलर क्या करेगा उसको नोट

play07:25

डाउन कर लेगा और उसके बाद एरर हैंडलर

play07:27

किससे पूछेगा लेक्सिक एनालाइजर से कि राइट

play07:30

नाउ व्हाट इज योर करंट पोजीशन दैट मींस

play07:32

करंट पोजीशन का मतलब क्या हुआ ये क्या है

play07:34

ये रो है और ये क्या है आपका कॉलम है ओके

play07:37

तो ये रो नंबर वन में है और कॉलम नंबर

play07:39

लेट्स सपोज 10 में है फाइन लेट्स अजूम ये

play07:43

हम सिचुएशन ले रहे हैं तो क्यों जब हम

play07:45

प्रोग्राम को कंपाइल करते हैं प्रैक्टिकली

play07:47

अगर आपने कोई प्रोग्राम लिखा होगा उसको जब

play07:48

कंपाइल करते हैं तो क्या सारी एरर शो करता

play07:50

है एक साथ और साथ ही साथ ये भी बताता है

play07:52

कि अच्छा इस लाइन में है और इस कॉलम मतलब

play07:55

इस रो नंबर पे इस कॉलम में है तो लास्ट

play07:56

पॉइंट जो ये है फिफ्थ बाकी हम दोनों पे

play07:59

आते हैं अभी लेक्सिक एनालाइजर हेल्प्स इन

play08:01

गिविंग एरर मैसेज बाय प्रोवाइड रो नंबर

play08:04

एंड कॉलम नंबर ये बहुत ही इंपॉर्टेंट है

play08:08

ओके अगर कोई भी सिंटेक्स एरर आती है तो

play08:11

प्रोग्राम का जो कंपाइलेशन है वो कभी भी

play08:14

स्टॉप नहीं होगा बाकी आगे ही क्योंकि पूरा

play08:16

प्रोग्राम ये स्कैन करेगा जितने भी इसमें

play08:19

कैरेक्टर जो यूजर ने लिखे क यूजर को थोड़ी

play08:21

ना पता है कि यहां रूल क्या है हो सकता है

play08:23

वो रूल के अलावा भी कुछ लिख दे तो

play08:25

सिंटेक्स एरर आ जाएगी लेकिन ना तो यहां ये

play08:27

स्टॉप होगा पास्ट ी जनरेट करना ना लेक्स

play08:30

एलाइजर स्कैन करना रुकेगा अब नेक्स्ट ओके

play08:32

लेट्स सपोज यहां इसको पॉ इसको नोट डाउन

play08:34

कौन करेगा एरर हैंडलर और ये इंफॉर्मेशन रो

play08:37

नंबर कॉलम नंबर कौन भेजेगा एरर हैंडलर को

play08:39

लेक्सिक एनालाइजर सिंटेक्स एनालाइजर सिर्फ

play08:42

एरर भेजेगा कि सिंटेक्स एरर आई है लेक्सिक

play08:45

एनालाइजर क्या करेगा इसको बताएगा कि इस रो

play08:47

में इस कॉलम में ये एरर है तो एरर हडर

play08:49

उसको नोट डाउन कर लेगा और एक साथ सारे एरर

play08:51

देगा अब लेट्स सपोज ये स्कैनिंग स्टार्ट

play08:54

हुई और सेकंड रो में भी चला गया यहां भी

play08:56

ये टोकन आ गया ये टोकन आ गया उस हिसाब से

play08:58

क्या हो रहा है

play08:59

ये आपकी ट्री एक्सपेंड होते होते ऐसे चली

play09:01

आ रही है ओके ये ट्री एक्सपेंड हो रही है

play09:04

इसमें वो इतना इंपोर्टेंट नहीं समझना कैसे

play09:05

ये ट्री कंस्ट्रक्ट होगई ये पूरा अपना एक

play09:07

सेपरेट चैप्टर है वहा हम लोग डिस्कस

play09:09

करेंगे और करते करते करते हम लोग यहां

play09:11

पहुंचे लेट्स सपोज हम लाइन नंबर 10 और

play09:14

यहां पे इस समय लेट्स सपोज करंट पोजीशन

play09:17

हमारी ये कि लाइन नंबर 10 और कॉलम नंबर

play09:19

लेट्स सपोज 15 प हम पहुंचे अब यहां कोई

play09:22

एरर आ गई लेट्स सपोज वो सिचुएशन यहां है

play09:25

यहां ये एरर आ गई ओके ये सिंटेक्स अजूम कर

play09:28

रहे हैं तो क्या होगा फिर से यही सेम

play09:29

सिनेरियो स्टार्ट होगा अच्छा इस पर्टिकुलर

play09:32

लाइन मतलब यहां पे एक एरर मिली है जो कि

play09:34

सिंटेक्स एरर है जो भी वो एक्सपेक्ट कर

play09:36

रहा होगा सिंटेक्स एनालाइजर कि हमें ये

play09:37

मिलना चाहिए और टोकन कोई गलत आ गया तो

play09:39

इसका मतलब फिर से क्या करेगा एरर हैंडलर

play09:41

को ये रिपोर्ट करेगा कि यह एक सिंटेक्स

play09:43

एरर मिली है और उसके बाद एरर हैंडलर

play09:45

लेक्सिक एलाज से पूछे ग अच्छा इस टाइम

play09:47

करंट पोजीशन क्या है तो ये बताएगा मैं रो

play09:50

नंबर 10 और कॉलम नंबर 15 पे प्रेजेंट हो

play09:53

तो वो क्या करेगा उसको नोट डाउन कर लेगा

play09:55

ये हो गया ये हो गया सिंटेक्स एनालाइजर और

play09:57

लेक्स एनालाइजर की स्टोरी अब एक और आपका

play10:00

जो है क्या कहते हैं सिमटिक एनालाइजर भी

play10:04

सिमटिक एनालाइजर कब एक्टिव होता है वो

play10:06

एक्टिव होगा जैसे ही आपका ये

play10:07

आइडेंटिफिकेशन

play10:14

[संगीत]

play10:29

मतलब जैसे ही ये टोकन जनरेट हुआ और पास्ट

play10:31

री कंस्ट्रक्ट हुई साथ ही साथ सिमटिक

play10:33

एनालाइजर भी आ गया स्टोरी में ओके तो जैसे

play10:36

ही वो स्टोरी में आया तो अब ये चेक करेगा

play10:38

कहां से ये आईडी कहां स्टोर है सिंबल टेबल

play10:40

में लेट्स सपोज ये आपका सिंबल टेबल है ओके

play10:43

और यहां लेट्स सपोज इसका आईडी जोक टोकन

play10:46

जनरेट हो रहा था इसका इस तरीके से हम लोग

play10:48

डिस्कस किया आईडी कॉमा वन ऐसे हम लोग

play10:50

डिस्कस कि ये टोकन है कंपलीटली ये आपका

play10:52

आइडेंटिफिकेशन नेम और उसकी एट्रिल तो ये

play10:55

वन है और ये वेरिएबल नेम लेट्स सपोज x था

play10:58

और ये इसका

play10:59

जो टाइप था क्या वो फ्लोट था ये डिस्कस

play11:02

किए हम लोग प्रीवियस वीडियो में यह आएगा

play11:04

और वो चेक करेगा अच्छा ये मैच कर रहा है

play11:06

अब लेट्स सपोज यहां आते आते यहां पे आ गए

play11:08

ओके यहां पे कोई एक आइडेंटिफिकेशन

play11:29

य क्या आपका इंटी जर है तो जैसे ही इंटी

play11:33

जर लिखेगा यूजर तोय इंजर स्टोर भी करेगा

play11:34

सिकल लाइजर अब य जब इसकी चेकिंग होगी

play11:37

अच्छा यह तो इंटी जर है लेकिन य प्रॉब्लम

play11:39

क्या आगी आईडी च इ इ ट तो अगर आपका लेफ्ट

play11:42

हैंड साइड में यह अगर फ्लोट है तो राइट

play11:46

हैंड साइड में भी फ्लोट होना चाहिए लेकिन

play11:48

य चेक करेगा इंजर तोय क्या होगा टाइप मिस

play11:50

मैच लेकिन दो तरह का आपका टाइप कन्वर्जन

play11:53

होता है इंपलीसिट और एक्सप्लिसिट तो

play11:57

फ्लोट फ्लोट और इंट में अगर कंपेयर करेंगे

play12:00

तो इंट की साइज जो है फ्लोट से कम होती है

play12:03

तो इसको हम इंपलीसिटली क्या कर सकते हैं

play12:04

स्टोर कर सकते हैं लेट्स अजूम फ्लोट का जो

play12:06

है 4 बाइट का है और आपका ये इंटी जर ू

play12:10

बाइट का है ये अजमन है ओके तो अगर यहां पे

play12:12

इस तरीके से दिया हुआ है कि अच्छा ठीक है

play12:14

इंट कॉम फ्लोट में स्टोर करा लेंगे कोई भी

play12:16

डेटा लॉस नहीं होगा तो ये इंपलीसिट

play12:18

कन्वर्जन तो हो जाएगा लेकिन अगर ये उल्टा

play12:19

हो गया यहां पे आपका इंट है ओके और यहां

play12:22

क्या आपका फ्लोट है तो ये फर बाइट है और ू

play12:26

बाइट इसमें स्टोर करेंगे तो डेटा लॉस हो

play12:28

सकता है तो यहां क्या करेगा सिमटिक

play12:29

एनालाइजर ओके सट लेट्स सपोज वो हम इस टाइम

play12:33

100 लाइन में यहां पे 100 लाइन और लेट्स

play12:36

सपोज कॉलम नंबर लेट्स सपोज 11 है ये

play12:39

सिचुएशन है ये 100 था और ये 11 इस टाइम

play12:42

करंट पोजीशन ये है तो यहां हमको मिला

play12:44

फ्लोट और इसका लेफ्ट हैंड साइड में टाइप

play12:46

क्या है आपका इंटी जर तो सिमटिक एनालाइजर

play12:49

क्या करेगा एरर हैंडलर को इफॉर्म करेगा कि

play12:51

सिमटिक एरर एरर क्या है एरर हैंडलर पूछेगा

play12:54

कि एरर कौन सी है तो बताएगा कि ये टाइप

play12:56

मिस मैच हो गया ओके उसके बाद बाद एरर

play12:59

हैंडल किससे पूछेगा लेक्सिक लेजर कि कहां

play13:01

पे होगी मतलब व्हाट इज योर करंट पोजीशन तो

play13:03

पूछेगा तो ये बता देगा कि अच्छा 100 रो

play13:06

में है और 11थ कॉलम है तो ये आपको जो है

play13:09

एरर एरर हडर क्या करेगा उस चीज को नोट

play13:12

डाउन करेगा प्रोग्राम का जो कंपाइलेशन है

play13:15

यानी कंपाइलर कभी भी स्टॉप नहीं होगा वो

play13:16

पूरे प्रोग्राम को स्कैन करेगा वो सब कुछ

play13:18

स्कैन करके फाइनली लिस्ट ऑफ एरर जो है एरर

play13:21

हैंडलर दे देगा अच्छा इस लाइन में इस कॉलम

play13:23

में ये एरर है इस लाइन में इस कॉलम में ये

play13:25

एरर है तो ये थी पूरी स्टोरी किस तरीके से

play13:29

एनालाइजर पार्सर और सिमटिक एनालाइजर एक

play13:32

दूसरे से कम्युनिकेट करते हैं अब कुछ

play13:34

इंपॉर्टेंट जो तीसरा और चौथा उसको एक बार

play13:36

रीड कर लेते हैं फिर एग्जांपल डिस्कस करते

play13:37

हैं तो लेक्सिक एलाइजर क्या होता है

play13:40

स्कैनर क्या करता है वो प्रोग्राम को

play13:41

स्कैन करेगा मीनिंगफुल वर्ड में कन्वर्ट

play13:43

करेगा जिसको हम टोकन कहते हैं टोकन क्या

play13:45

होता है आइडेंटिफिकेशन

play13:58

करता है वो रिमूव करता है अभी हम इसपे

play14:00

एग्जांपल डिस्कस करते हैं तो और ज्यादा

play14:01

क्लेरिटी आएगी कैसे वो टोकन में कन्वर्ट

play14:03

होगा तो ये एलिमिनेट कर देगा लेक्सिक

play14:06

एनालाइजर एलिमिनेट्स वाइट स्पेस कैरेक्टर

play14:08

लाइक ब्लैंक एंड टैब अगर कहीं ब्लैंक है

play14:10

और कहीं अगर हमने टैब जो है बटन प्रेस

play14:13

किया हुआ है प्रोग्राम लिखते हो वो सारा

play14:15

स्पेस क्या करता है एलिमिनेट कर देता है

play14:17

तो ये था लेक्सिक लाइजर के बारे में बेसिक

play14:20

लेक्सिक लाइजर क्या होता है स्कैनर होता

play14:21

है मीनिंगफुल वर्ड्स में कन्वर्ट करता है

play14:23

जिसको टोकन कहते हैं कमेंट लाइन को रिमूव

play14:25

करता है और आपका वाइट स्पेस को रिमूव करता

play14:27

है और सबसे इंपोर्टेंट जो था वो फिफ्थ

play14:29

पॉइंट है फिफ्थ पॉइंट क्या है कि आपका ये

play14:32

एरर जो आपकी आती है जब कंपाइलेशन के बाद

play14:34

जो एरर आती है वो कौन बताता है किस लाइन

play14:36

और किस कॉलम में है वो आपका लैक्सिकल

play14:39

एनालाइजर बताता है तो ये था ठीक है

play14:41

बेसिक्स की क्या है लेक्सिक एनालाइजर उसकी

play14:43

डेफिनेशन उसकी वर्किंग अब हम लोग डिस्कस

play14:45

करेंगे इससे रिलेटेड प्रॉब्लम कि कैसे

play14:47

लक्सल एनालाइजर प्रोग्राम को स्कैन करके अ

play14:50

और उसको टोकन में कन्वर्ट करता है ओके

Rate This

5.0 / 5 (0 votes)

Related Tags
Compiler TheoryLexical AnalysisSyntax AnalysisCode CompilationProgramming ConceptsTokenizationSyntax ErrorSemantic AnalysisCompiler PhasesCompiler Design