Subsections

- Exercises

#
Program structure

Algol 68 programs can be written in one or more parts Here is a valid Algol 68 program:

       PROGRAM firstprogram CONTEXT VOID
       USE standard
       BEGIN
          print(20)
       END
       FINISH

Only the three lines starting with `BEGIN` and ending with `END` are strictly part of the Algol 68 program. The first, second and last lines are specific to the a68toc compiler. The first line gives the identification of the program as `firstprogram` and the fact that this file contains a program. The `CONTEXT VOID` phrase specifies that the program stands on its own instead of being embedded in other parts. The phrase is a vestige of the modular compilation system originally provided by the compiler at the heart of `a68toc`.

A full explanation of the `print` phrase will be found in chapter 9 (Transput). For now, it is enough to know that it causes the value in the parentheses to be displayed on the screen.2.3 The standard prelude must be `USE`d if you want to use `print`. You can use any identifier for the operating system file in which to store the Algol 68 source code of the program. Although it does not have to be the same as the identifier of the module, it is advisable to make it so.

Both the `print` phrase and the denotation are units. Chapter 10 will explain units in detail. Phrases are separated by the go-on symbol (a semicolon `;`). Because there is only one phrase in `firstprogram`, no go-on symbols are required. Here is another valid program:

       PROGRAM prog CONTEXT VOID
       USE standard
       BEGIN
          INT special integer = 48930767;
          print(20) ; print(special integer)
       END
       FINISH

The semicolon between the two `print` phrases is not a terminator: it is a separator. It means “throw away any value yielded by the previous phrase and go on with the succeeding phrase”. That is why it is called the go-on symbol. Notice that there is no semicolon after the third phrase.

Algol 68 programs are written in free format. This means that the meaning of your program is independent of the layout of the source program. However, it is sensible to lay out the code so as to show the structure of the program. For example, you could write the first program like this:

       PROGRAM firstprogram CONTEXT VOID
       USE standard(print(20))FINISH

which is just as valid, but not as comprehensible. Notice that `BEGIN` and `END` can be replaced by `(` and `)` respectively. How you lay out your program is up to you, but writing it as shown in the examples in this book will help you write comprehensible programs.

## Exercises

1.12
  What is wrong with this sample program?

         PROGRAM test
         BEGIN
            print("A"))
         END
         FINISH

  Ans
1.13
  Using an editor, key in the two sample programs given in this section, and compile and execute them. What do they display on your screen? Ans