def parse(parser, codeWriter, fileName):
    import stackParser
    from stackParser import Parser
    codeWriter.setFileName(fileName)
    while parser.hasMoreCommands():
        parser.advance()
        print("Command is " + parser.current() + " type is " +
              str(parser.commandType()))
        if parser.commandType() == Parser.C_ARITHMETIC:
            codeWriter.writeArithmetic(parser.arg1())
        elif (parser.commandType() == Parser.C_PUSH) | (parser.commandType()
                                                        == Parser.C_POP):
            codeWriter.writePushPop(parser.commandType(), parser.arg1(),
                                    parser.arg2())
        elif parser.commandType() == Parser.C_GOTO:
            codeWriter.writeGoto(parser.arg1())
        elif parser.commandType() == Parser.C_LABEL:
            codeWriter.writeLabel(parser.arg1())
        elif parser.commandType() == Parser.C_IF:
            codeWriter.writeIf(parser.arg1())
        elif parser.commandType() == Parser.C_CALL:
            codeWriter.writeCall(parser.arg1(), int(parser.arg2()))
        elif parser.commandType() == Parser.C_RETURN:
            codeWriter.writeReturn()
        elif parser.commandType() == Parser.C_FUNCTION:
            codeWriter.writeFunction(parser.arg1(), int(parser.arg2()))
        else:
            print("Unhandled command type, type is " +
                  str(parser.commandType()))
            print("\tCommand is " + parser.current())
def parse(parser, codeWriter, fileName):
    import stackParser
    from stackParser import Parser
    codeWriter.setFileName(fileName)
    while parser.hasMoreCommands():
        parser.advance()
        print("Command is " + parser.current() + " type is " + str(parser.commandType()))
        if parser.commandType() == Parser.C_ARITHMETIC:
            codeWriter.writeArithmetic(parser.arg1())
        elif (parser.commandType() == Parser.C_PUSH) | (parser.commandType() == Parser.C_POP):
            codeWriter.writePushPop(parser.commandType(), parser.arg1(), parser.arg2())
        elif parser.commandType() == Parser.C_GOTO:
            codeWriter.writeGoto(parser.arg1())
        elif parser.commandType() == Parser.C_LABEL:
            codeWriter.writeLabel(parser.arg1())
        elif parser.commandType() == Parser.C_IF:
            codeWriter.writeIf(parser.arg1())
        elif parser.commandType() == Parser.C_CALL:
            codeWriter.writeCall(parser.arg1(), int(parser.arg2()))
        elif parser.commandType() == Parser.C_RETURN:
            codeWriter.writeReturn()
        elif parser.commandType() == Parser.C_FUNCTION:
            codeWriter.writeFunction(parser.arg1(), int(parser.arg2()))
        else:
            print("Unhandled command type, type is " + str(parser.commandType()))
            print("\tCommand is " + parser.current())
def parse(parser, codeWriter, fileName):
    import stackParser
    from stackParser import Parser

    codeWriter.setFileName(fileName)
    while parser.hasMoreCommands():
        parser.advance()
        if parser.commandType() == Parser.C_ARITHMETIC:
            codeWriter.writeArithmetic(parser.arg1())
        elif (parser.commandType() == Parser.C_PUSH) | (parser.commandType() == Parser.C_POP):
            codeWriter.writePushPop(parser.commandType(), parser.arg1(), parser.arg2())
        else:
            print("Unhandled command type, type is " + str(parser.commandType()))
예제 #4
0
def commandType():
    global data
    global arith
    global push
    global pop
    arith = False
    push = False
    pop = False
    global components
    components = data[currentLine].split(" ")
    if data[currentLine] in arithmetic:
        codeWriter.writeArithmetic()
    elif "push" in data[currentLine] or "pop" in data[currentLine]:
        codeWriter.writePushPop()
예제 #5
0
def parse(parser, codeWriter, fileName):
    import stackParser
    from stackParser import Parser
    codeWriter.setFileName(fileName)
    while parser.hasMoreCommands():
        parser.advance()
        if parser.commandType() == Parser.C_ARITHMETIC:
            codeWriter.writeArithmetic(parser.arg1())
        elif (parser.commandType() == Parser.C_PUSH) | (parser.commandType()
                                                        == Parser.C_POP):
            codeWriter.writePushPop(parser.commandType(), parser.arg1(),
                                    parser.arg2())
        else:
            print("Unhandled command type, type is " +
                  str(parser.commandType()))