pcdunit2 class
pcdunit2 class
LEXICAL ANALYSIS
The Role of The Lexical Analyzer
Symbol
table
How lexical analyzer works?
Syntax checker in a compiler serves as the master program.
It first sends a request to get a valid token from the lexical
analyzer
Syntax checker do the grammar check over the token and then
asks for next token.
Any word that starts with an alphabet and can contain any
number or alphabet in between is called an identifier.
Token Lexeme
Identifier X
Operator equal =
Identifier X
Operator multiply *
Left parenthesis (
Identifier Acc
Operator Plus +
Integer constant 123
Examples of Tokens
regular
expression
It uses two pointers begin pointer and forward pointer bptr and
fptr to keep track of the portion of the input scanned.
Initially both the pointers point to the first character of the input
string
The bptr remains at the beginning of the string to be
read and the fptr moves ahead to search for end of
lexeme.
As soon as the blank space is encountered it
indicates end of lexeme
Then fptr will be at white space. When fptr
encounters white space it ignore and moves ahead.
Then both the bptr and fptr is set at next token i.
The input character is thus read from secondary
storage.
But reading in this way from secondary storage is
costly. Hence buffering technique is used.
A block of data is first read into a buffer, and then
scanned by lexical analyzer
In this method, the first buffer and second buffer are scanned
alternately.