Yuij

From Esolang
Jump to navigation Jump to search

Yuij is an esolang which uses few characters. + increases the amount of the current unit by 1. - decreases the amount of the current unit by 1. | prints everything after it till there is another |. Hello World:

|Hello World|

Implementation (made by AI, cuz i don't wanna learn how to make interpreters):

# This is a simple interpreter for a custom, text-based language.
# It reads a string of commands and executes them one by one.

def run_interpreter(program_string: str) -> None:
    """
    Interprets a string of commands for a custom language.

    The language supports the following commands:
    '+': Increases the current unit value by 1.
    '-': Decreases the current unit value by 1.
    '|...|': Prints the text between the two vertical bars.
    
    Args:
        program_string: A string containing the program to be interpreted.
    """
    
    # Initialize the "unit" variable.
    # This is the value that the '+' and '-' commands will manipulate.
    unit = 0
    
    # Use an index to iterate through the program string.
    # A while loop is used instead of a for loop so we can manually
    # advance the index when processing the '|...|' command.
    index = 0
    while index < len(program_string):
        command = program_string[index]

        if command == '+':
            # Increase the unit value by one.
            unit += 1
            print(f"Command: '+' -> Unit value is now {unit}")
        
        elif command == '-':
            # Decrease the unit value by one.
            unit -= 1
            print(f"Command: '-' -> Unit value is now {unit}")

        elif command == '|':
            # This is the start of a print command.
            # We need to find the matching closing '|'.
            try:
                # Find the index of the next '|' starting from the position after the current one.
                end_index = program_string.index('|', index + 1)
                
                # Extract the text between the two bars.
                text_to_print = program_string[index + 1:end_index]
                print(f"Command: '|...|' -> Output: '{text_to_print}'")
                
                # Move the index past the entire print block to avoid processing
                # the characters inside the bars and the closing bar itself.
                index = end_index
            except ValueError:
                # Handle the case where a closing '|' is not found.
                print("Error: Missing closing '|' for print command.")
                break # Stop execution on an error.
        
        else:
            # If the character is not a recognized command, skip it.
            print(f"Warning: Unrecognized command '{command}'")

        # Move to the next character in the program string.
        index += 1
    
    print("-" * 30)
    print(f"Program finished. Final unit value is: {unit}")