Generated code, language by language
What each AlgoML instruction becomes in C, Java and Python.
This page shows how the generator translates each part of the language. It helps to read the generated code and to move from AlgoML to a real language.
Types
| AlgoML | C | Java | Python |
|---|---|---|---|
INT | int | int | int |
REAL | double | double | float |
STRING | char[] | String | str |
BOOLEAN | bool | boolean | bool |
ARRAY[5] of INT | int t[5] | int[] t = new int[5] | list |
Instructions
| AlgoML | C | Java | Python |
|---|---|---|---|
x <- 5 | x = 5; | x = 5; | x = 5 |
read(n) | scanf("%d", &n); | n = scanner.nextInt(); | n = int(input()) |
write("n = ", n) | printf("n = %d", n); | System.out.print("n = " + n); | print("n = ", n, sep="", end="") |
if c then ... end if | if (c) { ... } | if (c) { ... } | if c: |
for i in 1 to n do | for (i = 1; i <= n; i += 1) | for (i = 1; i <= n; i += 1) | for i in range(1, n + 1): |
tab[i] | tab[i - 1] | tab[i - 1] | tab[i - 1] |
while c do | while (c) | while (c) | while c: |
repeat ... until c | do { ... } while (!(c)); | do { ... } while (!(c)); | while True: and break |
Operators
| AlgoML | C | Java | Python |
|---|---|---|---|
<> | != | != | != |
a div b | a / b | a / b | a // b |
a mod b | a % b | a % b | a % b |
AND, OR, NOT | &&, ||, ! | &&, ||, ! | and, or, not |
Program layout
- C: global variables at the top, then the functions, then
main. - Java: one class named after the algorithm, with static fields and methods, and a
Scannerfor input. - Python: one function per AlgoML function, and a
main()function called at the end of the file.
Every example on this site shows the real generated code: switch the tabs to compare.