LIMITED
LIMITED is an esolang by User:DadoDev which aims to have the one of the smallest possible instruction sets.
Syntax
Commands
LIMITED uses the following 4 commands.
Cmd | Description | Notes |
---|---|---|
SET x y
|
Sets the variable x to the value y
|
Declares x if it doesn't exist
|
ADD x y
|
Stores the sum of x and y in the variable x
|
y can be a varaible or a float literal
|
INV x
|
Multiplies the variable x by -1, effectively inverting it
|
x must be a variable
|
CMP x y z w
|
Checks the boolean of x y z (e.g. 1 == 3) and jumps to line number w if true
|
The supported comparisons are: ==, <, >, <=, >=, !=
|
It is also important to note that every variable is an unbounded float.
I/O commands
There exist 3 more optional commands to allow for I/O.
These are not included in the main list, as they technically aren't necessary for turing completeness.
Cmd | Description | Notes |
---|---|---|
INP x
|
Reads input and stores it in the variable x
|
Reads a float. Also declares x if it doesn’t exist
|
OUT x
|
Outputs the variable x to the console
|
Outputs as an integer |
ASC x
|
Outputs the variable x to the console as an ASCII character
|
Does not output a newline after |
Arguments
Unless a certain argument in a command is specified to be a variable (e.g. the x
argument in SET
), it can be a float literal (just the number).
This means things like ADD test 5
, OUT 42
, ASC 65
, etc. are all valid commands.
Also, the SET
command can be used to set a variable to another, e.g. SET var1 var2
Example programs
Here are several example programs to demonstrate LIMITED's capabilities.
Multiply a positive float and integer
INP value SET startVal value INP count ADD value startVal ADD count -1 CMP count > 1 5 OUT value
Hello, World!
ASC 72 ASC 101 ASC 108 ASC 108 ASC 111 ASC 44 ASC 32 ASC 119 ASC 111 ASC 114 ASC 108 ASC 100 ASC 33
More understandable version
SET H 72 SET e 101 SET l 108 SET o 111 SET , 44 SET S 32 SET w 119 SET r 114 SET d 100 SET ! 33 ASC H ASC e ASC l ASC l ASC o ASC , ASC S ASC w ASC o ASC r ASC l ASC d ASC !
Truth-machine
INP value OUT value CMP value == 1 2
Computational class
LIMITED is Turing-complete, since the language is a varation of Counter machine
Subtracring y
from x
is equivelant to adding x
to inverted y
, or as LIMITED code:
INV y ADD x y
Two counters are needed to be Turing-complete.
Implementations
The official implementation in Python:
import operator def var_arg(variables, arg): return variables[arg] if arg in variables else float(arg) def interpret(code): code = code.splitlines() pc = 0 variables = {} ops = { "==": operator.eq, "!=": operator.ne, "<": operator.lt, "<=": operator.le, ">": operator.gt, ">=": operator.ge } while pc < len(code): line = code[pc] tokens = line.split() cmd = tokens[0] if len(tokens) > 0 else None arg1 = tokens[1] if len(tokens) > 1 else None arg2 = tokens[2] if len(tokens) > 2 else None arg3 = tokens[3] if len(tokens) > 3 else None match cmd: case "SET": variables[arg1] = var_arg(variables, arg2) case "ADD": if arg1 in variables: if arg2 in variables: variables[arg1] = variables[arg1] + variables[arg2] else: variables[arg1] = variables[arg1] + float(arg2) else: error_var = arg1 if not(arg1 in variables) else arg2 print(f"{error_var} is not a variable.") exit() case "INV": variables[arg1] = arg1 * -1 case "CMP": if arg2 in ops: check = ops[arg2](var_arg(variables, arg1), var_arg(variables, arg3)) if check: pc = int(tokens[4]) - 1 continue else: print(f"Unknown operator: {arg2}") exit() case "INP": if not(arg1 in variables): variables[arg1] = 0.00 variables[arg1] = float(input("input number: ")) case "OUT": if arg1 in variables: print(variables[arg1]) else: print(arg1) case "ASC": if arg1 in variables: print(chr(int(variables[arg1])), end="") else: print(chr(int(arg1)), end="") pc += 1
(If there are any bugs, feel free to fix them)