Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

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. This article will help you to understand all the aspects of lexical analysis in an effective way. We believe that the information provided below will help you to gain deep knowledge about the topic.

What is Lexical Analysis?

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.

Video on Lexical Analysis

Terminologies

There are three terminologies-

  • Token
  • Pattern
  • Lexeme

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.

The Architecture of Lexical Analyzer

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

Roles and Responsibility of Lexical Analyzer

The lexical analyzer performs the following tasks-

  • 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.

Lexical Analysis

Advantages of Lexical Analysis

  • 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.

Disadvantages of Lexical Analysis

  • 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.

Video on Lexical Analysis

Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility CriteriaGATE 2023GATE Admit CardGATE Syllabus for CSE (Computer Science Engineering)GATE CSE NotesGATE CSE Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*