The environment that a NoComment program has access to consists of:
- Like in brainfuck: A static, flat memory space divided into bytes, initialized to all zeros, and a moveable pointer, initially at the 0th cell.
- A stack consisting of byte-sized items.
Some terminology to shorten some explanations.
|"Pointer"||Either the memory pointer itself or its position.|
|"Value of the pointer"||The value of the memory cell at the pointer.|
The extension of a source file does not matter but it is preferred that .noc is used. It is not possible (and it will not ever be possible) to import or include code from other source files.
In total, there are 10 commands. Each command is exactly one character, case sensitive ('a' is different from 'A'). Commands may not take any arguments. After a command has been executed, program execution begins at the next character in the source code (in the reference implementation, the "instruction pointer" is simply incremented).
|i||Increment the value of the pointer|
|d||Decrement the value of the pointer|
|c||Clears the value of the pointer (resets to 0)|
|l||Decrements the pointer (left)|
|r||Increments the pointer (right)|
|n||Push the value of the pointer to the stack; the original memory cell is not affected. (on)|
|f||Pop a value from the stack and overwrite the value of the pointer with it. (off)|
|s||If the value of the pointer is non-zero, peek (do not pop) a value from the stack (let's call it x) and jump x spaces forward in the source code. In reality, you are jumping x + 1 spaces because the program always moves one command forward after a command has executed. Therefore, think of x as the number of instructions you are skipping.|
|b||This is the same as above, but for backwards jumps. Be warned: the math works out slightly differently; in order to jump one space backwards you actually need to jump 2 spaces (-2 + 1 = -1).|
|o||Output the value of the pointer as ASCII (e.g. 65 = 'A', 32 = ' ').|
NoComment does not really have a syntax. As you may have guessed from the name of the language, NoComment does not allow comments (which is defined to be any character not in the set of commands listed above). Comment characters will throw an error and terminate the program. This means that every single character in a valid NoComment program must be a command; not even spaces or newlines are allowed. Therefore, all valid NoComment programs are one-liners.
- Stack underflow
- Stack overflow, when the stack is static (as in the reference implementation)
- Unrecognized command in source code
(Pointer overflow and underflow are completely legal and should not crash the program (the pointer will simply move to the opposite end of memory and execution will continue as normal); this is the reason why the memory space needs to be static.)
(Implementation note: The only requirement for errors is that they terminate the program and indicate that an error occured; they do not have to display the specific error that caused the termination.)
Copy the value of the pointer to the cell immediately to the right.
Values can be copied any number of spaces by replacing the r below with as many l or r commands as needed. e.g. to move a value two spaces to the left:
Add two cells
If the pointer's position is n, add the cells at n and n + 1 and store the result in n, clearing the cell at n + 1. (Note: Using this method to add something to zero will result in the correct answer but will be extremely slow, as there is no check for this particular situation before the add-loop. Essentially, 256 will be added to the first byte and subtracted from the second, which are both equivalent to doing nothing due to integer overflow.)
Subtract two cells
This is the exact same as the add operation, except that it does subtraction, not addition.
To come: Multiplication, division
Reference NoComment interpreter in Python at the official GitHub: https://github.com/captainFoxtrot/noComment