Apparently a very very low level programming language I made lolz

# Define some basic functions

def sudoprint(text):
    print(text)

def sudoinput(prompt):
    return input(prompt)

# Implementation of if statements

def sudoif(expressions, true_statements, false_statements):
    if expressions:
        for statement in true_statements:
            exec(statement)
    else:
        for statement in false_statements:
            exec(statement)

# Implementation of a mini calculator that can evaluate basic arithmetic expressions

def evaluate(expression):
    return eval(expression)

# Start interpreter loop

while True:
    # Get input from user
    user_input = sudoinput(">>> ")

    # Evaluate input
    if user_input == "quit":
        break
    elif user_input.startswith("sudoprint(") and user_input.endswith(")"):
        expression = user_input[10:-1]
        sudoprint(expression)
    elif user_input.startswith("sudoinput(") and user_input.endswith(")"):
        prompt = user_input[10:-1]
        result = sudoinput(prompt)
        sudoprint(result)
    elif user_input.startswith("sudoif(") and user_input.endswith(")"):
        # Splitting the string to separate the three different arguments
        arguments = user_input[7:-1].split(",", 3)
        expressions = eval(arguments[0])
        true_statements = arguments[1].split(";")
        false_statements = arguments[2].split(";")

        sudoif(expressions, true_statements, false_statements)
    elif user_input.startswith("evaluate(") and user_input.endswith(")"):
        expression = user_input[9:-1]
        result = evaluate(expression)
        sudoprint(result)

What do you think?

2 Likes
sudoprint = lambda text: print(text)

or I think you can just do

sudoprint = print

I don’t really understand your “language” ngl

1 Like

That seems… Dangerous.
Maybe filter it somehow? ( 0-9, -+%/*, and () )

2 Likes

Please do not use eval and definitively like this. It is the worst security risk you could have in a python code, not a new language

4 Likes

What do you mean by low level? Do you mean took not very much skill, or low level as in manual memory management and other things often associated with low level languages like C and Rust

1 Like

Nah i just quickly made the so called programming language
its not my idea, its @DefendyPug 's idea.

This wasn’t what my idea was.

Hey quick question, if someone runs f = open("main.py", "a") in the eval and the user file writes new code in to the main.py file. Does the file only change temporarily for that specific user or does it change the file for ANYONE who runs the program, including the owner of the repl.

Just for that user, as it temp forks the repl, and all changes are eventually deleted.

1 Like

so wouldn’t the malicous changes be reverted? Im trying to find ways to abuse the eval() but i can’t think of any. i know its not harmless but…it shouldn’t be that bad right?

Well I just tested it, and it turns out you can use exec() within eval().

Here’s an example, which just crashes the program, nothing too harmful, yet.

eval("exec('import sys; sys.exit()')")

Edit: Nevermind you don’t even need exec(), you can run functions natively with just eval() itself, but I think there is some limitations if you don’t use exec(), importing modules doesn’t seem to work, or I’m not doing it right

It’s a right way to make interpler programming language

yes the right way is instead of making a language splitting a string a couple times and then using eval to have an actual language interpret for you

1 Like

Yes. But language will be faster if for each line you will write to compile.c code lines and then run it with os.system. But a bit overloaded

these kinds of basically fake langs are much slower because they run the language they are running in and have to repeatedly invoke eval or os.system

1 Like

Actually if you want to design a language, you should learn LISP and use a LISP dialect for it. It is excellent.

No, bcs:

  • LISP is an old and a bit difficult language. The best choice is a C or C++.
  • Use Racket instead LISP

It is still LISP. There is a reason why true programmers understand that all programming langiages converge to LISP.
It is difficult but it is better suited for that.

About Racket … it shares a lot with LISP. It is not considered a LISP dialect, but it is almost one.

what about ALGOL, or any of its family members.

Algol, like offsprings like Pascal, is where it belongs. The programming cemetery.