What is Lexical Analysis?
(or)
Lexical Analysis in Compiler Design with Example


LEXICAL ANALYSIS is the very first phase in the compiler designing. A Lexer takes the modified source code which is written in the form of sentences . In other words, it helps you to convert a sequence of characters into a sequence of tokens. The lexical analyzer breaks this syntax into a series of tokens. It removes any extra space or comment written in the source code. Programs that perform lexical analysis are called lexical analyzers or lexers. A lexer contains tokenizer or scanner. If the lexical analyzer detects that the token is invalid, it generates an error. It reads character streams from the source code, checks for legal tokens, and pass the data to the syntax analyzer when it demands.

Example

How Pleasant Is The Weather?
See this example; Here, we can easily recognize that there are five words How Pleasant, The, Weather, Is. This is very natural for us as we can recognize the separators, blanks, and the punctuation symbol.



 HowPl easantIs Th ewe ather?
Now, check this example, we can also read this. However, it will take some time because separators are put in the Odd Places. It is not something which comes to you immediately.


Share to whatsapp

More Questions from System Software and Compiler Design Module 2

Structure of a Compiler Design - Phases of Compiler
View
How object program can be processed using linkage editor?
View
Explain the absolute loader and Write its algorithm.
View
Write note on MASM assembler
View
Explain Lexical analysis with a block diagram
View
With an algorithm, explain pass1 of a linking loader
View
How Program linking is possible in loaders?
View