Beispiel #1
0
def format_writable(stack, input, prove):
    string = ''
    for c in stack:
        if c[0] != '!':
            string += str(c[0])
        string += str(c[1])
    string += ' ' * (15 - len(string))
    for i in input:
        string += i
    string += ' ' * (35 - len(string))
    p1 = 'Shift' if prove[0] == 'S' else 'Reduce'
    p2 = prove[1]
    string += p1 + ' '
    string += p2
    return string


def write_to_file(l):
    file1 = open("output.txt", "w+")
    for f in l:
        file1.readline()
        write_string = str(f) + '\n'
        file1.write(write_string)
    file1.close()


grammer = Grammer(fr.read_grammer())
table = Table(fr.read_table())
process('( id + id ) * id $', grammer, table)