Roles of the Lexical analyzer

Boomi Nathan
1 Min Read
Disclosure: This website may contain affiliate links, which means I may earn a commission if you click on the link and make a purchase. I only recommend products or services that I personally use and believe will add value to my readers. Your support is appreciated!

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 This Article

J. BoomiNathan is a writer at SenseCentral who specializes in making tech easy to understand. He covers mobile apps, software, troubleshooting, and step-by-step tutorials designed for real people—not just experts. His articles blend clear explanations with practical tips so readers can solve problems faster and make smarter digital choices. He enjoys breaking down complicated tools into simple, usable steps.

Leave a review