W-INTERCAL

From Esolang
Jump to navigation Jump to search

W-INTERCAL is a version of INTERCAL made by Kiwitrader (talk) 03:31, 13 August 2016 (UTC)

It is recommended that novice programmers learn this rather than INTERCAL.

Syntax:

if you definitely want the interpreter to do something, use PLEASE.

 PLEASE command

otherwise, use DO:

 DO COMMAND

will have a one in 2 chance of executing the command.

comments are issued by IGNORE:

 PLEASE IGNORE this text is not executed

variables are set bu using:

 PLEASE SET VAR NAME -> VALUE TYPE

for example, to set hello to "Hello world":

 PLEASE SET VAR HELLO -> "Hello world" STRING

the new and improved syntax of COME FROM IS:

 PLEASE COME FROM STARTLINE TO ENDLINE

or:

 PLEASE COME FROM LINE

and it will execute the lines specified.

to output a variable, use

 -->
 PLEASE --> NAME

there are five operators in W-INTERCAL:

 ADD NUM NUM2 NUM3 NAME

and it stores the sum in name.

also,

 SUB
 MUL
 DIV
 MOD

work the same way.

the five supported types are:

 INTEGER
 STRING
 FLOAT 
 ARRAY

to append to an array:

 PLEASE ADDTO ARRAYNAME VALUE

note that in W-INTERCAL, arrays start counting from 1.

 PLEASE INSERT NAME INDEX VALUE

the only way to store ints in an array is to create an variable:

 PLEASE SET VAR V -> 3 INTEGER
 PLEASE SET VAR L -> [] ARRAY
 PLEASE ADDTO L V

and the

 DELETE

keyword deletes an item from the list:

 PLEASE DELETE L 1

now

 L

is an empty list.

and finally, the abstain keyword is to abstain from doing something.

 ABSTAIN FROM ABSTAIN

I have a python 3 interpreter of it here:

from random import choice
with open('main.wint', 'r') as f:
    prog = f.readlines()
    keywords = ['PLEASE', 'DO', 'ABSTAIN']
    ablist = []
    progg = []
    var = {}
    for item in prog:
        progg.append(item.strip())
    prog = progg[:]
    x = []
    for line in prog:
        line = line.split()
        x.append(line)
    for ins in x:
        if ins[0] == keywords[0]:  # PLEASE
            if ins[1] in ablist:
                ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
            elif ins[1] == 'COME' and ins[2] == 'FROM':
                instr = x[int(ins[3]) - 1:int(ins[5])]
                for ins in instr:
                    if ins[1] in ablist:
                        ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                    elif ins[1] == 'SET':
                        if ins[4] == '->' and ins[2] == 'VAR':
                            if ins[4] == '->' and ins[2] == 'VAR':
                                if ins[6] == 'STRING':
                                    var[str(ins[3])] = str(ins[5])
                                elif ins[6] == 'INTEGER':
                                    var[str(ins[3])] = int(ins[5])
                                elif ins[6] == 'FLOAT':
                                    var[str(ins[3])] = float(ins[5])
                                elif ins[6] == 'ARRAY':
                                    var[str(ins[3])] = []
                        else:
                            print('INVALID SYNTAX')
                    elif ins[1] == '-->':
                        try:
                            print('"'+var[str(ins[2])]+'"', end=' ')
                        except:
                            print(var[str(ins[2])], end=' ')
                    elif ins[1] == 'NEWLINE':
                        print()
                    elif ins[1] == 'PRINT':
                        out = ""
                        for string in ins[2:]:
                            out = out + ' ' + string
                        print('"'+out[1:]+'"',end=' ')
                    elif ins[1] == 'GETINPUT':
                        inp = input()
                        var[str(ins[2])] = inp
                    elif ins[1] == 'ADD':
                        add = 0
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add += int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'SUB':
                        if ins[2] in var.keys():
                            ins[2] = int(var[ins[2]])
                        if ins[3] in var.keys():
                            ins[3] = int(var[ins[3]])
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add -= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'MUL':
                        add = 1
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add *= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'DIV':
                        if ins[2] in var.keys():
                            ins[2] = int(var[ins[2]])
                        if ins[3] in var.keys():
                            ins[3] = int(var[ins[3]])
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add /= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'MOD':
                        if ins[2] in var.keys():
                            ins[2] = int(var[str(ins[2])])
                        if ins[3] in var.keys():
                            ins[3] = int(var[str(ins[3])])
                        add = int(ins[2]) % int(ins[3])
                        var[str(ins[-1])] = int(add)
                    
                        
                    elif ins[1] == 'ADDTO':
                        x = ins[3]
                        if x in var.keys():
                            x = var[x]
                        var[str(ins[2])].append(x)
                    elif ins[1] == 'DELETE':
                        del var[ins[2]][int(ins[3]) - 1]
                    elif ins[1] == 'INSERT':
                        x = ins[4]
                        if x in var.keys():
                            x = var[x]
                        y = ins[3]
                        y = int(y) - 1
                        var[ins[2]].insert(y, x)
                    elif ins[1] == 'GETOUT':
                        var[ins[4]] = var[ins[2]][int(ins[3]) - 1]
                    elif ins[1] in ablist:
                        ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                    else:
                        print("INVALID SYNTAX:", ins[0])
            elif ins[1] == 'SET':
                if ins[4] == '->' and ins[2] == 'VAR':
                    if ins[6] == 'STRING':
                        var[str(ins[3])] = str(ins[5])
                    elif ins[6] == 'INTEGER':
                        var[str(ins[3])] = int(ins[5])
                    elif ins[6] == 'FLOAT':
                        var[str(ins[3])] = float(ins[5])
                    elif ins[6] == 'ARRAY':
                        var[str(ins[3])] = []
                else:
                    print('INVALID SYNTAX')
            elif ins[1] == '-->':
                try:
                    print('"'+var[str(ins[2])]+'"', end=' ')
                except:
                    print(var[str(ins[2])], end=' ')
            elif ins[1] == 'NEWLINE':
                print()
            elif ins[1] == 'PRINT':
                out = ""
                for string in ins[2:]:
                    out = out + ' ' + string
                print(out[1:],end=' ')
            elif ins[1] == 'GETINPUT':
                inp = input()
                var[str(ins[2])] = inp
            elif ins[1] == 'ADD':
                add = 0
                for integ in ins[2:-1]:
                    if integ in var.keys():
                        integ = int(var[str(integ)])
                    add += int(integ)
                var[str(ins[-1])] = int(add)
            elif ins[1] == 'SUB':
                add = int(ins[2])
                for integ in ins[2:-1]:
                    if integ in var.keys():
                        integ = int(var[str(integ)])
                    
                    add -= int(integ)
                var[str(ins[-1])] = int(add)
            elif ins[1] == 'MUL':
                add = 1
                for integ in ins[2:-1]:
                    if integ in var.keys():
                        integ = int(var[str(integ)])
                    add *= int(integ)
                var[str(ins[-1])] = int(add)
            elif ins[1] == 'DIV':
                if ins[2] in var.keys():
                    ins[2] = int(var[ins[2]])
                for integ in ins[2:-1]:
                    if integ in var.keys():
                        integ = int(var[str(integ)])
                    add /= int(integ)
                var[str(ins[-1])] = int(add)
            elif ins[1] == 'MOD':
                if ins[2] in var.keys():
                    ins[2] = int(var[str(ins[2])])
                if ins[3] in var.keys():
                    ins[3] = int(var[str(ins[3])])
                add = int(ins[2]) % int(ins[3])
                var[str(ins[-1])] = int(add)
            elif ins[1] == 'ADDTO':
                x = ins[3]
                if x in var.keys():
                    x = var[x]
                var[ins[2]].append(x)
            elif ins[1] == 'DELETE':
                del var[ins[2]][int(ins[3]) - 1]
            elif ins[1] == 'INSERT':
                x = ins[4]
                if x in var.keys():
                    x = var[x]
                y = ins[3]
                y = int(y) - 1
                var[ins[2]].insert(y, x)
            elif ins[1] == 'GETOUT':
                var[ins[4]] = var[ins[2]][int(ins[3]) - 1]
            elif ins[1] == 'ABSTAIN':
                ablist.append(ins[3])
            
                
                    
            elif ins[1] in ablist:
                ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
            else:
                print("INVALID SYNTAX:", ins)
        elif ins[0] == keywords[1]:   # DO
            x = [1,2]
            if choice(x) == 1:
                if ins[1] in ablist:
                    ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                elif ins[1] == 'COME' and ins[2] == 'FROM':
                    ins = x[int(ins[-1]) - 1]
                    if ins[1] in ablist:
                        ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                    elif ins[1] == 'SET':
                        if ins[4] == '->' and ins[2] == 'VAR':
                            if ins[6] == 'STRING':
                                var[str(ins[3])] = str(ins[5])
                            elif ins[6] == 'INTEGER':
                                var[str(ins[3])] = int(ins[5])
                            elif ins[6] == 'FLOAT':
                                var[str(ins[3])] = float(ins[5])
                            elif ins[6] == 'ARRAY':
                                var[str(ins[3])] = []
                        else:
                            print('INVALID SYNTAX')
                    elif ins[1] == '-->':
                        try:
                            print('"'+var[str(ins[2])]+'"', end=' ')
                        except:
                            print(var[str(ins[2])], end=' ')
                    elif ins[1] == 'NEWLINE':
                        print()
                    elif ins[1] == 'PRINT':
                        out = ""
                        for string in ins[2:]:
                            out = out + ' ' + string
                        print(out[1:],end=' ')
                    elif ins[1] == 'GETINPUT':
                        inp = input()
                        var[str(ins[2])] = inp
                    elif ins[1] == 'ADD':
                        add = 0
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add += int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'SUB':
                        if ins[2] in var.keys():
                            ins[2] = int(var[ins[2]])
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add -= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'MUL':
                        add = 1
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add *= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'DIV':
                        if ins[2] in var.keys():
                            ins[2] = int(var[ins[2]])
                        add = int(ins[2])
                        for integ in ins[2:-1]:
                            if integ in var.keys():
                                integ = int(var[str(integ)])
                            add /= int(integ)
                        var[str(ins[-1])] = int(add)
                    elif ins[1] == 'MOD':
                        if ins[2] in var.keys():
                            ins[2] = int(var[str(ins[2])])
                        if ins[3] in var.keys():
                            ins[3] = int(var[str(ins[3])])
                        add = int(ins[2]) % int(ins[3])
                        var[str(ins[-1])] = int(add)
                    
                    elif ins[1] == 'ADDTO':
                        x = ins[3]
                        if x in var.keys():
                            x = var[x]
                        var[str(ins[2])].append(x)
                    elif ins[1] == 'DELETE':
                        del var[ins[2]][int(ins[3]) - 1]
                    elif ins[1] == 'INSERT':
                        x = ins[4]
                        if x in var.keys():
                            x = var[x]
                        y = ins[3]
                        y = int(y) - 1
                        var[ins[2]].insert(y, x)
                    elif ins[1] == 'GETOUT':
                        var[ins[4]] = var[ins[2]][int(ins[3]) - 1]
                    elif ins[1] == 'ABSTAIN':
                        ablist.append(ins[3])        
                    elif ins[1] in ablist:
                        ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                    else:
                        print("INVALID SYNTAX")
                elif ins[1] == 'ADD':
                    add = 0
                    for integ in ins[2:-1]:
                        if integ in var.keys():
                            integ = int(var[str(integ)])
                        add += int(integ)
                    var[str(ins[-1])] = int(add)
                elif ins[1] == 'SUB':
                    if ins[2] in var.keys():
                        ins[2] = int(var[ins[2]])
                    for integ in ins[2:-1]:
                        if integ in var.keys():
                            integ = int(var[str(integ)])
                        add -= int(integ)
                    var[str(ins[-1])] = int(add)
                elif ins[1] == 'MUL':
                    add = 1
                    for integ in ins[2:-1]:
                        if integ in var.keys():
                            integ = int(var[str(integ)])
                        add *= int(integ)
                    var[str(ins[-1])] = int(add)
                elif ins[1] == 'DIV':
                    if ins[2] in var.keys():
                        ins[2] = int(var[ins[2]])
                    add = int(ins[2])
                    for integ in ins[2:-1]:
                        if integ in var.keys():
                            integ = int(var[str(integ)])
                        add /= int(integ)
                    var[str(ins[-1])] = int(add)
                elif ins[1] == 'MOD':
                    if ins[2] in var.keys():
                        ins[2] = int(var[str(ins[2])])
                    if ins[3] in var.keys():
                        ins[3] = int(var[str(ins[3])])
                    add = int(ins[2]) % int(ins[3])
                    var[str(ins[-1])] = int(add)
                
                elif ins[1] == 'PRINT':
                    out = ""
                    for string in ins[2:]:
                        out = out + ' ' + string
                    print(out[1:],end=' ')
                elif ins[1] == 'SET':
                    if ins[4] == '->' and ins[2] == 'VAR':
                        if ins[6] == 'STRING':
                            var[str(ins[3])] = str(ins[5])
                        elif ins[6] == 'INTEGER':
                            var[str(ins[3])] = int(ins[5])
                        elif ins[6] == 'FLOAT':
                            var[str(ins[3])] = float(ins[5])
                        elif ins[6] == 'ARRAY':
                            var[str(ins[3])] = []
                    else:
                        print('INVALID SYNTAX')
                elif ins[1] == '-->':
                    try:
                        print('"'+var[str(ins[2])]+'"', end=' ')
                    except:
                        print(var[str(ins[2])], end=' ')
                elif ins[1] == 'NEWLINE':
                    print()
                elif ins[1] == 'GETINPUT':
                    inp = input()
                    var[str(ins[2])] = inp
                elif ins[0] == 'IGNORE':
                    continue
                elif ins[1] == 'ADDTO':
                    x = ins[3]
                    if x in var.keys():
                        x = var[x]
                    var[str(ins[2])].append(x)
                elif ins[1] == 'DELETE':
                    del var[ins[2]][int(ins[3]) - 1]
                elif ins[1] == 'INSERT':
                    x = ins[4]
                    if x in var.keys():
                        x = var[x]
                    y = ins[3]
                    y = int(y) - 1
                    var[ins[2]].insert(y, x)
                elif ins[1] == 'GETOUT':
                    var[ins[4]] = var[ins[2]][int(ins[3]) - 1]
                else:
                    print("INVALID SYNTAX")
        
        elif ins[0] == keywords[2]:   # ABSTAIN
                if ins[0] in ablist:
                    ahfkjshaldkfjshakjfhsdajlhsdlfjwehaiuryafehwlGSDhbc = 0
                else:
                    ablist.append(ins[2])