/    /  Compiler Design-Sentinels

Sentinels

 

In the Buffer pairs scheme, every time the forward pointer is moved, it checks in order to ensure that one half of the buffer did not move off. If it is done, then the other half should be reloaded.

 

Hence, the ends of the buffer halves need to go through two tests for every advance of the forward pointer.

  • Test 1: For the end of the buffer.
  • Test 2: To determine what character is to be read.
  • The usage of sentinel helps to reduce the two tests that are required into one by extending each buffer half to hold a sentinel character at the end.
  • The sentinel is a special character that should not be a part of the source code.
  • An eof character is used as a Sentinel

 

Advantages

  • It only performs one test to see if the forward pointer points to a eof.
  •  It performs more tests only when it reaches the end of buffer half.
  • The average test for every input character is close to 1 since there are N input characters encountered between eofs.

 

Reference Link

Sentinels