ZTOALC L
Jump to navigation
Jump to search
Control flow
A ZTOALC L program starts with a line containing a positive integer, followed by a number of lines containing instructions. There is an instruction pointer (IP), which is initially the number at the first line of the program. Until the IP becomes 1, the following is repeated: The instruction at line IP is executed (if this instruction exists), and consecutively IP is either divided by 2 if it is even, or it is multiplied by 3 and increased by 1 if it is odd.
Expressions
ZTOALC L has two types of values, namely integers (of unlimited size) and arrays (these arrays can contain both integers and other arrays). Now there are a few possible expressions:
input |
The expression input will read one character from the input, and evaluate to its ASCII value.
|
variable | Variables will evaluate to their value. |
number | Numbers will evaluate to their value, for example -29 will evaluate to -29.
|
[size] |
where size is some expression evaluating to a number. [size] will create a new array with size size .
|
array[index] |
where array is some expression evaluating to an array and index evaluates to some number. This will evaluate to the item at position index in the array array .
|
Instructions
The following instructions can be used:
print expr |
where expr is some expression evaluating to a number between 0 and 127. This will print the character corresponding to this ASCII value.
|
jump if expr |
where expr is some expression evaluating to a number. If this number is zero, nothing happens. If the number is however non-zero, then IP will be increased by 1, and it will not be divided by 2 or multiplied by 3 and increased by 1 after this.
|
lhs = rhs |
where lhs and rhs are both expressions. This will put the value of rhs into lhs . If lhs is a name that was not defined yet, this will also define a variable with this name.
|
lhs += rhs |
where lhs and rhs are both expressions evaluating to numbers. This will increase lhs by the value of rhs .
|
lhs -= rhs |
where lhs and rhs are both expressions evaluating to numbers. This will decrease lhs by the value of rhs .
|
Examples
Hello, world!
18 print 10 print 87 print 33 print 114 print 32 print 108 print 100 print 101 print 111 jump if 1 print 111 print 108 print 108 print 72
Truth-machine
6 jump if m m = n print n m -= 48 n = input