# What are the operations on sequential files in compiler design?

Compiler DesignProgramming LanguagesComputer Programming

#### Web Design for Beginners: Build Websites in HTML & CSS 2022

68 Lectures 8 hours

#### HTML5 & CSS3 Site Design

61 Lectures 6 hours

The major operations on sequential files are as follows −

• Creating a file − The primary creation of a file is also defined as the loading of the file. In some implementations, space is first designated to the file, thus the data are loaded into that Skelton.

• Opening a file − Before a program can access a file for input or output, that file must be opened. The open operation is given the name of a file and the access mode (read or write). In Pascal, the procedure reset opens a file in read mode and the procedure rewrite opens a file in write mode.

• Reading a file − Records are read form a sequential file using the following types of statements. In COBOL

AT END imperative – statement

where the filename is defined in an FD (File Description), the optional. INTO clause specifies an identifier in WORKING-STORAGE that will receive the contents of the record, and the AT END clause is required to specify what is to happen when the input file is exhausted.

In PASCAL-

depending on the disposition of any leftover characters in the input record, where the filename appears in the program statement and the record name variable will receive the data.

• Writing a file − A write operation generates a new component at the content position in the file and shift the contents of a designated program variable to the new component. In COBOL

WRITE record-name [FROM identifier]

where the record name is defined in the file’s FD (file description) and the optional identifier of the FROM clause is defined in WORKING-STORAGE

In PASCAL-

writeln (Filename, recordname);

write (Filename, recordname);

depending upon whether or not a new line is to be started after this one, where the filename appears in the program statement and the record name variable will include the information to be written. The record will appear on the file in the same order as they are written.

• Updating a file − It can modify the contents of a master file to create it follow a more current snapshot of the real world is called updating the file. These changes can include the insertion, deletion, and modification of records.

• Retrieving from a file − The access of a file for goals of deriving meaningful data is called retrieval.

• Maintaining a file − Changes that are made to files to enhance the implementation of the programs that create them are known as maintenance activities.

• End-of-file test − An explicit test for the end-of-file position is required therefore that the program can take a specific action. Pascal provides a function −

eof:file→Boolean

that returns true if the file is positioned at its end, and false otherwise.

Updated on 23-Oct-2021 11:16:39