IUP Computer Science
CO 310 Spring 1982

Project 3

File QUEUE310.COMPSCI contains a mixture of input commands and data. Each data value is a number that occurs right-justified in a four-column field. Each data value is on a separate record. Each input command consists of two parts: a server action and a queue entry in the following format.

    Column #      1 2 3 4 5 6 7 8 9 0 1 2 3
                  S S S S S S   E E E E E 
The 'SSSSSS' is the server action; the.'EEEEE' is the queue entry.

The queue entries are tasks to be placed at the rear of a queue of things to do. These tasks are performed on the data when indicated by a server action. The server actions indicate what to do with the task at the front of the queue. The server actions and queue entries are described below.

    Server Action     What to do
	
    NEXT              Perform the task at the front of the queue. If there
                      is no task in the queue, print a message and perform a WAIT.
					  
    IGNORE            Delete the task at the front of the queue. If there
                      is no task in the queue, print a message and perform a WAIT.

    WAIT              Do nothing to the front of the queue.

    Queue Entry       Task to Perform

    READ              Read the data value on the next record.
 
    INCR              Add 1 to the data.value.

    PRINT             Print the data value.

If the queue entry is blank, no task should be added to the queue.

Write a program that uses a circular queue to process the commands and data in the QUEUES10.COMPSCI file. Your output should consist of the results of the PRINT task (print the current data value) and error messages. After the last command is processed, list any entries still in the queue and the current data value.

Your program will act as a crude interpreter, performing the "program" contained in the file. The language for this "program" contains control statements (server actions), I/O statements (READ and PRINT) and an assignment statement (INCR). The following sample input indicates how the "program" is to be interpreted.

     
     Input Command            Action Taken
     WAIT   READ 
     WAIT   PRINT 
     NEXT   INCR              Read the data value (30)
       30
     IGNORE INCR              Discard the PRINT task
     NEXT   PRINT             Increment the data value (it becomes 31)
     IGNORE                   Discard the second INCR task
     NEXT                     Print the data value (31)
     NEXT                     Print error message, queue is empty
     NEXT   READ              Read the data value (54)
       54
     WAIT   PRINT
     NEXT                     Print the data value (54)
Note: Your program should always handle the adding of a queue entry before performing the server action.