CellArg
Paradigm(s) | imperative |
---|---|
Designed by | TheFloatingPixel |
Appeared in | 2023 |
Memory system | Cell-based |
Dimensions | one-dimensional |
Computational class | Unknown |
Reference implementation | [1] |
Influenced by | brainfuck |
File extension(s) | .ca |
CellArg is a language created by User:TheFloatingPixel in 2023. The name 'CellArg' comes from how it handles instruction parameters - before execution, the arguments are replaced with the values of the respective cells.
Overview
CellArg (similarly to brainfuck) uses a cell-based memory system. The initial value of all cells is 0, except for cell #1, the value of which is initially 1. CellArg programs consist of a list of instructions; anything that isn't a valid instruction is ignored. The instructions are extracted from the string using the regex [\+\-;#$]( ?[0-9])+
. Before execution, the parameters of the instruction are replaced with the values of the respective cells.
This means that if the memory was in the following state
Cell #0 | Cell #1 | Cell #2 |
2 | 1 | 0 |
the instruction + 0 1
would result in the instruction + 2 1
, thus adding 1 to the cell #2. In this situation, to add 1 to the cell #0, we would have to use the instruction + 2 1
.
There are 5 available instructions (all instructions are described as after the replacement):
Instruction | Description |
---|---|
+ (cell1) (cell2)
|
Add the value of cell number (cell2) to the value of cell number (cell1) |
- (cell1) (cell2)
|
Subtract the value of cell number (cell2) from the value of cell number (cell1) |
# (cell1)
|
Print the value of cell number (cell1) converted to a Unicode character to the standard output |
$ (cell1)
|
Ask for one-character long input from the user, and save it to the value of the cell number (cell1) |
; (cell1) (cell2)
|
Jump to instruction with the number of the value of the cell number (cell1), if the value of the cell number (cell2) is different than 0. |
Examples
Hello World (with explanations)
Make the value of cell number 0 = 10 to access cell number 10 + 2 1 add 1 to cell 0 + 2 1 add 1 to cell 0 + 2 2 add cell 0 to itself, multiplying it by two + 2 1 add 1 to cell 0 + 2 2 add cell 0 to itself, multiplying it by two By the end of this part, the value of cell 0 is 10. + 0 5 Add 10 to cell number 10. This is possible, because we just made the value of cell 0 = 10. Thanks to that, after the replacement the parameters of this instruction will be 10 and 0, adding the value of cell 0 to the cell number 10 - 5 0 Subtract the value of cell 0 from itself, effectively resetting it to 0 The following part is just a bunch of simple additions and subtractions, with a few prints sprinkled in. Print H + 5 10 + 5 10 + 5 10 + 5 10 + 5 10 + 5 10 + 5 10 add 70 to cell number 0 + 5 1 + 5 1 add 2 to cell number 0 # 5 print value of cell number 0 Print e + 5 10 + 5 10 + 5 10 add 30 to cell number 0 - 5 1 subtract 1 from cell number 0 # 5 print value of cell number 0 Print ll + 5 10 add 10 to cell number 0 - 5 1 - 5 1 - 5 1 subtract 3 from cell number 0 # 5 # 5 print value of cell number 0, twice Print o + 5 1 + 5 1 + 5 1 add 3 to cell number 0 # 5 print value of cell number 0 Print , - 5 5 reset cell 0 + 5 10 + 5 10 + 5 10 + 5 10 add 30 to cell number 0 + 5 1 + 5 1 + 5 1 + 5 1 add 4 to cell number 0 # 5 Print " " - 5 10 subtract 10 from cell number 0 - 5 1 - 5 1 subtract 2 from cell number 0 # 5 print value of cell number 0 Print W + 5 10 + 5 10 + 5 10 + 5 10 + 5 10 add 50 to cell 0 + 5 1 + 5 1 + 5 1 + 5 1 + 5 1 subtract 5 from cell number 0 # 5 print value of cell number 0 Print o + 5 10 + 5 10 add 20 to cell 0 + 5 1 + 5 1 + 5 1 + 5 1 add 4 to cell 0 # 5 print value of cell number 0 Print r + 5 1 + 5 1 + 5 1 add 3 to cell 0 # 5 print value of cell number 0 Print l - 5 10 subtract 10 from cell 0 + 5 1 + 5 1 + 5 1 + 5 1 add 4 to cell 0 # 5 print value of cell number 0 Print d - 5 10 subtract 10 from cell 0 + 5 1 + 5 1 add 2 to cell 0 # 5 print value of cell number 0 Print ! - 5 5 reset cell 0 + 5 10 + 5 10 + 5 10 add 30 to cell 0 + 5 1 + 5 1 + 5 1 subtract 3 from cell 0 # 5 print value of cell number 0
Hello World (without explanations)
+ 2 1+ 2 1+ 2 2+ 2 1+ 2 2+ 0 5+ 5 10+ 5 10+ 5 10+ 5 10+ 5 10+ 5 10+ 5 1+ 5 1# 5+ 5 10+ 5 10+ 5 10- 5 1# 5+ 5 10- 5 1- 5 1- 5 1# 5# 5+ 5 1+ 5 1+ 5 1# 5- 5 5+ 5 10+ 5 10+ 5 10+ 5 10+ 5 1+ 5 1+ 5 1+ 5 1# 5- 5 10- 5 1- 5 1# 5+ 5 10+ 5 10+ 5 10+ 5 10+ 5 10+ 5 1+ 5 1+ 5 1+ 5 1+ 5 1# 5+ 5 10+ 5 10+ 5 1+ 5 1+ 5 1+ 5 1# 5+ 5 1+ 5 1+ 5 1# 5- 5 10+ 5 1+ 5 1+ 5 1+ 5 1# 5- 5 10+ 5 1+ 5 1# 5- 5 5+ 5 10+ 5 10+ 5 10+ 5 1+ 5 1+ 5 1# 5
Truth machine
+ 5 1+ 5 1+ 5 5+ 5 1+ 5 5+ 0 5- 5 5+ 5 1+ 5 1+ 5 1+ 5 1+ 5 1+ 5 1+ 0 5+ 6 1- 5 5+ 5 10- 5 1- 5 1+ 0 5+ 8 1$ 5+ 6 5- 5 10- 5 10- 5 10- 5 10- 5 1- 5 1- 5 1- 5 1- 5 1- 5 1- 5 1- 5 1+ 8 10+ 8 10+ 8 10+ 8 10- 8 1# 6; 8 5
One Time Cat
$ 2# 2