Presentation by
Rushikesh kadam
SYSTEM
SOFTWARE
Lexical analyzer
Input string from
source code
Tokens,
lexims
int main( )
{
}
i n t m a i n ( ) { }
i n t m a i n ( ) { }
• Lexim begin pointer
• points to the beginning of every token
• Forward pointer
• Points every next character in the input string
Begin pointer
Forward
pointer
intially
i n t m a i n ( ) { }
Begin pointer
Forward
pointer
i n t m a i n ( ) { }
Begin pointer
Forward
pointer
i n t m a i n ( ) { }
Begin pointer
Forward
pointer
End of lexime
i n t m a i n ( ) { }
Begin pointer
Forward
pointer
i n t m a i n ( ) { }
Reading each
character
One system call
1000 character s 1000 system call
Buffering
• One Buffer Scheme
int i,j ;
A block of data is first read into a buffer, and then
second by lexical analyzer.
i n t i , j ;
In this scheme, only one buffer is used to store the input
string but the problem with this scheme is that if lexeme is
very long then it crosses the buffer boundary, to scan rest of
the lexeme the buffer has to be refilled, that makes
overwriting the first of lexeme.
• Two Buffer Scheme
int i,j ;
i=i+1;
i n t i , j ;
BP
FP
eof
Second buffer
i n t i , j ;
BP
FP
eof
First buffer
eof = end of file buffer
sentinal
• Algorithm
switch(*forward++)
{
}
case ‘ eof’:
if (forward is at the end of 1st buffer)
{
forward= beginning of 2nd buffer;
refill 2nd buffer;
}
else if (forward is at the end of 2nd buffer)
{
forward= beginning of 1st buffer;
refill 1st buffer;
}
else break;
case for other charcters :
THANK YOU!

Input buffering

  • 1.
  • 2.
    Lexical analyzer Input stringfrom source code Tokens, lexims int main( ) { } i n t m a i n ( ) { }
  • 3.
    i n tm a i n ( ) { } • Lexim begin pointer • points to the beginning of every token • Forward pointer • Points every next character in the input string Begin pointer Forward pointer intially
  • 4.
    i n tm a i n ( ) { } Begin pointer Forward pointer i n t m a i n ( ) { } Begin pointer Forward pointer
  • 5.
    i n tm a i n ( ) { } Begin pointer Forward pointer End of lexime
  • 6.
    i n tm a i n ( ) { } Begin pointer Forward pointer
  • 7.
    i n tm a i n ( ) { } Reading each character One system call 1000 character s 1000 system call
  • 8.
    Buffering • One BufferScheme int i,j ; A block of data is first read into a buffer, and then second by lexical analyzer. i n t i , j ; In this scheme, only one buffer is used to store the input string but the problem with this scheme is that if lexeme is very long then it crosses the buffer boundary, to scan rest of the lexeme the buffer has to be refilled, that makes overwriting the first of lexeme.
  • 9.
    • Two BufferScheme int i,j ; i=i+1; i n t i , j ; BP FP eof Second buffer i n t i , j ; BP FP eof First buffer eof = end of file buffer sentinal
  • 10.
    • Algorithm switch(*forward++) { } case ‘eof’: if (forward is at the end of 1st buffer) { forward= beginning of 2nd buffer; refill 2nd buffer; } else if (forward is at the end of 2nd buffer) { forward= beginning of 1st buffer; refill 1st buffer; } else break; case for other charcters :
  • 11.