Input Buffering

Input Buffering

  • The lexical analyzer scans only one character in the input string at a time from left to right
  • It makes use of two pointers, begin pointer (bptr) and forward pointer (fptr), for maintaining a track of the input scanned
  • Initially both the pointers point to the first character of the input string as shown


  • The bptr remains at the beginning of the string to be read and the fptr moves ahead to search for end of lexeme. Once 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 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
There are two methods used in this context
Ø  One Buffer Scheme
Ø  Two Buffer Scheme
One Buffer Scheme:
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 part of lexeme.

Two Buffer Scheme:

Here, we use a buffer divided into two N-character (N is generally equal to the maximum number of characters that be read at one time) halves as shown below,

Share on Google Plus

About Data Sciences by Venu

Hi, My name is Venugopala Chary and I'm Currently working as Associate Professor in Reputed Engineerng College, Hyderabad. I have B.Tech and M.tech in regular from JNTU Hyderabad. I have 11 Years of Teaching Experience for both B.Tech and M.Tech Courses.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment