3D
3D is a 3 dimensional esoteric programming language inspired by Befunge. It was created by User:Stop h time on 25 March 2008 and finished 31 March 2008. It has been superseded by Suzy, which could have been called 3D 5.0, because it is the fifth iteration of the 3D idea.
Commands
- LEFT, start moving to the left
- RIGHT, start moving to the right
- UP, start moving up
- DOWN, start moving down
- NEXT, start moving forewards through the 3rd dimension
- PREV, start moving backwards through the 3rd dimension
- JUMP, jump over an instruction
- DBLJMP, jump over 2 instructions
- INT, this one has 3 different usages: set integer variable, use integer variable, convert a string to an integer (next command must be an integer, INT, a string or STR, the first two for the first usages, the latter two for the third one)
- STR, 2 different usages: set a string variable, or use a string variable (next command must be an integer or INT to let the interprenter know which string)
- IFEQU, Jump if INT0 != INT1
- STREQU, Jump if STR0 != STR1
- IFLAR, Jump if INT0 <= INT1
- IFRND, jump random (50% chance of JUMP)
- RNDDIR, random direction (including back!)
- END, end program
- SWAP, swap 2 variables (example: SWAP INT 3 4, to swap INT3 and INT4 or: SWAP INT INT 0 1, to swap the integer no INT0 and INT1)
- YNPRMT, prompt Yes/No (label text: STR0) (if user chooses No, JUMP)
- SPRMT, prompt string (label text: STR0, default value/store var: STR1)
- OUTPUT, output variable (example: OUTPUT STR 1 or: OUTPUT INT 1)
- ADD, add something to an int (example: ADD 2 INT 3 would translate as INT2 += INT3, ADD 1 3 would be INT1 += 3). Useful as logical OR.
- SUB, subtract something from the previous defined int, usage similar to ADD. Useful as logical XOR.
- MUL, multiply, see above. Useful as logical AND.
- DIV, integer division, usage: see above.
- NOT, Usage: NOT 3. If INT3 would be 0, it is changed to 1, else it is changed to 0.
- empty: do nothing
- "abc, string constant
- 123, integer constant
Implementation
User:Stop h time has written an interpreter and two simple editors in Python. (The interpreter script is to be found at [1])
Turing-complete
The author believes 3D is Turing-complete, but isn't quite sure. He thinks the following program may prove it:
RIGHT ADD 0 1 INT DOWN UP 16 0 INT LEFT
It's an infinite loop, every time adding 1 to INT0, and setting INT(INT0) to 16. So this would set INT1 to 16, INT2 to 16, INT3 to 16, until infinity.
Examples
The following examples are all valid 3D programs (laid out on 2 dimensions, due to technical limitations):
OUTPUT "Hello world END prints "Hello World" on screen
DOWN The program used by the author for testing his interpreter. INT It writes the numbers 1-10 on screen and exits. 0 (Note the suspended addition) 10 RIGHT ADD 1 IFLAR DOWN END UP 1 INT OUTPUT 1 LEFT
3D is especially fit for creating 'marble-machines':
OUTPUT IFRND DOWN DOWN DOWN LEFT IFRND IFRND RIGHT IFRND DOWN DOWN RIGHT DOWN 0 1 2 4 5 6 7 END END END END END END END