Skip to content

SpecificationVIII · Programs and modules

8.1

Structure of a program

A program is a text with a single algorithm and, around it, the pieces that algorithm uses: subprograms, classes, records, enumerations and constants.

Markdown version

8.1.1 How it works

The top level of the text only accepts units: named blocks that open and close. No executable statement may be left loose outside them.

Figure 8.1-1.A file with its single algorithm and its sibling units. None goes inside another, and order does not matter.

A file with four sibling units one under the other: the constant SALUDO, the enumeration Color, the algorithm Tienda, highlighted as the only one, and the subroutine Precio.

UnitHow many
Algorithmexactly one
Subroutine, Functionas many as needed
Class, Interfaceas many as needed
Record, Enumeration, Variantas many as needed
Constantas many as needed

Units are siblings: none goes inside another. They can be written before or after the algorithm, in any order.

ProgramAn algorithm with its neighbours

Constant SALUDO As String <- "Hola";

Enum Color
  Rojo, Verde
EndEnum

Algorithm Tienda
  Write SALUDO, " ", Precio(3);
EndAlgorithm

Subroutine Precio(unidades As Integer) As Integer
  Return unidades * 5;
EndSubroutine

Output

Hola 15

The program finishes normally.

An empty algorithm is valid and does nothing. The algorithm's name does not take up the variable namespace: it may match the name of a variable.

8.1.2 Classic pseudocode

A program written in the classic style —Algorithm, Define with several names, Read, Write, If, Switch, loops, Dimension and Function with a result variable— is analysed without any diagnostic and runs as is, also from the terminal with pseudo ejecutar. The only requirements are the usual ones: semicolons, indices from zero and no variable read without a value.

In short

  • A text has exactly one algorithm.
  • Sibling units go around it, in any order.
  • There are no loose statements or nested units.
  • Classic pseudocode works without touch-ups.