Exemplo n.º 1
0
class AutoTester():

    def __init__(self, code, file_name, reuse_file=None):
        self.code = code
        self.file_name = file_name
        self.compiler = None
        self.reuse_file = False if reuse_file is None else reuse_file

    def compare(self, input, expected_output):

        if self.compiler is None:

            self.compiler = Compiler(self.code, self.file_name, input, self.reuse_file)
        else:
            self.compiler.change_input(input)

        output = self.compiler.compile()
        return self.__compare_outputs(output.strip(), expected_output.strip())

    @staticmethod
    def __compare_outputs(expected_output, actual_output):
        return cmp(expected_output.split(), actual_output.split()) == 0

    def remove_file(self):
        self.compiler.remove_file()
Exemplo n.º 2
0
    def compare(self, input, expected_output):

        if self.compiler is None:

            self.compiler = Compiler(self.code, self.file_name, input, self.reuse_file)
        else:
            self.compiler.change_input(input)

        output = self.compiler.compile()
        return self.__compare_outputs(output.strip(), expected_output.strip())
Exemplo n.º 3
0
def main(argv):
    compiler = Compiler()
    input = FileStream(argv[1])  #read the first argument as a filestream
    lexer = patitoLexer(input)  #call your lexer
    stream = CommonTokenStream(lexer)
    parser = patitoParser(compiler, stream)
    tree = parser.program(
    )  #start from the parser rule, however should be changed to your entry rule for your specific grammar.

    if parser.getNumberOfSyntaxErrors() == 0:
        print(
            "PROGRAMA CORRECTO ========================================================================"
        )
        quadruples = compiler.get_quadruples()
        constants = compiler.get_constants_table()
        virtualMachine = VirtualMachine(quadruples, constants)
        virtualMachine.begin()
    else:
        print("PROGRAMA INCORRECTO")