512

From Esolang
Jump to navigation Jump to search

512 is an esoteric programming language created by User:Stysan. Challenge was to try to create programming language in 512 bytes. Its syntax is inspired by Batch syntax. 512 scripts can be stored in any extension, but originally 512 files were stored in .512s.

How it works

There are 4 variables: 1, 2, a and m.
You can set value for 1 and 2 using their commands: 1 and 2. You can set value for a using command a (user will type value). You can set value for m using command m. It will set M command by adding A to B. Commands are separated by spaces. Syntax errors will lead to "Error". Other commands will be marked as comments (create comments with _ instead of spaces).

Commands

Commands table
Example Output Description
pHello World! Hello World! Outputs a value.
a No output Asks a question (makes line editable until enter pressed) and makes answer value of variable a.
153 No output Sets variable 1 value 53.
247 No output Sets variable 2 value 47.
m No output Sets variable m value of a+b.
p%1 53 Prints value of variable 1.
p%2 47 Prints value of variable 2.
p%m 100 Prints value of variable m.
p%a Example Prints value of variable a.

Interpreter

Original interpreter was written in Python 3.8.5.

p=input()
p=open(file=p,mode="r")
p=p.read()
p=p.split(" ")
a,b,m,q="","","",""

for i in p:
    try:
        if i[0]=="p":
            if i[1:]=="%1":print(a)
            elif i[1:]=="%2":print(b)
            elif i[1:]=="%m":print(m)
            elif i[1:]=="%a":print(q)
            else:print(i[1:])
        elif i[0]=="a":q=input()
        elif i[0]=="1":a=i[1:]
        elif i[0]=="2":b=i[1:]
        elif i[0]=="m":m=eval(f"{a}+{b}")
    except:
        input("Error")
        quit()

Examples

Hello World!

pHello World!

Mathes!

129385
223207
m
p%m

(Mathes works by editing source code)