Professional Documents
Culture Documents
Assalam o Alaikum!
I am Mohammad Aakash
(2223)
2
What is Ad hoc?
3
What is Lexer?
4
What is Lexical Analysis?
“ “The process of converting
sequence of characters
into sequence of tokens ”
https://en.wikipedia.org/w
iki/Lexical
6
Ad - hoc Lexer
8
class Lexer
{
Inputstream s;
char next; //Lookahead
Lexer(Inputstream _s){
s=_s;
next=s.read( );
} 9
Token nextToken(){
if(idChar(next))
return readId();
if(number(next))
return readNumber();
if(next==‘ ” ’)
return readString();
…...
10
Token readId( ){
string id=“ “;
while(true){
char c=input.read( );
if(idChar ( c ) ==false)
return
new Token{TID,id};
id=id + string( c );
}
}
11
boolean idChar(char c){
if( isAlpha ( c) )
return true;
if( isDigit( c ) )
return true;
if( c== ‘ _ ’)
return true;
return false;
}
12
Token readNumber(){
string num = “”;
while(true){
next = input.read();
if( !isNumber(next))
return
new Token(TNUM,num);
num = num+string(next);
}
}
13
THANKS!
Any questions?
14