DIZNR INTERNATIONAL

Lexical Analysis in simple words – token generation, blank space, symbol table, lexical error

Lexical Analysis in simple words – token generation, blank space, symbol table, lexical error

https://www.gyanodhan.com/video/7B2.%20GATE%20CSEIT/Compiler%20Design/276.%20Lexical%20Analysis%20in%20simple%20words%20-%20token%20generation%20%20%20blank%20space%20%20%20symbol%20table%20%20%20lexical%20error.mp4

Lexical Analysis in Simple Words

Lexical Analysis is the first phase of a compiler that breaks down the source code into smaller meaningful units called tokens. This process is done by a program called the Lexical Analyzer (Lexer).

 How Lexical Analysis Works?

 The source code is read character by character.
 Meaningful groups of characters are converted into tokens.
 Unnecessary characters like spaces, tabs, and comments are removed.
 A symbol table is created to store identifiers and keywords.
 If an unknown symbol is found, a lexical error is reported.

 Example of Token Generation

Input Code:

int x = 10;

Lexical Analyzer Output (Tokens):

Keyword: int
Identifier: x
Operator: =
Number: 10
Symbol: ;

Each part of the code is classified into a specific token type.

 Handling Blank Spaces & Comments

Whitespace (spaces, tabs, new lines) is ignored by the lexical analyzer.
Comments (//, /* ... */) are removed, as they don’t affect program execution.

Example:

int a = 5; // This is a comment

 The lexer ignores "// This is a comment" and processes only:

Keyword: int
Identifier: a
Operator: =
Number: 5
Symbol: ;

 Symbol Table

 A symbol table stores identifiers (variable names, function names) and their attributes like data type, memory location, scope, etc.
 It helps the compiler track variables efficiently.

Example Symbol Table:

Identifier Type Memory Location
x int 1001
y float 1002

 Lexical Errors

Errors occur when the lexer finds an unknown or invalid character.

Example:

int @x = 10;

Lexical Error: “Unexpected character ‘@’ found.”

 Summary

Lexical Analysis breaks code into tokens.
Blank spaces & comments are ignored.
 A symbol table stores variable names and types.
Lexical errors occur due to unknown characters.

Would you like a step-by-step breakdown of a real Lexical Analysis process?

Lexical Analysis in simple words – token generation, blank space, symbol table, lexical error

LEXICAL ANALYSIS Structure of compiler – Functions and …

Lexical Analysis – Compiler Construction

compiler design lecture notes

Chapter 3 Lexical Analysis

CS 335: Lexical Analysis

Here is a simple explanation of Lexical Analysis and its key components, written in easy language (suitable for beginners or non-technical readers):


Lexical Analysis in Simple Words

Lexical Analysis is the first step of a compiler.
It reads the code written by a programmer and breaks it into small parts called tokens.


1. What is a Token?

A token is a small, meaningful unit in a programming language.
Think of it like words in a sentence.

Example:

c
int x = 5;

This line will be broken into tokens like:

Token Type Token Value
Keyword int
Identifier x
Operator =
Constant 5
Symbol ;

These tokens help the compiler understand the code step-by-step.


2. Role of Blank Spaces

Example:

c
int a=10;

Even with extra spaces, the tokens will still be:
int, a, =, 10, ;


3. Symbol Table

A symbol table is like a notebook the compiler uses to remember:

Every time a new identifier is found (like a variable name), it is stored in the symbol table.


4. Lexical Errors

These are mistakes in the structure of the code, usually when:

Example:

c
int 2num = 5; // Error: variable cannot start with number

This is a lexical error.


Summary Table:

Term Meaning in Simple Words
Token Smallest meaningful unit (like a word)
Blank Space Used to separate tokens; ignored by lexer
Symbol Table A record of variable/function names and info
Lexical Error Error in token creation (like wrong names or characters)

Would you like a visual chart, example code walkthrough, or a PDF summary of this topic?

Lexical Analysis in simple words – token generation, blank space, symbol table, lexical error

Compilers Download