SlideShare a Scribd company logo
COMPILER DESIGN S.KRISHNAVENI,
LEXICAL ANALYSIS ASSISTANT PROFESSOR
INFORMATION TECHNOLOGY
Lexical Analysis Notes for GATE
• Lexical analysis is an important topic, belonging to the
Computer Science family. And, when you are
preparing for competitive examinations like GATE, you
need to have complete information about this topic.
• What is Compiler?
• What is Lexical Analysis?
• Terminologies
• The architecture of the Lexical analyzer
• Functions of lexical analyzer
• Types of Tokens
• Lexical analysis is the starting phase of the compiler.
• It gathers modified source code that is written in the
form of sentences from the language preprocessor.
• The lexical analyzer is responsible for breaking these
syntaxes into a series of tokens, by removing
whitespace in the source code.
• If the lexical analyzer gets any invalid token, it
generates an error. The stream of character is read by
it and it seeks the legal tokens, and then the data is
passed to the syntax analyzer, when it is asked for.
What is Lexical Analysis?
• Token: It is a sequence of characters that
represents a unit of information in the source
code.
• Pattern: The description used by the token is
known as a pattern.
• Lexeme: A sequence of characters in the source
code, as per the matching pattern of a token, is
known as lexeme. It is also called the instance
of a token.
Terminologies
• To read the input character in the source code and produce
a token is the most important task of a lexical analyzer.
• The lexical analyzer goes through with the entire source
code and identifies each token one by one.
• The scanner is responsible to produce tokens when it is
requested by the parser.
• The lexical analyzer avoids the whitespace and comments
while creating these tokens.
• If any error occurs, the analyzer correlates these errors with
the source file and line number.
The Architecture of Lexical Analyzer
The Architecture of Lexical Analyzer
The Architecture of Lexical Analyzer
• The lexical analyzer is responsible for removing the
white spaces and comments from the source program.
• It corresponds to the error messages with the source
program.
• It helps to identify the tokens.
• The input characters are read by the lexical analyzer
from the source code.
Roles and Responsibility of Lexical Analyzer
Roles and Responsibility of Lexical Analyzer
• Lexical analysis helps the
browsers to format and
display a web page with
the help of parsed data.
• It is responsible to
create a compiled binary
executable code.
• It helps to create a more
efficient and specialised
processor for the task.
• It requires additional
runtime overhead to
generate the lexer table and
construct the tokens.
• It requires much effort to
debug and develop the lexer
and its token description.
• Much significant time is
required to read the source
code and partition it into
tokens.
Advantages and Disadvantages
of Lexical Analyzer
Advantages and Disadvantages
of Lexical Analyzer
• It will identify lexemes in the given input.
• It will produce tokens as output.
• It will ignore/delete comments & white spaces
• It will produce lexical error if any
• It makes an entry into symbol table for each
identifiers.
• It should scan 1st
character of source code till
last character.
Functions of Lexical Analyzer
1. Which of the following is not a token?
(a) Identifier
(b)Keyword
(c) Operator
(d)None of these
Lexical Analyzer
2. Which of the following is recognized by Lexical
analysis?
(a) Token
(b)Comment
(c) White Spaces
(d)All of these
Lexical Analyzer
3.Which of the following is Lexical error?
(a) a1
(b)1a
(c) a
(d)1
Lexical Analyzer
4. Which of the following statement is lexically
valid?
(a) INT x;
(b)int x;
(c) x int;
(d)All of these
Lexical Analyzer
5. Find number of tokens in the following code.
int x==y;
(a) 6
(b)5
(c) 4
(d)3
Lexical Analyzer
6. Find the number of tokens in the following
code
x+=y++***z
(a) 11
(b)10
(c) 9
(d)8
Lexical Analyzer
7. Find the number of tokens in the following
code.
int/*comment*/ x;
(a) 4
(b)3
(c) 2
(d)1
Lexical Analyzer
8. Find the number of tokens in the following
code.
in/*comment*/t x;
(a) 4
(b)3
(c) 2
(d)1
Lexical Analyzer
9. Which of the following is not a single token?
(a) **
(b)++
(c) <=
(d)All of these
Lexical Analyzer
9. Which of the following is a single token?
(a) &&
(b)++
(c) +=
(d)All of these
Lexical Analyzer
10. Which of the following is not a single token?
(a) ==
(b)+=
(c) =+
(d)All of these
Lexical Analyzer
11. Which of the following can be used to
recognize the tokens in lexical analysis?
(a) Finite Automata
(b)Push down Automata
(c) Turing Machine
(d)All of these
Lexical Analyzer
12. Which of the following phase uses symbol
table in compiler?
(a) Lexical Analysis
(b)Syntax Analysis
(c) Semantic Analysis
(d)All of these.
Lexical Analyzer
Lexical Analyzer

More Related Content

PPTX
Cd ch2 - lexical analysis
PDF
11700220036.pdf
PPT
Data design and analysis of computing tools
PPTX
Compiler Construction ( lexical analyzer).pptx
PPT
Lexical Analysis
PPTX
Chapter 2.pptx compiler design lecture note
PPTX
Compiler Design.pptx
PPTX
ashjhas sahdj ajshbas sajakj askk sadk as
Cd ch2 - lexical analysis
11700220036.pdf
Data design and analysis of computing tools
Compiler Construction ( lexical analyzer).pptx
Lexical Analysis
Chapter 2.pptx compiler design lecture note
Compiler Design.pptx
ashjhas sahdj ajshbas sajakj askk sadk as

Similar to "Lexical Analysis for GATE and CS Exams" (20)

PDF
Lexical Analysis.pdf
PDF
An Introduction to the Compiler Designss
PPT
Lexical Analysis
PPT
1.Role lexical Analyzer
PDF
role of lexical parser compiler design1-181124035217.pdf
PDF
Lexical Analysis
PPTX
automata theroy and compiler designc.pptx
PDF
COMPILER DESIGN.pdf
DOCX
Compiler Design
PPTX
Lexical analyzer
PPTX
Valuable Information on Lexical Analysis in Compiler Design
PPTX
Language for specifying lexical Analyzer
PPTX
A Role of Lexical Analyzer
PPTX
Lexical Analysis - Compiler Design
PDF
Assignment4
PPT
Lecturer-05 lex anylser (1).pptrjyghsgst
PPTX
Role-of-lexical-analysis
PPTX
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
PPTX
Lexical analysis
PDF
Structure of a Compiler, Compiler and Interpreter, Lexical Analysis: Role of ...
Lexical Analysis.pdf
An Introduction to the Compiler Designss
Lexical Analysis
1.Role lexical Analyzer
role of lexical parser compiler design1-181124035217.pdf
Lexical Analysis
automata theroy and compiler designc.pptx
COMPILER DESIGN.pdf
Compiler Design
Lexical analyzer
Valuable Information on Lexical Analysis in Compiler Design
Language for specifying lexical Analyzer
A Role of Lexical Analyzer
Lexical Analysis - Compiler Design
Assignment4
Lecturer-05 lex anylser (1).pptrjyghsgst
Role-of-lexical-analysis
Chahioiuou9oioooooooooooooofffghfpterTwo.pptx
Lexical analysis
Structure of a Compiler, Compiler and Interpreter, Lexical Analysis: Role of ...
Ad

Recently uploaded (20)

PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
737-MAX_SRG.pdf student reference guides
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPT
Total quality management ppt for engineering students
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
737-MAX_SRG.pdf student reference guides
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Fundamentals of safety and accident prevention -final (1).pptx
Information Storage and Retrieval Techniques Unit III
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Module 8- Technological and Communication Skills.pptx
Exploratory_Data_Analysis_Fundamentals.pdf
III.4.1.2_The_Space_Environment.p pdffdf
Abrasive, erosive and cavitation wear.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Total quality management ppt for engineering students
distributed database system" (DDBS) is often used to refer to both the distri...
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Ad

"Lexical Analysis for GATE and CS Exams"

  • 1. COMPILER DESIGN S.KRISHNAVENI, LEXICAL ANALYSIS ASSISTANT PROFESSOR INFORMATION TECHNOLOGY
  • 2. Lexical Analysis Notes for GATE • Lexical analysis is an important topic, belonging to the Computer Science family. And, when you are preparing for competitive examinations like GATE, you need to have complete information about this topic. • What is Compiler? • What is Lexical Analysis? • Terminologies • The architecture of the Lexical analyzer • Functions of lexical analyzer • Types of Tokens
  • 3. • Lexical analysis is the starting phase of the compiler. • It gathers modified source code that is written in the form of sentences from the language preprocessor. • The lexical analyzer is responsible for breaking these syntaxes into a series of tokens, by removing whitespace in the source code. • If the lexical analyzer gets any invalid token, it generates an error. The stream of character is read by it and it seeks the legal tokens, and then the data is passed to the syntax analyzer, when it is asked for. What is Lexical Analysis?
  • 4. • Token: It is a sequence of characters that represents a unit of information in the source code. • Pattern: The description used by the token is known as a pattern. • Lexeme: A sequence of characters in the source code, as per the matching pattern of a token, is known as lexeme. It is also called the instance of a token. Terminologies
  • 5. • To read the input character in the source code and produce a token is the most important task of a lexical analyzer. • The lexical analyzer goes through with the entire source code and identifies each token one by one. • The scanner is responsible to produce tokens when it is requested by the parser. • The lexical analyzer avoids the whitespace and comments while creating these tokens. • If any error occurs, the analyzer correlates these errors with the source file and line number. The Architecture of Lexical Analyzer
  • 6. The Architecture of Lexical Analyzer
  • 7. The Architecture of Lexical Analyzer • The lexical analyzer is responsible for removing the white spaces and comments from the source program. • It corresponds to the error messages with the source program. • It helps to identify the tokens. • The input characters are read by the lexical analyzer from the source code. Roles and Responsibility of Lexical Analyzer
  • 8. Roles and Responsibility of Lexical Analyzer
  • 9. • Lexical analysis helps the browsers to format and display a web page with the help of parsed data. • It is responsible to create a compiled binary executable code. • It helps to create a more efficient and specialised processor for the task. • It requires additional runtime overhead to generate the lexer table and construct the tokens. • It requires much effort to debug and develop the lexer and its token description. • Much significant time is required to read the source code and partition it into tokens. Advantages and Disadvantages of Lexical Analyzer
  • 10. Advantages and Disadvantages of Lexical Analyzer • It will identify lexemes in the given input. • It will produce tokens as output. • It will ignore/delete comments & white spaces • It will produce lexical error if any • It makes an entry into symbol table for each identifiers. • It should scan 1st character of source code till last character. Functions of Lexical Analyzer
  • 11. 1. Which of the following is not a token? (a) Identifier (b)Keyword (c) Operator (d)None of these Lexical Analyzer
  • 12. 2. Which of the following is recognized by Lexical analysis? (a) Token (b)Comment (c) White Spaces (d)All of these Lexical Analyzer
  • 13. 3.Which of the following is Lexical error? (a) a1 (b)1a (c) a (d)1 Lexical Analyzer
  • 14. 4. Which of the following statement is lexically valid? (a) INT x; (b)int x; (c) x int; (d)All of these Lexical Analyzer
  • 15. 5. Find number of tokens in the following code. int x==y; (a) 6 (b)5 (c) 4 (d)3 Lexical Analyzer
  • 16. 6. Find the number of tokens in the following code x+=y++***z (a) 11 (b)10 (c) 9 (d)8 Lexical Analyzer
  • 17. 7. Find the number of tokens in the following code. int/*comment*/ x; (a) 4 (b)3 (c) 2 (d)1 Lexical Analyzer
  • 18. 8. Find the number of tokens in the following code. in/*comment*/t x; (a) 4 (b)3 (c) 2 (d)1 Lexical Analyzer
  • 19. 9. Which of the following is not a single token? (a) ** (b)++ (c) <= (d)All of these Lexical Analyzer
  • 20. 9. Which of the following is a single token? (a) && (b)++ (c) += (d)All of these Lexical Analyzer
  • 21. 10. Which of the following is not a single token? (a) == (b)+= (c) =+ (d)All of these Lexical Analyzer
  • 22. 11. Which of the following can be used to recognize the tokens in lexical analysis? (a) Finite Automata (b)Push down Automata (c) Turing Machine (d)All of these Lexical Analyzer
  • 23. 12. Which of the following phase uses symbol table in compiler? (a) Lexical Analysis (b)Syntax Analysis (c) Semantic Analysis (d)All of these. Lexical Analyzer