31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

INPUT AND OUTPUT<br />

7.16 TERMINAL I/O<br />

The <strong>PASCAL</strong> language requires that the file buffer always contain the<br />

next file component that will be processed by the program. This<br />

requirement can cause problems when the input to the program depends<br />

on the output most recently generated. To alleviate such problems in<br />

the processing of the predeclared text files INPUT and OUTPUT, <strong>PASCAL</strong><br />

uses a technique called delayed device access, also know as lazy<br />

lookahead.<br />

As a result of delayed device access, an item of data is not retrieved<br />

from a physical file device and inserted in the file buffer until the<br />

program is ready to process it. The file buffer is filled when the<br />

program makes the next reference to the file. A reference to the file<br />

consists of any use of the file buffer variable, including its<br />

implicit use in the GET, READ, and READLN procedures, or any test for<br />

the status of the fi1e, namely, the EOF and EOLN functions.<br />

The RESET procedure initiates the process of delayed device access.<br />

RESET is done automatically on the prede~lared file INPUT. RESET<br />

expects to fill the file buffer with the first component of the file.<br />

However, because of delayed device access, an item of data is not<br />

supplied from the input device to fill the file buffer until the next<br />

reference to the file.<br />

When writing a program for which the input will be supplied by the<br />

predeclared text file INPUT, you should be aware that delayed device<br />

access occurs. Because RESET initiates delated device access, and<br />

because EOF and EOLN cause the buffer to be filled, you should place<br />

the first prompt for input before any tests for EOF or EOLN. The<br />

information you enter in response to the prompt supplies the data that<br />

is retained by the file device until you make another reference to the<br />

input file.<br />

Example<br />

VAR<br />

I<br />

INTEGER;<br />

BEGIN<br />

WRITE ('Enter an integer or an empty line: ');<br />

WHILE NOT EOLN DO<br />

BEGIN<br />

READLN (I);<br />

WRITELN ('The integer was: ' , 1:1);<br />

WRITE ('Enter an integer or an empty line: ');<br />

END;<br />

WRITELN ('Done');<br />

END.<br />

7-28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!