<program> | ::= | <decl><body> |
<decl> | ::= | VAR_SET (ENTER) ( (id) = (num) ) + |
<body> | ::= | PROGRAM (ENTER) <labelled command>+ |
<labelled command> | ::= | (id): <command> | <command> |
<command> | ::= | INC (id) | DEC (id) | MOV (id) (id) | BRANCH (id) (id) | INPUT (id) | OUTPUT (id) | ADD (id) (id) | ALLOC (id) (id) | STOREI (id) | LOADI (id) | STOP |
* Strings after # symbols are regareded as comments
* An identifier (id) is a string starting from [a-zA-Z]
* (num) is a decimal number or a ternary number with 20 trits followed by t (Example: 00000000111111112222t).
Overview
------------------------------ Declaration of variables Declaration of program body ------------------------------
A variable (id) is initialized to (num)
Semantics of command is given in the following table, where X and Y are variables, L is a label, and IP is the program counter.
command | semantics | note |
INC X | X++, IP++ | Increment of X |
DEC X | X--, IP++ | Decrement of X |
MOV X Y | Y:=X, IP++ | Copy |
BRANCH X L | if X=0 then IP:=L else IP++ | Zero branch |
INPUT X | X:=input(), IP++ | Input |
OUTPUT X | output(X), IP++ | Output |
ADD X Y | Y:=X+Y, IP++ | Addition |
STOP | halt | Halt |
ALLOC X Y | X:=VAR_ALLOC, VAR_ALLOC:=VAR_ALLOC+Y, IP++ | Allocation |
STOREI X | [INDEX]:=X, IP++ | Store |
LOADI X | X:=[INDEX], IP++ | Load |