Versert

Versert is a Befunge-inspired esoteric programming language, devised by Kang Seonghoon.

History

Versert is started as the question what if Befunge doesn't have a stack. This idea was flew in my brain on July 10, 2005, and implemented on July 22, 2005.

Versert (correct romanization is beoseot, though) is a Korean word for mushroom, clearly showing the relation with fungi. I would thank to Han Dongseong for this name.

Language Specification

Environment

Versert is a two-dimensional programming language, like Befunge. Here two-dimensional language means the code is structured in the two-dimensional space, unlike C or Java which have a linear flow of execution.

All code is stored to infinite two-dimensional plane. Any point in the plane have a coordinate of the form (column, row), and each character in the code is stored in the cell which have an integer coordinate. One cell can contain one 8-bit unsigned integer (limited from 0 to 255). The origin (0, 0) corresponds to the leftmost character in the first line of the code.

Before the execution, the source code is read as ASCII text and stored in the plane. All other empty cells are assumed to contain space character, i.e. 32. Then there are no newline character (i.e. 10) in this space, and it has no effect that one stores newline character to the plane later.

Versert has no stack; Versert has the following variables internally.

Instruction Pointer: IP = (x, y)
IP points to the instruction currently executing. Initially IP is (0, 0).
Velocity: delta = (dx, dy)
delta represents the direction of IP. After the instruction pointed by IP is executed, delta is added to IP so IP points to next to-be-executed instruction. Initially delta is (1, 0) -- IP towards the east.
Data Pointer: DP = (px, py)
DP points to the target cell directly read or written by the instruction. Initially DP is (0, 0).
Registers: A, B
A and B are only variables the instruction can directly changes. Initially A and B are zero.

The code space is wrapped at the extreme like Befunge; if IP goes to the east, IP returns to original cell from the west, vice versa. This property is often called Lahey-space.

List of instructions

Below is a complete list of instructions. All other characters have no effect rather than silently adding delta to IP, like the space character.

Char. Meaning Description
0..9
A ← 0..9
Sets A to given number.
+
B ← B + A
Adds A to B.
-
B ← B - A
Subtracts A from B.
*
B ← B × A
Multiplies A to B.
~
A, B ← B, A
Swaps A and B.
`
if A > B then
A, B ← B, A
Swaps A and B if A is greater than B.
>
if A < B then
A, B ← B, A
Swaps A and B if A is less than B.
/
dx, dy ← -dy, -dx
If IP is heading right, turns up; if down, turns left; if left, turns down; if up, turns right.
\
dx, dy ← dy, dx
If IP is heading right, turns down; if down, turns right; if left, turns up; if up, turns left.
@
exit()
Terminates the program.
#
if B = 0 then
IP ← IP + delta
If B is zero, skips one instruction and executes next instruction.
.
putchar(A)
Prints lowermost 8 bits of A to standard output as ASCII character.
:
putint(A)
Prints A to standard output as integer.
,
A ← getchar()
Reads a character and stores its ASCII code to A. When EOF is encountered, A won't be changed.
;
A ← getint()
Reads an integer and stores it to A. When EOF is encountered, A won't be changed.
{
B ← space[px, py]
Gets an instruction pointed by DP, and stores its ASCII code to B.
|
px ← px + A
py ← py + B
Moves DP A cells right, B cells down.
}
space[px, py] ← B
Puts lowermost 8 bits of B to an instruction pointed by DP, as ASCII character.

Examples

This is a famous "Hello, world!" program. Yay, it's cheating ;)

\"Hello, world!" program.
\3+5*0~|}-2+0~|#/{~.00\
     @.~*5+2\#{|1~/

This is same program with no such trick.

6~6*}2*~.{+7-~.~7+~..~3+~.~{8+~.~{4-~.~4*9-~.~8-~.~3+~.~6-~.~8-~.~{3-~.~2~5*~.@

This program does same thing as UNIX's cat program.

#/#.0~1\ 
@\#+,~-/

This program is a quine. (Thanks to mtve)

# #/ 0|   0~4+8*0~|}-0~|#/{~.00\ 
" @\# -2+{|~0*8-4~0.~*5+2\#{|1~/

Download

I have written reference implementation in ISO C.

You may inspect my Mercurial repository for more resources.


(rev 1d46270eb038)