Comments
Keywords: pame

Subsections

- Exercises

#
Comments

When you write a program in Algol 68, the pieces of program which do the work are called “source code”. The Algol 68 compiler translates this source code into C source code which is then translated by the GNU C compiler into “object code”. This is then converted by a program called a linker into machine code, which is understood by the computer. You then execute the program by typing its name at the command-line plus any arguments needed. This is called running the program.

When you write the program, it is usually quite clear to you what the program is doing. However, if you return to that program after a gap of several months, the source code may not be at all clear to you. To help you understand what you have written in the program, it is possible, and recommended, to write comments in the source code. Comments can be put almost anywhere, but not in the middle of mode indicants and not in the middle of denotations. A comment is ignored by the compiler, except that comments can be nested. A comment is surrounded by one of the following pairs:

       COMMENT ... COMMENT
       CO ... CO
       #...#
       {...}

where the ... represent the actual comment. The paired braces are peculiar to the a68toc compiler. Other compilers may not accept them. Here is an Algol 68 program with comments added:

       PROGRAM prog CONTEXT VOID
       USE standard
       BEGIN
          INT i = 23,  # My brother's age #
              s = 27; CO My sister's age CO
          CHAR z = "&",  COMMENT An ampersand
          COMMENT  y{acht}="y";
          REAL x = 1.25;
          print(i); print(s); print(z);
          print(y); print(x)
       END
       FINISH

There are four comments in the above program. If you start a comment with `CO` then you must also finish it with `CO`, and likewise for the other comment symbols (except the braces). Here is a program with a bit of source code “commented out”:

       PROGRAM prog CONTEXT VOID
       USE standard
       BEGIN
          INT i = 1, j = 2 #, k = 3#;
          print(i); print(j)
       END
       FINISH

The advantage of commenting out source is that you only have to remove two characters and that source can be included in the program again. You can use any of the comment symbols for commenting out. Here is another program with a part of the program containing a comment commented-out:

       PROGRAM prog CONTEXT VOID
       USE standard
       BEGIN
          INT i = 1;
          COMMENT
          REAL six = 6.0, # Used subsequently #
               one by 2 = 0.5;COMMENT
          CHAR x = "X";
          print(i); {print(six);} print(x)
       END
       FINISH

This is an example of nested comments. You can use any of the comment symbols for this purpose as long as you finish the comment with the matching symbol. However, if the part of your program that you want to comment out already contains comments, you should ensure that the enclosing comment symbols should be different. One way of using comment symbols is to develop a standard method. For example, the author uses the `#...#` comment symbols for one line comments in the code, `CO` symbols for multiline comments and `COMMENT` symbols for extensive comments required at the start of programs or similar code chunks.

## Exercises

1.14
  Write a short program which will print the letters of your first name. You should declare an identifier of mode `CHAR` for each letter, and write a `print` phrase for each letter. Remember to put semicolons in the right places. Add comments to your program to explain what the program does. Ans /DD>