Ejemplo n.º 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()
Ejemplo n.º 2
0
def create_dev(ip):
    dev = Router(ip, username, password, cmd_file, rdeb)
    if dev.err:
        print "Skipping device %s\n" %ip
        return
    #all input values are correct
    #create Interpreter
    i = Interpreter(dev, ideb, ideb)
    i.start()
    if ideb:
        #print last debug info
        print "Oper_st: %s" %i.oper_st
        print "Data_st: %s" %i.data_st
        print "Env: %s" %i.env
Ejemplo n.º 3
0
            #strip leading spaces
            cmd = self.cmds.pop(0)
            cmd = cmd.lstrip()
            #skip comments
            while  cmd.startswith('#'):
                if len(self.cmds) == 0:
                    print "Done with device \n"
                    return False
                cmd = self.cmds.pop(0).lstrip()
            return cmd
    #end of Dummy class
    #instantiate Dummy
    r = Dummy()
    #instantiate Interpreter and set debug
    i = Interpreter(r, debug = True, verb = verbose)
    i.start()
    print "Oper_st: %s" %i.oper_st
    print "Data_st: %s" %i.data_st
    #print env after last command if required
    if verbose: print "Env: %s" %i.env
    #work is done end
    sys.exit()   

else : #wrong command
    print "Usage: Rtrcfg -d =>for Router debug or Rtrcfg -d|-dd cmd_file =>for Interpreter debug"; sys.exit()

#list with device ips
ip_list = []

#get ips        
ip_file = raw_input("Enter IP file or an IP: ")