Previous | Next | Table of Contents | Index | Program List | Copyright

2.5 System Structures: General Form of an Ada Program

To summarize what we have learned so far, the programs shown earlier all have the general form described in Figure 2.1:

One of the main functions of a computer is to perform arithmetic computations and display the results of computations. Such operations are specified by the sequence of executable statements that appear in the program body following the reserved word BEGIN. Each statement is translated by the Ada compiler into one or more machine-language instructions, which are copied to the object file and later executed. Declarations, on the other hand, describe to the compiler the meaning and purpose of each user-defined identifier. They result in the allocation of some memory space to hold the data values.

Figure 2.1
General Form of an Ada Program

WITH package1;
WITH package2;
 ...
WITH packageN;
PROCEDURE pname IS

  declarations (variables, constants, etc.)

BEGIN

  program statement;
  ...
  program statement;

END pname;

PROGRAM STYLE
Use of Blank Space

The consistent and careful use of blank spaces can significantly enhance the style of a program. A blank space is required between words in a program line (e.g., between PROCEDURE and Distance in Program 2.5). Because extra blanks between words and symbols are ignored by the compiler, you may insert them as desired to improve the style and appearance of a program.

Always leave a blank space after a comma and before and after operators such as *, -,and =.

Indent by two or more spaces all lines except for the first and last lines of the program and the line BEGIN.

Finally, use blank lines between sections of the program.

All of these measures are taken for the sole purpose of improving the style and hence the clarity of the program. They have no effect whatever on the meaning of the program as far as the computer is concerned; however, they make it easier for people to read and understand the program. Be careful not to insert blank spaces where they do not belong. For example, there cannot be a space between the characters : and = that comprise the assignment symbol :=. Also, you cannot put a blank in the middle of an identifier.


Previous | Next | Table of Contents | Index | Program List | Copyright

Copyright © 1996 by Addison-Wesley Publishing Company, Inc.