Exemple #1
0
    def run(source_code, vm):
        #why this runs, its because of the lox interpreter environment, which remains in existence even after this function ends 
        scanner = Scanner(source_code)
        scanner.scanTokens()
        
        parser = Parser(scanner.token_list)
        parser.parse()

        compiler = Compiler()
        compiler.compileAll(parser.AST)

        disassembler = Disassembler(compiler.chunk)
       
        vm.run(compiler.chunk)
Exemple #2
0
    def debugRun(source_code, vm):
        #why this runs, its because of the lox interpreter environment, which remains in existence even after this function ends 
        scanner = Scanner(source_code)
        scanner.scanTokens()
        
        print(scanner.toString())
        
        parser = Parser(scanner.token_list)
        parser.parse()

        print("##################################AST###################################")
        print(ASTPrinter().printAll(parser.AST))
        print("########################################################################")
        compiler = Compiler()
        compiler.compileAll(parser.AST)

        disassembler = Disassembler(compiler.chunk)
        print("#############################ByteCode###################################")
        print(disassembler.pretty_print())
        print("########################################################################")

        vm.run(compiler.chunk)