-
Notifications
You must be signed in to change notification settings - Fork 1
Commands, Control Flow, and Syntax
quietsamurai98 edited this page Sep 16, 2017
·
5 revisions
- Pointers must be explicitly declared by writing the pointer's name (outside a CFB head), followed by a whitespace.
- Pointer names must contain at least one letter, and may contain alphanumeric characters or underscores only.
- Pointers are initialized to position [0][0][0] in the Memory Cube.
- Pointer scope is limited to the CFB body it was declared in, and all CFBs within said body.
- If the pointer is declared outside of a CFB body, it has global scope.
- Pointer Movement Commands
-
>
: Move from [S][T][C] to [S][T][C+1] -
<
: Move from [S][T][C] to [S][T][C-1] -
^
: Move from [S][T][C] to [S][T+1][C] -
v
: Move from [S][T][C] to [S][T-1][C] -
X
: Move from [S][T][C] to [S+1][T][C] -
O
: Move from [S][T][C] to [S-1][T][C]
-
- Data Modification Commands
-
+
: Increment the value of the target cell by 1, overflow if needed. -
-
: Decrement the value of the target cell by 1, underflow if needed.
-
- Console IO Commands
- Output commands
-
.
: Output the value of the target cell as a character with an ASCII code of cell value mod 256, not followed by a newline -
'
: Output the value of the target cell in binary, followed by a newline -
:
: Output the value of the target cell as a base10 number followed by a newline
-
- Input commands
-
,
: Get a byte of data from the console as an ASCII character without requiring a newline, and set the target cell's value to the ASCII value mod 2S -
"
: Get data from the console as a binary number, requiring a newline, and set the target cell's value to the binary value mod 2S -
;
: Get data from the console as a base10 number, requiring a newline, and set the target cell's value to the base10 value mod 2S
-
- Output commands
- To instruct a pointer to execute a command or series of commands, write the name of the pointer followed by a pair of parentheses containing zero or more commands.
- You cannot have any whitespace between the pointer and the opening parenthesis! The interpreter will think you're telling it to declare a pointer, then execute a list of commands without specifying what pointer to use.
- The parentheses are called command parentheses, and the command parentheses combined with the commands inside are collectively called command blocks, or CBs.
- CBs may not appear within CFB heads, and may only contain pointer commands.
- Example:
my_ptr(+>+>+<<)
will increment the cells [S][T][C], [S][T][C+1], and [S][T][C+2] by one, and then returnmy_ptr
to its original position at [S][T][C].
- There are two system commands that are used to communicate with the interpreter directly, rather than to manipulate pointers.
- System commands must appear outside CBs and CFB heads.
- The two system commands are:
!
: Stop program execution
?
: Perform garbage collection
-
Control flow blocks have two components, called the head and body.
- The head is a pair of parentheses containing the name of a pointer, and is responsible for controlling the execution of the body's contents.
- The body is a pair of brackets, and the code contained within said brackets. The type of body brackets determines the type of CFB.
-
If statements
- Format:
(head){body}
- Example:
(myptr){myptr(-)}
will decrement the value ofmyptr
's target cell ifmyptr
's target cell is not equal to zero.
- Format:
-
While loops
- Format:
(head)[body]
- Example:
(myptr)[myptr(-)]
will decrement the value ofmyptr
's target cell whilemyptr
's target cell is not equal to zero.
- Format:
-
Repeat Loops
- Format:
(head)(body)
or(number)(body)
- Example:
(ptr_a)(ptr_b(+))
will increment the value ofptr_b
's target cell n times, where n is the initial value ofptr_a
's target cell. - Notes:
- The number of times the body is executed is set before executing the body.
Therefore,(myptr)(myptr(+))
would double the value ofmyptr
's target cell, rather than cause an infinite loop. - The head can be a pointer, or a hard coded number.
Therefore,(10)(myptr(+))
would add 10 tomyptr
's target cell.
- The number of times the body is executed is set before executing the body.
- Format:
- All comments are block comments, and must start with
/*
and end with*/
. - Comments may contain any text except for the substrings
/*
or*/
.