Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.
/ APP-lang Public archive

One-symbol esoteric programming language interpreter

Notifications You must be signed in to change notification settings

Hitonoriol/APP-lang

Repository files navigation

APP-lang

One-symbol esoteric programming language interpreter

Command line args

Execute APP source file:

app <filename>

Interactive mode:

app

Memory structure

APP lang memory consists of 2 layers of cells numbered from 0 to whatever number of cells can be allocated until you run out of memory.

Layers are labeled as: 0 - number cells and 1 - String cells

You can switch between layers by switching MODE: either by using operator S which flips MODE's current value (if it's 0 then make it 1 and back by the same logic) or by using setters: [mode_num] for MODE 0 and [mode_str] for MODE 1. Most operators that take arguments and return values do different things depending on the current MODE.

Even though memory cells are numbered starting from 0, there are cells reserved for certain operators (often referred to as DATA* where * is cell's number):

Cell number Description
0 First argument cell.

For example, operator + in MODE 1 will take values from this cell and DATA1, add them and put the result to current cell

1 Second argument cell.
2 Logical cell.

Any logical operation (?, g, s) will put it's result to this cell. Then, the conditional execution operator !...; will execute operators between ! and ; if this cell's value is 1, otherwise this block will be skipped.

3 Cycle counter.

Cycle operator {...} will execute operators between { and } with each iteration decrementing this cell by 1 until it reaches 0.

4 Memory jump pointer.

Points to the number of cell to which the jump should be made by j operator. By default this cell's value is it's own number (4) so you can change it and make jump to the cell you need: jxj - will jump to this cell, make its value greater by 10 and jump to newly set cell number. You can then return to cell you jumped from using operator R.

5 Floating point precision.

Output operator w sets floating point precision based on this cell. Default value is 3.

6 Copy pointer.

Must be set to the number of cell you wish to copy current cell's value to. Then you can call copy operator C and the value will be copied to the specified cell.

7 Output buffer.

Everything you print out with w operator gets appended to this String cell. Then, to print its contents to the screen you need to use W operator.

Operators:

Operator Description
a Set current int cell to 0 if MODE is 0 // if MODE is 1, clear current string cell
p Increment current cell
m Decrement current cell
w Write current number cell value with float-point precision from DATA5 cell (3 digits by default) to buffer cell (DATA7) if current mode is 0 // write current string cell value to buffer cell if mode is 1
W Print buffer cell value on the screen, then clear it
P Clear the buffer cell
_ Console line break
> Next cell
< Previous cell
. Put a character with code from current int cell to current string cell
v Add 5 to current cell
x Add 10 to current cell
i If MODE is 0, get int from keyboard to number cell // if MODE is 1, get string from keyboard.
+ if MODE is 0, set value of current cell to cell[DATA0] + cell[DATA1], // if MODE is 1, join DATA0 and DATA1 strings and put result to current string cell
- Set value of current cell to cell[DATA0] - cell[DATA1]
? If cell[DATA0] == cell[DATA1], set cell[DATA2] to 1, otherwise, to 0. Works with int cells as well as with strings.
g If cell[DATA0] > cell[DATA1], set cell[DATA2] to 1, otherwise, to 0.
s If cell[DATA0] < cell[DATA1], set cell[DATA2] to 1, otherwise, to 0.
r Set current cell value to random int in range min = cell[DATA0] & max = cell[DATA1]
{...} Repeat operators between "{" and "}" cell[DATA3] times
!...; Execute operators between "!" and ";" if cell[DATA2] == 1
c Put current cell number to current int cell
S Switch MODE between 0 (numbers) and 1 (string)
/ Make cell[current] = cell[DATA0] / cell[DATA1]
* Make cell[current] = cell[DATA0] * cell[DATA1]
j Jump to memory cell which number is stored in DATA4 cell. Default DATA4 value is its own position, so to set cell number to jump you have to do something like that: "jxjR" - this code will make APP jump to 10th memory cell and then back to DATA4
R Return from cell jump (works only after "j")
C Copy current cell number to cell with number from DATA6. Works with string cells as well as with int
@ Logically flip current cell (if its value is 1, set it to 0, otherwise set it to 1)
P Put current string cell to a file with name from DATA0 string cell
l Load string to current string cell from file with name from DATA0 string cell
& Append current number cell value to current string cell if mode is 0, // if mode is 1, convert current string cell value to current number cell
A Put substring from string DATA0 with start DATA0 and length DATA1 to destination string cell
b Put current string cell length to current number cell
q Put the position of the first occurance of substring DATA1 in string DATA0 to destination cell
Q Erase substring DATA1 from string DATA0 and put the result to destination string cell
e Execute APP code from String[Int[DATA0]]
D Set current cell as destination
0 Set current cell as DATA0
1 Set current cell as DATA1
2 Set current cell as DATA2
3 Set current cell as DATA3
z Push current cell's value to stack (two different stacks for int and string cells | mode0 -> int; mode1 -> string)
Z Pop the top value from stack to current cell (mode0 -> int; mode1 -> string)
E Put length of stack to current cell (mode0 -> length of int stack; mode1 -> length of string stack)
"..." Set current String cell to the string value specified between quotation marks.
[mode_num] Set MODE to 0.
[mode_str] Set MODE to 1.
[*8=var_name] Create alias 'var_name' for data cell #8.
[$var_name=%ppwW] Run specified code with origin point in cell with alias var_name
[$var_name=123] Set value of var_name to 123
[>var_name] Set cell with alias 'var_name' as current
[$5=10] Set 5th Int cell's value to 10
[$5=$10] Set 5th Int cell's value to 10th cell value
[$5=#10] Temporarily set current cell to 5th and execute APP code from 10th string cell
[$5=%ppwW] Run operators in 5th cell
[$c=10] / [$c=$10] / [$c=%app] / [$10=$c] c -- current cell
[e] Skip next goto
[:label] Declare a label (any name except ([,],/,\,") )
[#label] Go to label. Don't write ":" here. Just don't.
[ret] Return to last goto
[!12345] Sets current cell to a value
[>5] Jumps to a memory cell