Raj Kumar
Computer Science And Engineering

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

System Software and Compiler Design

Explanation

974    0
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:   
   Raj Kumar
Computer Science And Engineering

More Questions from System Software and Compiler Design Module 2