Input Buffering

Estudies4you
Input Buffering in Compiler Design

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,

Home
To Top