Adele (algorithm description language)
Adele ( a lgorithm de scription l anguag e ) is an algorithm description language which is limited to essential language constructs. As a result, Adele is largely free of syntactic ballast and gives the user a lot of expression, which makes it easier to read the algorithms. Adele is a pseudocode language, but its modeling of algorithms is less abstract. The Adele syntax has influences from various programming languages, but is mainly based on Pascal and Modula-2 . Another algorithm description language, which is based on Java syntax , is Jana .
The algorithms written in Adele are not tied to a specific programming language, so that the algorithms only serve as a kind of template and the later implementation has to be in the desired programming language. Adele is particularly suitable for teaching purposes if, for example, a book author does not want to use a specific programming language to describe his algorithms.
Forest structure and writing convention
Functions
Functions have a name, a return type, and input and output parameters. Different parameters are separated by spaces.
example
Mein_Algorithmus(↓param1 ↓param2 ↑param3): Integer begin ANWEISUNG(EN) return param3 end Mein_Algorithmus
↓ stands for an input parameter (here: param1 and param2 ) and ↑ for output or return parameter (here: param3 ). In addition, transition parameters are marked with ↕.
It should be noted that the parameters are not typed in the signature, but in the function body by param .
Example:
Mein_Algorithmus(↓param1 ↓param2 ↑param3): Integer param param1: Integer; param2: Boolean; begin ANWEISUNG(EN) return param3 end Mein_Algorithmus
variables
The assignment of variables is very suggestive and identical to most programming languages. As a convention, it makes sense to start variables with a small letter.
The syntax is:
Variable := Ausdruck
Example:
meine_variable := 5;
Procedure / function calls
The function is called like an ordinary statement. Any transfer parameters required are marked with a ↑ (several parameters are separated by spaces). In order to better distinguish variables from functions, it makes sense to capitalize the first letter.
Syntax:
Funktionsname(↑parameter_1 ↑parameter_2... ↑parameter_n)
Example:
Meine_Funktion(↑param1)
Statement blocks
As a rule, statement blocks are terminated with an end (Modula 2 convention). Only repeat ... until do not need an end.
conditions
- Syntax of if-conditions:
if AUSDRUCK then ANWEISUNG(EN) {elsif AUSDRUCK then ANWEISUNG(EN)} [else ANWEISUNG(EN)] end
- Syntax of case conditions:
case AUSDRUCK of | Marke: ANWEISUNG(EN) | Marke: ANWEISUNG(EN) ... [else ANWEISUNG(EN)] end
Loops and broken loops
- While loop syntax:
while AUSDRUCK do ANWEISUNG(EN) end
- Syntax of repeat loops:
repeat ANWEISUNG(EN) until AUSDRUCK
- Syntax of for loops:
for VARIABLE := AUSDRUCK to AUSDRUCK [by AUSDRUCK] to ANWEISUNG(EN) end
VARIABLE is undefined after the loop pass.
- Loop syntax:
loop ANWEISUNG(EN) exit end
- Leave an inner loop statement with
exit
Cancellation and return values of procedures / functions
- Leave a function with
return
- Exit a function with a return value
return AUSDRUCK
- End an algorithm without returning to the higher-level algorithm
halt
Input and output
- Read a media at position x or the end of the file
Read(↑x ↑eof)
- Write x on a medium
Write(↓x)
- Line break on the output medium
WriteLn
Expressions
Expressions consist of the operations common in other programming languages (+, -, |, & etc.) and combinations of operands and operations. The short-circuit evaluation is used for Boolean expressions .
Declarations
Variables and constants can be declared in Adele between the function header and the beginning :
Syntax for variables:
Variable: Typ
Syntax for constants:
Konstante = Wert
Example:
Meine_Funktion(↓param1 ↓param2 ↑param3): Integer variable1: Integer; variable2: Boolean; konstante1 = 10; konstante2 = 3; ... begin ANWEISUNG(EN) return param3 end Meine_Funktion
Data types
The data types common in Pascal and Modula-2 are made available:
- Integer
- real
- Boolean
- Char
- Enumeration types , for example (north, south, west, east)
- Array [Index: Index] of Type - The specification of a limit is not mandatory. It is also sufficient to write Array of Type
- Record a: type, b: type; ... end
Modifier
- static
Variables can be declared as static, so that their value is not discarded after the end of the function and is available again the next time the function is called.
static variable: Typ
- static with pre-initialization by init
static variable: Typ init(false)
param The type assignment does not take place in Adele in signature. With param, types can be assigned to function parameters. param can be applied to several variables one after the other.
param parameter: Typ;
See example under functions
- local
With local, local variables such as B. Loop variables are declared. local can be applied to several variables one after the other.
local variable: Typ;
- global
Global variables can be declared (also from within a function). global can be applied to several variables one after the other.
global variable: Typ;
Comments
Adele uses the Ada spelling for comments . Comments are introduced by a double minus and go to the end of the line. Multi-line comments are not possible:
Example:
-- Dies ist ein Kommentar
Standard functions
No specific functions of a specific programming language should be used in Adele, because Adele should be kept as general as possible. It therefore makes sense to only use functions whose purpose is evident from the function name or to use corresponding instructions instead of a function.
Examples:
statt INC(i): i:=i+1 statt ODD(i): i mod 2 = 1
However, the following are permitted:
- Ord (↓ ch)
Returns the ordinal value of a character.
- Chr (↓ x)
Returns the character for the ordinal value x.
Classes, objects, modules and other constructs
There are no rules for any of the other constructs. However, it is recommended to use the Pascal language notation.
Literature and Sources
- Rechenberg and Pomberger: Computer science manual. Carl-Hanser-Verlag, Munich / Vienna 2002. 1189 pp. ISBN 3-446-21842-4