Roles of the Lexical analyzer


Lexical analyzer performs below given tasks:
  • Helps to identify token into the symbol table
  • Removes white spaces and comments from the source program
  • Correlates error messages with the source program
  • Helps you to expands the macros if it is found in the source program
  • Read input characters from the source program

Example of Lexical Analysis, Tokens, Non-Tokens
Consider the following code that is fed to Lexical Analyzer

#include <stdio.h>
    int maximum(int x, int y) {
        // This will compare 2 numbers
        if (x > y)
            return x;
        else {
            return y;
        }
    }


Examples of Tokens created

 

LexemeToken
intKeyword
maximumIdentifier
(Operator
intKeyword
xIdentifier
,Operator
intKeyword
YIdentifier
)Operator
{Operator
IfKeyword


 

Examples of Nontokens

TypeExamples
Comment// This will compare 2 numbers
Pre-processor directive#include <stdio.h>
Pre-processor directive#define NUMS 8,9
MacroNUMS
Whitespace/n /b /t


Share to whatsapp

More Questions from System Software and Compiler Design Module 2

Explain the absolute loader and Write its algorithm.
View
How object program can be processed using linkage editor?
View
The linkage editor
View
What is Lexical Analysis?
(or)
Lexical Analysis in Compiler Design with Example
View
Lexical Analyzer Architecture.
(or) How tokens are recognized
View
Input Buffering in Compiler Design
View
Roles of the Lexical analyzer
View