AlgoML
FR

Program structure

The header, the declarations and the main block of an AlgoML file.

The frame

Algorithm Name
version '1.0'
language C
declarations
begin
instructions
end
end algorithm

The parts always come in this order:

PartRole
Algorithm NameThe name of the program. Use letters, digits and _, starting with a letter.
version '1.0'A version number of your choice, as text.
language CThe language to generate: C, JAVA or PYTHON.
DeclarationsConstants, variables, structures, functions and procedures.
begin ... endThe main block: the instructions run when the program starts.
end algorithmThe end of the file.

Declarations

Everything you use must be declared before begin: constants, variables, structures, functions and procedures.

Algorithm Gcd
version '1.0'
language C
function gcd(a : INT, b : INT) : INT
variable r : INT
begin
while b <> 0 do
r <- a mod b
a <- b
b <- r
end while
return a
end function
variable x : INT
variable y : INT
begin
read(x)
read(y)
write("gcd = ", gcd(x, y), "\n")
end
end algorithm
Input 48 36Output gcd = 12gcd.aml on GitHubTry itSoon

Here gcd is a function with its own local variable r, declared between its header and its own begin. x and y are global variables.

Comments

Write a comment with // until the end of the line, or between /* and */ over several lines.

// Greatest common divisor, Euclid's method
r <- a mod b /* remainder of the division */

Names

  • Names are case sensitive: total and Total are two different variables.
  • A name cannot be a keyword such as begin, if or end.
  • The checker refuses two declarations with the same name in the same block.

Report a problem with this page