/    /  Compiler Design-Role of a Lexical Analyzer

Role of a Lexical Analyzer

 

The lexical Analyzer being the first phase in compiler designing, plays an important role.

  • It reads the source program, scans it, groups them into lexemes, and gives a sequence of tokens.
  • It eliminates the comments and white spaces present in the source code.
  • It helps in removing errors.
  • It reads the source program character by character and returns tokens of the source program.
  • It feeds the information about identifiers into the symbol table.
  • It expands macros in the source code if any is found.

 

Why do we need a Lexical Analyzer?

  1. Simplicity of the design of the compiler.
  2. Efficiency of the compiler is improved.
  3. Portability of the compiler is improved.

 

Reference Link

Role of a Lexical Analyzer