Count number of tokens in compiler design | Lexical Analyzer

THE GATEHUB
9 Jan 202421:08

Summary

TLDRThe video script discusses the tokenization process of a lexical analyzer program, explaining how it converts a given program into tokens. It emphasizes the importance of using a deterministic finite automaton for tokenization and the concept of longest matching. The script explores various examples, including identifiers, keywords, special symbols, and operators, to illustrate how tokens are identified and categorized. It also touches on common errors such as token errors and the significance of comments in a program.

Takeaways

  • 📘 The video discusses how a lexical analyzer program converts given code into tokens, emphasizing the importance of tokens in identifying elements within the code.
  • 🔍 Two important points for tokenization are highlighted: the use of a deterministic finite automaton (DFA) and the process of doing tokenization by giving importance to the longest matching.
  • 👉 The lexical analyzer always gives importance to the longest matching token, which means it combines characters into the longest possible token that matches the token definitions.
  • 🌐 The script explains the concept of tokens, variables, keywords, and special symbols, and how they are identified and converted during the tokenization process.
  • 🔢 The process of counting tokens is discussed, noting that it is crucial to correctly identify the number of tokens present in a given code snippet.
  • 💡 The video clarifies that the lexical analyzer does not check for syntax or semantic errors; it only scans the program to convert it into tokens.
  • 🚫 The difference between lexical errors and syntax or semantic errors is explained, with lexical errors being those that prevent the creation of valid tokens.
  • 🔑 The role of comments in a code snippet is discussed, noting that the lexical analyzer will remove them, affecting the token count.
  • 🔄 The concept of 'longest matching' is repeatedly emphasized, as it is a key principle in tokenization to avoid errors and ensure accurate token identification.
  • 📖 The script serves as an educational resource, aiming to provide a comprehensive understanding of lexical analysis and tokenization in programming.
  • 🔍 The video concludes by covering various scenarios and examples to illustrate the tokenization process, including handling of strings, operators, and potential errors.

Q & A

  • What is the primary function of a lexical analyzer in a compiler?

    -The primary function of a lexical analyzer is to convert a given program into tokens, which are meaningful words or symbols in the program.

  • What are tokens in the context of lexical analysis?

    -Tokens are meaningful words or symbols identified by the lexical analyzer, such as keywords, identifiers, operators, and special symbols.

  • What are the two important points to understand about how a lexical analyzer converts a program into tokens?

    -The two important points are: 1) The lexical analyzer uses deterministic finite automata (DFA) to perform tokenization. 2) During tokenization, the lexical analyzer always gives importance to the longest matching sequence.

  • How does the lexical analyzer handle keywords and identifiers?

    -The lexical analyzer reads characters sequentially and tries to match the longest sequence of characters that form a valid token, such as a keyword or an identifier. It checks for the next character to determine if the sequence forms a complete token.

  • Why is the concept of 'longest matching' important in lexical analysis?

    -The concept of 'longest matching' is important because the lexical analyzer must ensure that it identifies the longest possible sequence of characters that form a valid token. This avoids prematurely identifying partial tokens and ensures accurate tokenization.

  • What happens if a program contains a syntax error during lexical analysis?

    -The lexical analyzer does not rectify syntax or semantic errors. Its job is to scan the program and convert it into tokens. Syntax errors are checked by the syntax analyzer, and semantic errors are checked by the semantic analyzer.

  • How does the lexical analyzer handle special symbols and operators?

    -Special symbols and operators are treated as individual tokens. The lexical analyzer identifies these symbols directly and does not require reading additional characters for confirmation.

  • What is the role of deterministic finite automata (DFA) in lexical analysis?

    -Deterministic finite automata (DFA) are used by the lexical analyzer to recognize patterns in the input program and convert them into tokens. DFA helps in identifying the longest matching sequence of characters for each token.

  • What is the difference between deterministic finite automata (DFA) and non-deterministic finite automata (NFA) in the context of lexical analysis?

    -DFA has a single path for each input character leading to a unique next state, making it efficient for lexical analysis. NFA can have multiple paths for a single input character, but it can be converted to DFA for practical use in lexical analyzers.

  • How does the lexical analyzer handle strings and comments in the input program?

    -Strings are treated as single tokens starting and ending with double quotes, and the content within the quotes is not further tokenized. Comments are removed by the lexical analyzer and are not converted into tokens.

Outlines

00:00

🔍 Introduction to Lexical Analysis

The script begins with an exploration of lexical analysis, explaining the process of converting a program into tokens using a lexical analyzer program. It emphasizes the importance of understanding two key points: the use of deterministic finite automata in lexical analysis and the concept of longest matching during tokenization. The paragraph discusses how to identify tokens such as identifiers, keywords, and special symbols, and how to handle situations where the next character read may or may not be necessary for determining the token.

05:01

📈 Detailed Explanation of Tokenization

This paragraph delves deeper into the tokenization process, highlighting the importance of longest matching to avoid errors in counting tokens. It discusses various examples, including the handling of binary addition and unary increment operators, and clarifies the concept of combining tokens to form the correct token sequence. The summary also touches on the significance of recognizing constant values and understanding the role of syntax and semantic errors in the context of lexical analysis.

10:02

🛠️ Handling of Syntax and Lexical Errors

The script continues with a discussion on syntax and lexical errors, explaining the difference between them and how they are treated during lexical analysis. It points out that lexical errors are not checked by the lexical analyzer, which only focuses on converting the input program into tokens. The paragraph provides examples to illustrate common mistakes, such as using variables before declaration and incorrect use of operators, and emphasizes the importance of proper variable declaration and usage order.

15:05

📝 Impact of Comment Lines on Tokenization

This section of the script addresses how comment lines are treated during lexical analysis. It explains that the lexical analyzer will remove comment lines, which may affect the count of tokens and the overall structure of the program. The paragraph illustrates how spaces and other elements are handled after the removal of comments, ensuring that the token count remains accurate and reflecting the impact on the program's syntax.

20:07

🔧 Final Thoughts on Lexical Analysis

The final paragraph wraps up the discussion on lexical analysis by summarizing the key points covered in the script. It reiterates the importance of using the longest matching strategy during tokenization and the role of the lexical analyzer in identifying meaningful words and converting them into tokens. The summary also touches on common errors that can occur, such as unclosed strings, and the need to be aware of these issues when writing programs.

Mindmap

Keywords

💡Lexical Analyzer

A lexical analyzer, also known as a lexer or tokenizer, is a software program that breaks down a text stream into a series of tokens, which are meaningful words or symbols in the context of programming languages. In the video, the lexical analyzer is central to the discussion, as it is responsible for converting the given program into tokens, highlighting its importance in the initial phase of source code processing.

💡Token

In the context of the video, a token represents a meaningful sequence of characters identified by the lexical analyzer. Tokens are the fundamental building blocks used in syntax analysis and parsing. The script discusses how different types of tokens such as keywords, variables, operators, and symbols are identified and extracted from the source code.

💡Deterministic Finite Automaton (DFA)

A Deterministic Finite Automaton is a theoretical model of computation that recognizes patterns in input data. In the video, DFA is used to describe the mechanism by which the lexical analyzer identifies tokens. The script mentions DFA in the context of tokenization, emphasizing its role in determining the longest matching pattern in the input stream.

💡Longest Matching

The concept of longest matching refers to the process of identifying the longest possible string of characters that can be recognized as a token. The video script explains that during tokenization, the lexical analyzer always prefers the longest match to avoid premature termination of token recognition, which is crucial for accurately parsing the input program.

💡Identifier

An identifier in programming is a name given to entities such as variables, functions, or labels. The script discusses how identifiers are recognized as tokens by the lexical analyzer, which is essential for distinguishing between different types of tokens and their respective meanings within the program.

💡Keyword

A keyword is a reserved word in a programming language that has a special meaning and purpose. In the video, keywords are mentioned as a type of token that the lexical analyzer must recognize. They are significant because they cannot be used as identifiers and have predefined roles in the language syntax.

💡Variable

A variable is a storage location paired with an associated symbolic name, which contains some known or unknown quantity of information referred to as a value. The script explains that variables are identified as tokens by the lexical analyzer, which is fundamental for the compiler to understand the program's data usage.

💡Operator

Operators are symbols or words that represent mathematical or logical operations in programming. The video script discusses how operators are categorized as tokens by the lexical analyzer, which is essential for understanding the operations to be performed on variables and values within the program.

💡Comment

Comments are parts of the source code that are not executed as code but are meant for human readers to understand the program's purpose or functionality. The script explains that the lexical analyzer removes comments from the source code, emphasizing the role of comments in making the code more readable and maintainable without affecting execution.

💡Syntax Error

A syntax error occurs when the structure of the code does not conform to the rules of the programming language. The video script mentions syntax errors in the context of the lexical analyzer's role in identifying tokens, noting that while the analyzer identifies tokens, it does not check for syntax correctness, which is a responsibility of subsequent stages in the compilation process.

💡Semantic Error

Semantic errors are mistakes in the logic or meaning of the code, which may not prevent the code from compiling but can lead to incorrect behavior at runtime. The script briefly touches on semantic errors, indicating that the lexical analyzer does not check for these types of errors, which are instead identified during the semantic analysis phase of compilation.

Highlights

Introduction to lexical analyzers and the concept of tokenization in programming.

Explanation of tokens as meaningful words in the context of programming.

The importance of deterministic finite automata in lexical analysis.

Discussion on how lexical analyzers use a deterministic finite automaton for tokenization.

The significance of longest matching in lexical analysis to avoid syntax errors.

How lexical analyzers give importance to the longest matching token.

The process of identifying tokens in a given program and the role of the initial state.

Explanation of how a lexical analyzer determines the first token in a program.

The role of variables in tokenization and their identification as tokens.

How to handle the reading of the next character in tokenization when necessary.

The concept of non-deterministic finite automata and their conversion in tokenization.

Practical examples of tokenization, including keywords, variables, and special symbols.

The process of eliminating comments in a program during lexical analysis.

How lexical analyzers ignore syntax and semantic errors, focusing solely on meaningful words.

The importance of counting tokens correctly to avoid mistakes in lexical analysis.

Examples illustrating the concept of longest matching in tokenization.

Discussion on the handling of syntax and semantic errors in programming.

Final thoughts on the role of lexical analyzers in generating tokens from a program.

Transcripts

play00:00

सो इस वीडियो में हम लोग डिस्कस करेंगे

play00:01

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

play00:04

को टोकन में कन्वर्ट करता है तो टोकन क्या

play00:06

होता है बेसिकली ठीक है इट्स अ मीनिंगफुल

play00:08

वर्ड जिसमें आपका

play00:11

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

play00:15

क्या-क्या होते हैं अब इस वीडियो में हम

play00:18

लोग डिस्कस करेंगे कि कोई भी आपका गिवन

play00:19

प्रोग्राम है उसको किस तरीके से टोकन में

play00:22

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

play00:24

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

play00:26

उसके लिए दो इंपोर्टेंट पॉइंट है जो कि

play00:28

जानना बहुत जरूरी है पहले लेक्सिक

play00:30

एनालाइजर यूस डिटरमिनिस्टिक फाइना इट

play00:32

ऑटोमेटर जो हम लोग टीसी में डिस्कस किए थे

play00:35

डीएफए एनएफ फाइना इट ऑटोमेटर वही डीएफ

play00:37

डीएफए टू डू टोकेनाइजेशन पहला पॉइंट दूसरा

play00:40

पॉइंट वाइल डूइंग टोकेनाइजेशन

play00:43

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

play00:45

लिखना लेक्सिक एनालाइजर ऑलवेज गिव्स

play00:49

इंपॉर्टेंस टू लांगेस्ट मैचिंग अब इस

play00:51

दोनों जो है पॉइंट का क्या मतलब है ये

play00:54

आपका गिवन प्रोग्राम है सी प्रोग्राम अब

play00:56

इसमें हमें फाइंड आउट करना है कि कितने

play00:57

नंबर ऑफ टोकन प्रेजेंट है तो सबसे पहला

play01:00

देखते हैं तो सबसे पहला टोकन क्या आएगा

play01:02

इंटी जर तो ये सबसे पहला टोकन हो जाएगा ये

play01:04

हो जाएगा टोकन नंबर वन लेकिन आएगा कैसे तो

play01:07

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

play01:09

सपोज हम ये हमारा ये स्टेट है इनिशियल

play01:11

स्टेट ओके उसके बाद क्या कर र है i को ये

play01:14

रीड करेगा और नेक्स्ट स्टेट पे चला जाएगा

play01:17

ओके तो जैसे ही हमको फाइनल स्टेट मिलेगा

play01:20

वहीं स्टॉप कर जाएंगे और क्या हो जाएगा वो

play01:22

आपका टोकन हो जाएगा तो आ क्या हम आ पे

play01:25

स्टॉप कर सकते हैं क्योंकि आ भी आपका एक

play01:26

वेरिएबल हो सकता है वेरिएबल क्या होता है

play01:28

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

play01:29

टोकन तो क्या हम यहीं स्टॉप कर जाएंगे

play01:31

नहीं जब भी कोई वेरिएबल आएगा यहां दो

play01:34

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

play01:36

कभी-कभी हमें नेक्स्ट सिंबल रीड करना

play01:38

पड़ेगा नेक्स्ट कैरेक्टर और कभी-कभी ऐसे

play01:41

जो है सिंबल्स आएंगे जिसके लिए नेक्स्ट

play01:43

मतलब ये नेक्स्ट आपका कैरेक्टर रीड करने

play01:46

की जरूरत नहीं है खैर वो कैसे आएगा देखते

play01:48

हैं तो आपका आई आया तो ऐसी पॉसिबिलिटी हो

play01:51

सकती है कि भाई ये आइडेंटिफिकेशन

play02:00

ए के बाद यहां आए उसके बाद आई ए मिला अब

play02:02

उसके बाद फिर क्या करेंगे नेक्स्ट

play02:03

कैरेक्टर चेक करेंगे मिला उसके बाद यहां आ

play02:06

ग अभी भी हम शर नहीं है कि हो सकता है कि

play02:09

इंट के बाद किसी ने इस तरीके से लिख दिया

play02:12

किसीने लिख दिया आई एन

play02:14

टी प इस तरीके से भी कुछ लिख सकता है तो

play02:17

क्या होगा ये ये इंजर य आपका कीवर्ड नहीं

play02:20

होगा ये पूरा मिला के क्या हो जाएगा एक

play02:21

आईडेंटिफायर होगा इसलिए हम यही स्टॉप नहीं

play02:23

करेंगे नेक्स्ट क्या होगा नेक्स्ट चेक

play02:25

करेंगे लेट सपोज इस तरीके से लिख नेक्स्ट

play02:28

आपका ब्लैंक ओके तो ब्लैंक इस तरीके से अब

play02:32

तब जाके हमें पता चलेगा ओ अब हम क्या

play02:34

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

play02:36

ब्लैंक क्रिएट किया ऐसे ही पता चल गया कि

play02:38

अच्छा ये तीनों मिला के क्या आ रहा है

play02:39

आपका एक कीवर्ड हो रहा है इंटी जर डेटा

play02:40

टाइप तो इसलिए हमें कभी-कभी नेक्स्ट सिंबल

play02:43

रीड करके तब फाइनल स्टेट प पहुंचेंगे और

play02:46

कभी-कभी ऐसा होगा कि हमें जो है नेक्स्ट

play02:48

सिंबल रीड करने की जरूरत नहीं पड़ेगी अभी

play02:49

उसपे आते हैं देखते हैं तो इसका मतलब इंट

play02:51

आपका क्या हो गया एक कीवर्ड हो गया ये

play02:53

पहला कीवर्ड हो गया नेक्स्ट इसी तरीके से

play02:55

क्या है मेन देख लेते हैं एक और देख लेते

play02:57

हैं अब सपोज दैट हमें यहां मिला ए

play03:01

ए ये भी हो सकता है कि भाई आपका येय

play03:03

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

play03:19

ब्रैकेट आया इसका मतलब ये पता चल गया कि

play03:22

भाई ओपन ब्रैकेट का मतलब इससे पहले क्या

play03:24

था आपका फंक्शन और ये क्या आपका मेन

play03:26

फंक्शन तो दूसरा जो

play03:28

है

play03:30

क्या कहते हैं टोकेंस दूसरा टोकन क्या हो

play03:32

जाएगा आपका मेन हो जाएगा तो यहां देखो मेन

play03:35

रीड करके यहां तक पहुंचे अब नेक्स्ट सिंबल

play03:38

जो है रीड करना जरूरी है क्यों क्योंकि हम

play03:48

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

play03:51

का नाम इस तरीके से लिख सकता है ऐसा सिर्फ

play03:54

यहीं तक जाके हम नहीं कह सकते कि अच्छा

play03:55

मेन जो है आपका फंक्शन नहीं हमें नेक्स्ट

play03:58

सिंबल भी रीड करना पड़ेगा अब देखो तो

play04:01

इसलिए हम फाइनल पर पहुंच जाएंगे और यह

play04:02

डायग्राम हम पूरा नहीं बना रहे क्योंकि य

play04:04

स्पेस है नहीं सारे बस यह समझ लो इस तरीके

play04:07

से ये क्या है आपका एक टम डिटरमिनिस्टिक

play04:10

फाइना इट ऑटोमेटा नहीं लेकिन अगर कोई आपका

play04:12

नॉन डिटरमिनिस्टिक फाइट ऑटोमेटा भी बन रहा

play04:14

है तो उसको हम डीएफ में कन्वर्ट कर सकते

play04:15

हैं तो इसलिए कहीं कहीं आपको फाइना इट

play04:18

ऑटोमेटा भी लिखा होगा तो उसमें कंफ्यूज

play04:19

नहीं होना है लेक्सिक एलाइजर यूस डीएफ टू

play04:22

डू टोकेनाइजेशन तो इस तरीके से वो

play04:24

टोकेनाइजेशन करेगा अब नेक्स्ट नेक्स्ट

play04:27

क्या है ओपन ब्रैकेट अब इसके लिए हमें

play04:28

नेक्स्ट है कोई भी नेक्स सिंबल उसको रीड

play04:31

करने की जरूरत नहीं वो सेल्फ सफिट है

play04:33

अच्छा य एक स्पेशल सिंबल है इसका मतलब वो

play04:35

क्या टोकन है यह भी क्या आपका टोकन है तो

play04:38

इस लाइन में टोटल नंबर ऑ टोकन टूथ

play04:41

4 फोर टोकन हो गया यह भी आपका टोकन है

play04:46

इसका मतलब यहां इस लाइन में फ हो गया यह

play04:48

आपका टोकन 6 से 8 ओके तो यहां तक गए हम

play04:53

लोग कितना मिला 8 मिल गया देखो ये आपका एक

play04:55

कीवर्ड है टोकन ये आपका एक वेरिएबल है

play04:57

टोकन स्पेशल सिंबल टोकन यहां तक 8 हो गया

play05:01

अब ये क्या है अब डायरेक्टली हम लिख रहे

play05:02

हैं 4 9 10 11 12 13 14 15 16 17 18 ओके य

play05:12

18 उसके बाद 19 अब यहां ये समझना बहुत

play05:16

जरूरी यहां तक 19 आया लो यहां लिख लेते

play05:17

हैं यहां तक 19 आया अब यहां प्लस प्लस है

play05:20

ओके तो अब

play05:22

देखो यहां आए सपोज ट ये आपका एक प्लस है

play05:26

तो हो सकता है कि आपका बाइनरी जो है एडिशन

play05:29

हो

play05:30

लेकिन ऐसा भी हो सकता है कि आपका यह प्लस

play05:33

प्लस में तब जाके हम फाइनल में पहुंचेंगे

play05:34

क्योंकि ये हो सकता है कि आपका यूनिरी

play05:36

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

play05:39

वाइल डूइंग टोकेनाइजेशन लेक्सिक एलाइजर

play05:41

ऑलवेज गिव इंपोर्टेंस टू द लांगेस्ट

play05:44

मैचिंग लांगेस्ट का मैचिंग लांगेस्ट अगर

play05:46

यह आपका एक टोकन है और यह भी टोकन और

play05:49

दोनों कंबाइन होके अगर आपका टोकन मिला है

play05:51

तो उसको हम क्या करेंगे कंबाइन करके

play05:52

लिखेंगे इसलिए लांगेस्ट मैचिंग लिखा हुआ

play05:55

है तो ये जो टोकन है ये एक होगा तो यहां

play05:59

19 यहां तक हुआ था फिर 20 21 ओके ये आपका

play06:03

21 यहां तक हुआ फिर 22 इस लाइन में 22 हो

play06:08

गया फिर ये आप गया 23 24 25 ये 26 27 यहां

play06:14

तक 27 मिला अब यहां देखो देखो लांगेस्ट

play06:17

मैचिंग इ इससे समझते हैं

play06:19

102 वन अपने आप में एक कांस्टेंट है तो

play06:23

क्या होगा टोकन रो अपने आप में एक

play06:25

कांस्टेंट है ओके ये भी एक टोकन होगा टू

play06:28

भी अपने आप में एक कांस्टेंट है तो ये

play06:30

अलग-अलग क्या आ रहा है आपका टोकन आ रहा है

play06:32

लेकिन यहां क्या है आपका एक साथ लिखा हुआ

play06:33

है तो पूरा हम क्या करेंगे एक साथ लिखेंगे

play06:35

लांगेस्ट मैचिंग का मतलब ये कि तब तक हम

play06:37

उसको इंक्लूड करते जाएंगे एक ही टोकन में

play06:40

जब तक

play06:40

कि मतलब ये कि वो अलग ना हो तो इसका मतलब

play06:43

102 अपने आप में एक टोकन है तो यहां तक 27

play06:46

हो गया था ओके काउंटिंग देख लेना ओके

play06:48

काउंटिंग में हो सकता है मिस्टेक हो जाए

play06:49

बट कांसेप्ट हमें समझना है 27 उसके बाद

play06:52

यहां है 28 ओके पूरा प्रिंट अफ क्या है ये

play06:55

भी आपका एक फंक्शन 28 29 ओके ओ है 29 यहां

play07:00

तक पहुंचा अब यहां ये समझना है जैसे ही

play07:02

आपका अ जो भी आपका मतलब ये प्रिंट अफ के

play07:05

अंदर जो डबल कोट्स में लिखा होगा वो यहां

play07:08

से स्टार्ट करेंगे और डबल कोट्स के खत्म

play07:12

होने तक ये पूरा एक टोकन होगा इसमें हमें

play07:14

कंफ्यूज नहीं होना इसके अंदर हमें चेक

play07:16

करने की जरूरत नहीं क्या लिखा हुआ है डबल

play07:18

कोट्स पूरा एक क्या होगा टोकन होगा तो 27

play07:21

यहां तक हो था 28 29 30 31 32 33 34 ओके

play07:29

35 ये मिला के 36 ये 37 यहां तक 37 आया 38

play07:35

रिटर्न 39 40 41 यहां तक 41 मिला और ये

play07:40

क्या हो गया आपका 42 तो फाइनल आंसर जो आ

play07:42

रहा है वो क्या आ रहा है आपका 42 तो इसमें

play07:45

सिर्फ दो ही इंपॉर्टेंट पॉइंट है समझने के

play07:47

लिए कि आपका लेक्सिक एनालाइजर डीएफ यूज

play07:50

करता है इस तरीके से डायग्राम वो

play07:51

इंपोर्टेंट नहीं है उतना बस हमें क्या

play07:53

करना है क्वेश्चन किस तरीके से आएंगे कि

play07:54

आपको एक प्रोग्राम दिया रहेगा नंबर ऑफ

play07:56

टोकन वहां क्या करना है ये टर्म बहुत ही

play07:58

इंपॉर्टेंट ओके लांगेस्ट मैचिंग जैसे हमने

play08:01

लांगेस्ट मैचिंग के लिए कौन सा एग्जांपल

play08:03

दिया प्लस प्लस का और 102 का क वन भी अपने

play08:07

आप में क्या है कांस्टेंट मी टोकन जीरो भी

play08:11

लेकिन कंबाइन अगर आपका प्लस टोकन है और यह

play08:14

प्लस टोकन लेकिन दोनों कंबाइन होके प्लस

play08:17

भी तो टोकन है बाइनरी एडिशन लेकिन अगर ये

play08:19

आपका प्लस आ रहा तो दोनों मिला के अगर

play08:21

टोकन है दोनों मिला के लिखेंगे ऐसा नहीं

play08:23

है कि इसको अलग और इसको अलग लिखेंगे नहीं

play08:25

ऐसा नहीं लिखना तो इस पर्टिकुलर क्वेश्चन

play08:26

के लिए नंबर ऑफ टोकन क्या आएंगे 42

play08:29

काउंटिंग में हो सकता है कोई मिस्टेक हो

play08:30

गई हो तो प्लीज उसको आप जो है काउंट करके

play08:32

देख लेना लेकिन कांसेप्ट तो आई थिंक समझ

play08:34

में आ गया होगा किस तरीके से टोकन काउंट

play08:36

करना है तो टोटल क्या हो जाएगा 42 सो एक

play08:38

प्रॉब्लम और डिस्कस करते हैं ये प्रॉब्लम

play08:40

बहुत ही इंटरेस्टिंग है समझने के लिए कि

play08:42

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

play08:45

जनरेट करता है प्रोग्राम को अब देखो यहां

play08:47

हैब हम डीएफए बनाने नहीं जा रहे हैं बस

play08:49

खाली हमें देखना है अच्छा ये मेन आपका एक

play08:51

जो है टोकन हो गया अब इसके बाद क्या आ रहा

play08:54

है आपका क्लोज ब्रैकेट पहले ही आ गया ओके

play08:57

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

play08:59

काम सिर्फ इतना ही होता है कि कोई भी आपका

play09:01

गिवन प्रोग्राम है उसको टोकन में कन्वर्ट

play09:03

कर दो वो सिंटेक्स और सिमटिक एरर को

play09:06

रेक्टिफाई नहीं करता वो सिंटेक्स एरर जो

play09:09

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

play09:10

सिमटिक से रिलेटेड चीजें होंगी वो सिमटिक

play09:13

एनालाइजर देखेगा लेक्सिक एनालाइजर सिर्फ

play09:14

क्या करेगा प्रोग्राम को स्कैन करेगा अगर

play09:17

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

play09:19

में कन्वर्ट कर देगा ओके तो ये मीनिंगफुल

play09:21

वर्ड है यस क्या है ये आप क्लोज ब्रैकेट थ

play09:24

तो यहां तक हमको क्या मिल गया तीन टोकन इस

play09:26

लाइन में मिल गए ये चौथा टोकन हो गया तो

play09:28

टोटल फोर गया अब देखो देख लेते हैं पहले 4

play09:32

5 6 7 8 9 10 11 12 यहां तक हमको 12 मिल

play09:38

गया 13 14 कॉमा क्या हो जाएगा 15 16 17 18

play09:45

19 20 21 यहां तक 21 मिल गया 22 23 24 25

play09:51

26 27 यहां तक 27 मिल गया और ये क्या आपका

play09:54

28 तो टोटल कितना मिला है

play09:57

28 लेकिन क्या इस अगर देखें प्रोग्राम में

play10:00

तो प्रोग्राम में एक तो पहली बात य कि

play10:02

सिंटेक्स एरर है य देखो यह तो वैलिड है

play10:04

नहीं य हमने फलोर बकेट पहले क्लोज लिखा य

play10:06

ओपन लिखा हुआ है जबक ऐसा होता नहीं है जो

play10:08

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

play10:10

आना चाहिए य बाद में आना चाहिए लेकिन लेसल

play10:13

ये लेक्सिक एरर नहीं लेक्सिक एरर क्या

play10:14

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

play10:16

नेक्स्ट एग्जांपल में अब दूसरी प्रॉब्लम

play10:19

क्या है इसमें सिंटेक्स एरर है नो डाउट

play10:21

ओके तो इसमें सिंटेक्स एरर है ओके

play10:24

सिंटेक्स एरर क्या इसमें सिमटिक एरर भी है

play10:27

मतलब सेम वही है सिटेक्स एरर सिमटिक एरर

play10:30

सिमटिक एरर का मतलब क्या होता है देखो

play10:32

यहां हमने x = a + ब स् स पहले लिखा हुआ

play10:35

है दैट मीन यहां हम एक्सप्रेशन सारे

play10:37

वेरिएबल हम पहले यूज करें डिक्लेयर बाद

play10:40

में करते हैं मतलब नहीं बाद में कर रहे

play10:42

हैं तो होता क्या है कि अगर आपको

play10:45

प्रोग्राम लिखना है तो सबसे पहले वेरिएबल

play10:47

को डिक्लेयर करते हैं उसके बाद जो है उसको

play10:49

यूज करते हैं यहां क्या हो गया उल्टा हो

play10:51

गया और दूसरी चीज y तो हमने यहां डिक्लेयर

play10:53

भी नहीं किया फिर भी हम वहां y यूज करें

play10:56

ये क्या अनडिक्लेयर्ड वेरिएबल तो इसमें

play10:58

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

play11:00

कोई भी लेक्सिक एरर नहीं आएगी तो जब भी

play11:02

कोई भी एग्जांपल आए तो उसमें हमें इमोशनल

play11:04

नहीं होना कि अरे इसका सिंटेक्स तो गलत हो

play11:06

गया तो इसलिए हम इसका नंबर ऑफ टोकन नहीं

play11:09

क्रिएट कर सकते नंबर ऑफ टोकेंस लेक्सिक

play11:11

एनालाइजर टोकन जनरेट करेगा बस खाली हमें

play11:14

ना सिंटेक्स देखना है ना सिमटिक देखना है

play11:15

सिर्फ ये देखना है कहीं कोई उसमें लेक्सिक

play11:17

एरर है कि नहीं अगर लेक्सिक एरर होगा तब

play11:20

तो वो टोकन में जनरेट नहीं कर पाएगा

play11:21

लेक्सिक एरर क्या होती है देखते हैं

play11:23

सिंटेक्स और सिमटिक लेक्सिक एनालाइजर चेक

play11:25

नहीं करता है ओके सो अब एक एग्जांपल और

play11:28

डिस्कस कर ओके यही आपका सेम मेन है

play11:32

टूथ इस लाइन में कितने थ्री इसको मिला

play11:35

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

play11:39

अब देखो यहां डबल इक्वल है यहां एक इक्वल

play11:42

है ये भी आपका क्या है टोकन क्योंकि क्या

play11:45

है असाइनमेंट सॉरी असाइनमेंट ऑपरेटर और

play11:48

दूसरा भी क्या है आपका असाइनमेंट ऑपरेटर

play11:49

लेकिन अगर इन दोनों को कंबाइन करेंगे तो

play11:52

क्या आ जाता कंपैरिजन ऑपरेटर हां ठीक है

play11:54

यहां हम कंपैरिजन नहीं कर सकते उसके लिए

play11:56

हमें क्या करना होगा ए या मब कोई ना कोई

play11:58

कंडीशनल स्टेटमेंट लगाना होगा यहां हम

play12:00

क्या कर ें असाइन कर रहे वैल्यू लेकिन ये

play12:02

क्या है ऑपरेटर असाइनमेंट ऑपरेटर नहीं

play12:04

इक्वल टू ऑपरेटर जो कि कंपैरिजन के लिए

play12:06

यूज कर ले सिंटेक्स एरर नहीं चेक करता

play12:08

लेक्सिक लेजर अभी जो हम लोगों ने डिस्कस

play12:10

किया प्रीवियस एग्जांपल में सिंटेक्स और

play12:12

सिमटिक एरर के बारे में हमें नहीं सोचना

play12:14

है बस ये देखना है क्या आपको मतलब लेक्सिक

play12:17

लाइजर को ये मीनिंगफुल वर्ड दैट मींस टोकन

play12:20

मिल रहा है अगर टोकन मिल रहा है तो वो

play12:22

हैवली कन्वर्ट कर देगा ये दोनों कंबाइन

play12:24

होके आ रहे हैं ओके क्योंकि ये देखो ये जो

play12:27

हमने डिस्कस किया लांगेस्ट मै बार-बार

play12:29

इसीज पे एमफसा क्यों कर रहे हैं क्योंकि

play12:31

हो सकता है इसी में गलती हो कि अच्छा ये

play12:34

भी इक्वल है ये भी इक्वल है तो दो अलग-अलग

play12:35

ऑपरेटर हो नहीं दोनों को कंबाइन करके अगर

play12:37

एक ऑपरेटर बना है तो उसको भी उसी को हम

play12:40

टोकन कहेंगे अलग-अलग नहीं लिखना है फाइन

play12:42

ये हो गया उसके बाद यहां हो गया ये टोकन

play12:45

है ये टोकन है अब देखो यहां लेस देन है ये

play12:48

भी एक आपका ऑपरेटर है और इक्वल भी एक

play12:51

ऑपरेटर लेकिन अगर इन दोनों को अप्लाई करें

play12:53

तो क्या होता है लेस दन और इक्वल टू ये

play12:55

सिंगल ऑपरेटर होगा तो ये दोनों मिला के

play12:57

क्या होगा एक टोकन यहां भी एक टोकन यहां

play12:59

भी तो क्या हो जाएगा फोर वहां तक था 5 6 7

play13:03

8 9 10 11 12 13 यहां तक क्या आया

play13:07

13 उसके बाद 14 15 ओके और इसके अंदर जो भी

play13:13

होगा एक सिंगल लेंगे तो 15 के बाद ये 16

play13:16

17 18 19 20 यहां तक 20 आ रहा और लास्ट

play13:19

वाला गया आपका 21 अब यहां एक चीज यहां भी

play13:21

आएगी देखो सिंटेक्स क्या यहां परसेंटाइल

play13:24

डी थ्री बार जो है तीन बार लिखे हुए हैं

play13:26

लेकिन यहां वेरिएबल सिर्फ एक ही बार लिखे

play13:28

हुए हैं ये क्या आपका सिंटेक्स एरर है

play13:30

सिंटेक्स एरर नहीं चेक करना बार-बार इस

play13:32

चीज को इसलिए रिपीट कर रहे हैं क्योंकि

play13:34

मोस्टली गलती ही होती है अच्छा यहां

play13:35

सिंटेक्स एरर नहीं करना हमें टोकन में

play13:37

कन्वर्ट ही नहीं करना नहीं ऐसा नहीं करना

play13:39

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

play13:42

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

play13:43

कर देता है तो इस प्रोग्राम के लिए टोटल

play13:45

नंबर ऑफ टोकन कितने आएंगे 21 ओके तो इस

play13:48

प्रॉब्लम को सॉल्व करते हैं ये बहुत ही

play13:49

इंटरेस्टिंग प्रॉब्लम है ओके तो सेम यही

play13:52

टूथ एंड 4 यहां तक तो सब कॉमन है फोर ये

play13:55

हो गया ठीक है वन अब यहां देखो ये समझना

play13:59

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

play14:02

यहां इसको पॉइंटर नहीं समझना यहां सिर्फ

play14:03

लेक्सिक एनालिसिस हो रही है दैट मींस जो

play14:06

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

play14:08

कन्वर्ट कर दे रहा है तो स्टार स्टार का

play14:10

मतलब सिंपली मल्टीप्लिकेशन या ये पॉइंटर

play14:13

या डी रिफरेंस ऑपरेटर या रिफरेंस सॉफ्टवेर

play14:15

कुछ नहीं समझेगा नॉट रिफरेंस डी रिफरेंस

play14:17

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

play14:19

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

play14:21

मल्टीप्लिकेशन समझेगा और यहां क्या है

play14:23

आपका कैरेक्टर तो अपने आप में ये क्या हो

play14:25

जाएगा आपका एक टोकन और ये दूसरा टोकन हो

play14:27

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

play14:30

स्ट्रिंग का मतलब ये पूरा एक टोकन है और

play14:32

ये एक टोकन तो कितना हो जाएगा ट 3 4 5 6 6

play14:35

प् 4

play14:36

10 ओके इवन अगर कहीं इस तरीके से लिखा हुआ

play14:39

स्टार स्टार सी ओके तो यह भी एक टोकन होगा

play14:42

यह भी एक टोकन होगा यह भी एक टोकन होगा ये

play14:44

भी इस तरह के भी प्रॉब्लम बहुत सारे

play14:46

प्रॉब्लम हम इसलिए डिस्कस कर रहे हैं ताकि

play14:48

कहीं भी किसी भी तरीके का कोई क्वेश्चन हो

play14:50

तो हर एक कांसेप्ट उसमें हर तरह की

play14:52

वैराइटी अगर इंक्लूडेड रहेगी तो कोई भी जो

play14:55

है दिक्कत नहीं आएगी सारी चीज सॉल्व हो

play14:57

जाएंगे नेक्स्ट

play14:59

टूथ फर 5 तो कितना हो गया 15

play15:05

टू 3 4 5 20 ट 3 4 5

play15:12

25 अब देखो ये समझने इस क्वेश्चन में

play15:15

सिर्फ यही इंपोर्टेंट था समझना बाकी तो

play15:17

ऑलरेडी पता है किस तरीके से कर अब देखो य

play15:19

आई ए है और इसके बाद क्या ब्लैंक उसके बाद

play15:21

टी है तो क्या इसको हम एक कीवर्ड समझ

play15:24

मानेंगे नहीं ये कीवर्ड नहीं है लेजर क्या

play15:28

करेगा इसको अलग कर देगा इसको अलग कर देगा

play15:30

इसको अलग कर देगा ये आपका इंट स्पेस है

play15:34

बीच में आई ए के बाद तो इसका मतलब ये ये

play15:37

इसको अलग आइडेंटिफिकेशन

play15:41

में कन्वर्ट कर देगा ये हो जाएगा ये हो

play15:45

जाएगा ये तो कितना हो जाएगा 1 2 3 4 5 6

play15:47

तो 25 प् 6

play15:49

31 ओके अब आते हैं नेक्स्ट लाइन नेक्स्ट

play15:52

लाइन में क्या आ आपकी कॉमेंट लाइन तो

play15:54

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

play15:56

में हमने डिस्कस किया था लेक्सिक लाइजर की

play15:58

डेफिनेशन के टाइम कि लेक्सिक एनालाइजर

play15:59

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

play16:01

है तो अगर उसमें कोई भी कमेंट लाइन उसको

play16:03

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

play16:05

रिमूव हुई रिमूव होने के बाद यहां एक

play16:08

स्पेस बचेगा तो आ और t में भी स्पेस रहेगा

play16:10

तो ये वाली लाइन ये वाली लाइन दोनों सेम

play16:12

ही है इन दोनों में कोई डिफरेंस नहीं है

play16:15

यहां कितना आया था 1 2 3 4 5 6 तो यहां भी

play16:19

सिक्स आ रहा है 31 + 6 च इज इ 37 काउंटिंग

play16:23

आप देख लेना ओके नेक्स्ट अब यहां क्या है

play16:25

स और इसके बीच में स्पेस है और देन एर है

play16:28

ये कैप

play16:29

कीवर्ड नहीं है ये सीच और ए आर अलग अलग

play16:31

चीज है इसका मतलब ये आपका एक टोकन हो गया

play16:34

दूसरा ये हो गया तीसरा ये हो गया चौथा ये

play16:36

हो गया पांचवा ये हो गया छ ये हो गया ट 3

play16:39

4 5 6 तो 37 प् 6 य लिख 37 प् 6 ये क्या

play16:46

हो जाएगा

play16:47

43 तो यहां तक 43 अब देखो वही सेम चीज

play16:50

यहां भी क्या है आपका कमेंट लेंथ वो रिमूव

play16:52

हो गया तो सी स्पेस ए इन दोनों में कोई भी

play16:55

डिफरेंस नहीं आएगा वही सेम टू सेम आएगा तो

play16:57

कितना आ रहा है 1 2 3 4 5 6 तो यहां भी

play17:01

सिक्स मिला तो

play17:03

43 + 6 49 यहां तक मिलेगा और यह क्या हो

play17:08

गया

play17:09

50 तो वैरायटी ऑफ प्रॉब्लम का मतलब यही

play17:12

होता है कि हर तरह के एस्पेक्ट को कवर कर

play17:14

लिया जाए तो यहां बहुत ही इंपॉर्टेंट ये

play17:16

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

play17:18

एग्जांपल में यही हमें बताना था कि कमेंट

play17:20

लाइन जैसे ही रिमूव करेंगे तो इसमें देखो

play17:22

ये दोनों लाइन भी क्या है सेम टू सेम है

play17:25

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

play17:27

ये लास्ट एग्जांप है इसमें मैंने जो है

play17:29

टोकन एरर दैट मींस लेक्सिक एरर को भी

play17:31

इंक्लूड किया हु ये पांच लाइन है और इसमें

play17:33

पूछा जा रहा है क्वेश्चन में कि हर एक

play17:35

लाइन में कितने टोकेंस होंगे तो देखो टोकन

play17:38

नंबर वन टोकन नंबर टू 3 4 5 ये आपकी कमेंट

play17:41

लाइन है लेक्शन एनालाइजर इसको रिमूव रिमूव

play17:44

कर देगा कैसे हम

play17:47

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

play17:51

लाइन की स्टार्टिंग होती है और इसके बीच

play17:52

में कुछ भी है वो कुछ भी कंसीडर नहीं करे

play17:54

जैसे ही म मल्टीप्लिकेशन और डिवाइड मिला

play17:57

कमेंट लाइन वहां फिनिश हो जाएगा तो दैट

play17:59

मीस ये पूरा पार्ट रिमूव कर देगा टोटल

play18:01

कितना है टूथ 4 5 इसमें मिला फ अब यहां

play18:05

आते हैं x सॉरी टोकन होगा उसके बाद हमें

play18:09

क्या मिला ट्रिपल इक्वल टू तो क्या ये कोई

play18:12

ऑपरेटर होता है नहीं सिंगल होता है

play18:14

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

play18:15

इंक्लूड कर दिया तो क्या हो गया आपका

play18:18

कंपैरिजन ऑपरेटर तो ये एक टोकन हो जाएगा

play18:20

अब हमारे पास सिर्फ बचा ये ये दोनों मिला

play18:22

के दो टोकन हो जाएंगे ये एक टोकन होगा ये

play18:24

एक टोकन होगा फाइन उसके बाद ये हो जाएगा

play18:27

टोकन

play18:29

अब देखो यहां से कमेंट लाइन स्टार्ट हुई

play18:31

चलते चले जाएंगे चलते चले जाएंगे चलते चले

play18:33

जाएंगे यहां क्या हो रहा है ये आपकी कमेंट

play18:35

लाइन फिनिश हो गई तो ये सीधे क्या करेगा

play18:38

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

play18:40

मल्टीप्लिकेशन है यहां कोई भी डिवीजन

play18:43

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

play18:44

होगी कमेंट लाइन नहीं होगी यह भी एक आपका

play18:47

क्या होगा टोकन होगा उसके बाद ए बी सीडी

play18:50

पूरा एक टोकन होगा ओके ये पूरा अलग अलग

play18:54

उसको कैरेक्टर देखो य इसलिए अभी इसको

play18:56

मिटाए नहीं है लांगेस्ट मैचिंग लांगेस्ट

play18:58

मैचिंग का मतलब a के बाद अच्छा b आ गया b

play19:00

के बाद यह पूरा मिला के एक वेरिएबल की तरह

play19:02

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

play19:05

ये डिवीजन और ये गया आपका सेमीकलन तो ये

play19:09

हो जाएगा 1 2 3 4 एलिमिनेट कर दिया 5 6 7

play19:14

8 9 टोटल कितना आ रहा है नाइन इसमें आ रहा

play19:16

है अब आते है इन स्टार स्टार प ओके तो ये

play19:20

आपका हो जाएगा दूसरा यह होगा तीसरा ये

play19:23

होगा चौथा ये होगा पांचवा ये होगा तो

play19:25

इसमें टोटल कितने आ रहे पांच यहां इसमें

play19:27

कंफ्यूजन हो सकते अच्छा स्ट क्या

play19:28

मल्टीप्लिकेशन दूसरा स्टार क्या है

play19:30

मल्टीप्लिकेशन तो दोनों अपना अपने आप में

play19:32

क्या है आपके टोकन इन दोनों को कंबाइन

play19:34

करेंगे क्या कोई टोकन मिल रहा है क्या कोई

play19:36

ऐसा ऑपरेटर होता है ससी प्रोग्रामिंग

play19:38

जिसको कहते हैं डबल डबल स्टार नहीं कोई

play19:40

ऑपरेटर नहीं होता इसलिए हम इन दोनों को

play19:42

अलग-अलग जो है टोकन कंसीडर करेंगे नेक्स्ट

play19:47

ये आपका एक हो जाएगा दूसरा तीसरा चौथा ये

play19:50

क्या हो जाएगा ये पांचवा हो जाएगा ये छठा

play19:53

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

play19:56

रहा है आपका न आ रहा है ओके देखो प्लस

play19:59

यहां मल्टीप्लिकेशन के केस में दोनों मिला

play20:02

के कोई एक ऑपरेटर नहीं बन रहा लेकिन यहां

play20:04

प्लस क्या है आपका बाइनरी अगर इन दोनों को

play20:06

मिला दिया तो यरी अपने आप में ये भी टोकन

play20:08

इसलिए लांगेस्ट मैचिंग तो ना आ गया अब

play20:11

देखो एक दो तीन अब ये क्या है आपका डबल

play20:15

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

play20:17

लेकिन यहां स्ट्रिंग देखो कहीं एंड नहीं

play20:18

हो रही है तो यहां क्या हो जाएगा आपका एरर

play20:21

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

play20:25

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

play20:28

किया स्ट्रिंग को लिखने के लिए डबल कोट्स

play20:30

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

play20:32

क्या आ जाएगा आपका टोकन तो एक एग्जांपल

play20:34

मैंने ले लिया ताकि आपको पता रहे टोकन एरर

play20:37

बेसिकली क्या हो है लेकिन मोस्टली अगर

play20:38

प्रोग्राम लिखेंगे उसमें सिंटेक्स या

play20:40

सिमटिक एरर ही आती है ओके तो आई होप मैंने

play20:45

ऑलमोस्ट जितनी भी पॉसिबल जो है प्रॉब्लम

play20:48

हो सकती तो सब कुछ कवर किया हुआ है तो ये

play20:50

था आपका लेक्सिक लेजर के बारे में ये

play20:53

पॉइंट है आपका कि डीएफए यूज करता है और

play20:55

दूसरा क्या है आपका मेन इंपॉर्टेंट जो इस

play20:58

पूरे पॉइंट का यानी इस पूरे टॉपिक का जो

play21:00

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

play21:03

ध्यान रखना है टोकन लिखते वक्त ये था आपका

play21:06

टोकेनाइजेशन ओके

Rate This

5.0 / 5 (0 votes)

Related Tags
Lexical AnalysisTokenizationProgramming ConceptsCompiler TheorySyntax ParsingSemantic AnalysisLanguage ProcessingCode SyntaxCompiler DesignSyntax Errors