INPUT BUFFERING Presentation by Rushikesh kadam SYSTEM SOFTWARE
Lexical analyzer Input string from source code Tokens, lexims i nt 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 i nt 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 i nt i ,j ; i =i+1; i n t i , j ; BP FP e of Second buffer i n t i , j ; BP FP e of First buffer e of = end of file buffer sentinal
Algorithm s witch(*forward++) { } c ase ‘ eof ’: i f (forward is at the end of 1 st buffer) { forward= beginning of 2 nd buffer; refill 2 nd buffer ; } e lse if (forward is at the end of 2 nd buffer) { forward= beginning of 1st buffer; r efill 1 st buffer; } e lse break; c ase for other charcters :