Example #1
0
 def parse(self):
     instructions = self._program()
     # do not print any output if error occurs
     if self.total_error_flag == 0:
         if self.print_symbol_table == 0:
             self.observer.print_output()
         elif self.print_symbol_table == 1:
             self.visitor.visitScope(self.program_scope)
             self.visitor.end()
         elif self.print_symbol_table == 2:
             currinstruction = instructions
             self.visitor.start()
             # while(currinstruction is not None):
             currinstruction.visit(self.visitor)
             # currinstruction = currinstruction._next
         elif self.print_symbol_table == 3:
             environment = self.program_scope.make_environment()
             stack = []
             currinstruction = instructions
             #while curr is not None:
             #    self.interpret(curr, environment, stack)
             #    curr = curr._next
             #v = InterpreterVisitor(environment)
             #v.start()
             #currinstruction.int_visit(v)
             v = Interpreter(currinstruction, environment)
             v.start()
         elif self.print_symbol_table == 4:
             #environment = self.program_scope.make_code_generator_environment()
             #print environment
             self.program_scope.make_code_generator_environment()
             c = CodeGenerator(self.program_scope, 0, instructions)
             c.start()
             c.cgoutput()
         elif self.print_symbol_table == 5:
             self.program_scope.make_code_generator_environment()
             c = CodeGenerator(self.program_scope, 1, instructions, filename=self.filename+".s")
             c.start()
             c.cgoutput()