The package Character_Io whose specification is given below, provides a function for reading characters from the terminal. It also provides a procedure for throwing away all the remaining characters on the current line. The package may raise the exception Io_Error.
package Character_Io is
function Get return Character;
-- reads a charactex from the terminal
procedure Flush;
-- throw away all character on the current line
Io_Error : exception;
end Character_Io;
Another package Look contains the function Read which scans the current input line looking for the punctuation characters comma (,) period (.) and semicolon (;). The function will return the next punctuation character found or raise the exception Illegal_Punctuation if a non-alphanumeric character is found. If,
during the process of scanning the input line, an Io_Error is encountered, then the exception is propagated to the caller of Read. The specification of Look is given below.
with Character_Io; use Character_Io;
package Look is
type Punctuation is (Comma, Period, Semicolon);
function Read return Punctuation;
-- reads the next , . or ; from the terminal
Illegal_Punctuation : exception;
end Look;
Sketch the package body of Look using the Character_Io package for reading characters from the terminal. On receipt of a legal punctuation character, an illegal punctuation character or an Io_Error exception, the remainder of the input line should be discarded. You may assume that an input line will always have a legal or illegal punctuation character and that Io_Errors occur at random. Using the Look package, sketch the code of a procedure Get_Punctuation which will always return the next punctuation character in spite of the exceptions that Look raises. An infinite input stream may be assumed.