Triskaidekalogophilia

From Esolang
Jump to: navigation, search

Triskaidekalogophilia is an esolang with only 9 commands that only allow string manipulation. The commands can add, delete or change characters within a string. The name derives from the words describing the love of the number 13 and the love of words.

Syntax

<Variable

Prints the value stored in Variable.


>Variable;Prompt

Saves a user-inputted string in Variable with the prompt coming from the variable Prompt.


^Variable;Index

Increases the ASCII value of the character at Index in Variable by 1. 127 becomes 0.


*Variable

Removes the last character in Variable.


+Variable

Adds a character with an ASCII value of 0 to the end of Variable.


?Variable;Index;Result

Places the character in Variable at Index in Result.


=Variable1;Variable2

Executes the next command if the two variables are equal. If not, that line is skipped.


@LineNumber

Goes to the specified line.


#

Returns to the line after the last @ command. If there has already been a # command or no @ command the program returns to the beginning.


All numbers must be given in base-13 0-C, the case is irrelevant.

Examples

Cat program

+nil
*nil
>line;nil
<line
#

Interpreter

This is the code for the interpreter written in Python 3.3:

import time
Commands = {}
Variables = {}

def INPUT(String):
    String = String.split(';',1)
    if String[1] in Variables:
        Variables[String[0]] = input(Variables[String[1]])

def PRINT(String):
    if String in Variables:
        print(Variables[String])

def SHIFT(String):
    String = String.split(';',1)
    if String[0] in Variables:
        try:
            if not String[1] in Variables:
                Index = 0
            else:
                Index = int(Variables[String[1]],13)
            Variables[String[0]] = list(Variables[String[0]])
            Value = ord(Variables[String[0]][Index])
            Value = (Value+1)%128
            Variables[String[0]][Index] = chr(Value)
            Variables[String[0]] = .join(Variables[String[0]])
        except ValueError:
            pass

def DELCHAR(String):
    if not String in Variables:
        Variables[String] = 
    Variables[String] = Variables[String][:-1]

def ADDCHAR(String):
    if not String in Variables:
        Variables[String] = 
    Variables[String] = list(Variables[String])
    Variables[String].append(chr(0))
    Variables[String] = .join(Variables[String])

def GETCHAR(String):
    String = String.split(';',2)
    if String[0] in Variables and String[1] in Variables:
        try:
            Index = int(Variables[String[1]],13)
            Variables[String[2]] = Variables[String[0]][Index]
        except ValueError:
            pass

def EQUAL(String):
    global LineNumber
    String = String.split(';',1)
    if String[0] in Variables and String[1] in Variables:
        if Variables[String[0]] != Variables[String[1]]:
            LineNumber += 1

def GOTO(String):
    global LineNumber
    global LastJump
    LastJump = LineNumber
    LineNumber = int(Variables[String],13)

def RETURN(String):
    global LineNumber
    global LastJump
    LineNumber = LastJump
    LastJump = 0

Commands[">"] = INPUT
Commands["<"] = PRINT
Commands["^"] = SHIFT
Commands["*"] = DELCHAR
Commands["+"] = ADDCHAR
Commands["?"] = GETCHAR
Commands["="] = EQUAL
Commands["@"] = GOTO
Commands["#"] = RETURN

File = [Foo.replace('\n',) for Foo in open(input("File: ")).readlines()]
global LineNumber
global LastJump
LineNumber = 0
LastJump = 0
while LineNumber < len(File):
    Line = File[LineNumber]
    for Command in Commands:
        if Command == Line[0]:
            Function = Commands[Command]
            break
        else:
            Function = 'Comment'
    if Function != 'Comment':
        Function(Line[1:])
    LineNumber += 1

print('\n=== END ===')
time.sleep(5)