Lexical Analysis – Compiler



Compiler :

Compiler takes high level human readable program as input and convert it into the lower level code.This conversion takes place using different phases.First phase of compiler is lexical analysis.

Must Read : [What is Compiler ?]

Different phases of compilers :

  1. Analysis Phase
  2. Synthesis Phase

1.Analysis Phase :

Lexical Analysis Phase :

Task of Lexical Analysis is to read the input characters and produce as output a sequence of tokens that the parser uses for syntax analysis.
Lexical Analyser in Compiler Design - Phases of Compiler in C Programming

  1. Lexical Analyzer is First Phase Of Compiler.
  2. Input to Lexical Analyzer is “Source Code
  3. Lexical Analysis Identifies Different Lexical Units in a Source Code.
  4. Different Lexical Classes or Tokens or Lexemes
    • Identifiers
    • Constants
    • Keywords
    • Operators
  5. Example : sum = num1 + num2 ;

Concept of Lexical Analyzer in Compiler Design
So Lexical Analyzer Will Produce following Symbol Table

Token Type
sum Identifier
= Operator
num1 Identifier
+ Operator
num2 Identifier
; Seperator
  1. Lexical Analyzer is also called “Linear Phase” or “Linear Analysis” or “Scanning
  2. Individual Token is also Called Lexeme
  3. Lexical Analyzer’s Output is given to Syntax Analysis.