| AGM 2022, Final Round, Day 2 |
|---|
| Finished |
Captain Nix is passionate about languages. Programming languages especially. Now there's this new cool programming language called AGM (A Great programming not Markup language) with the following rules:
A valid instruction is either of the following:
A <name> is defined as follows:
An Expression (<expression>) is defined recursively as follows:
An <unary_operator> is either of the characters in this set {+, -, $$$\sim$$$}. A binary operator is any of the characters in this set {+, -, *, /, %, **, ^, &, |}.
The list of operators in them of descending priority is:
The list of keywords: ['BEG', 'END', 'BN', 'BZ', 'GOTO', 'PRINT']
Please note that:
Captain Nix has some programs written in this amazing programming language and wonders what they do. Can you help out?
The input files will contain characters on at most $$$100$$$ lines, representing the source code. It is guaranteed that there will be at most $$$10^3$$$ characters in the input and there will be at most $$$10^4$$$ instructions executed.
Output the result of each print instruction on a separate line if there no error of any kind in the code (syntax or runtime error). Otherwise output a single line containing the text "error" with none of the potential output.
PRINT $_5a; GOTO BEG $b = 10 */- 7; END;
error
BEG; PRINT 100 ** 2 * (3 ^ 1); END;
20000
BEG; $a; $b; $c; $a := 0; $b := 1; start_loop; $c := $a + $b; BG ($c - 100) GOTO END; PRINT $c; $a := $b; $b := $c; GOTO start_loop; END;
1 2 3 5 8 13 21 34 55 89
The first example outputs fibonacci terms less than 100.
The second example outputs the result of $$$100^2 \times (3 \oplus 1)$$$.
The third example has multiple errors. Not starting with BEG, improper variable name, use of undeclared variables, jump to non-declared labels, use of the wrong assignment operator, wrong expression formatting, instruction not ending with ; .
| Name |
|---|


