def p_startBotDeclaration(p):
    '''startBotDeclaration  :   '''
    global sintBotSymbolTable
    sintBotSymbolTable = TablaDeSimbolos(deepcopy(sintBotSymbolTable))
    global currentBotType
    simbolo = Simbolo("me",currentBotType,None)
    sintBotSymbolTable = sintBotSymbolTable.agregarATabla(simbolo.obtenerIdentificador(),simbolo)
 def run(self):
     """
     Corrida de la instruccion
     """
     global BotSymbolTable
     global posicionmatriz
     # Creamos el simbolo
     simbolo = Simbolo(self.identifier,self.botType,None)
     simbolo.tablaDeComportamientos = self.declarationSet
     # Agregamos el simbolo a la tabla
     BotSymbolTable.agregarATabla(self.identifier, simbolo)
def p_botCreate(p):
    '''botCreate :       TkInt  TkBot TkIdent botDeclaracionList TkEnd
                 |       TkBool TkBot TkIdent botDeclaracionList TkEnd
                 |       TkChar TkBot TkIdent botDeclaracionList TkEnd'''
    p[0] = Instruccion.CreateInstruccion(p[1],p[3],p[4])
    simbolo = Simbolo(p[3],p[1],None)
    simbolo.tablaDeComportamientos = p[4]
    global sintBotSymbolTable
    sintBotSymbolTable = sintBotSymbolTable.agregarATabla(p[3],simbolo)
    global currentBotType
    currentBotType = p[1]
def declararVariableTemporal(identificador,valor):
    """
    Crea una variable temporal para usos internos de un comportamiento
    
    @type  identificador: str
    @param identificador: identificador de variable
    @type  valor: Object
    @param valor: valor de la variable
    @rtype: Simbolo
    @return: simbolo temporal nuevo
    """
    simbolo = Simbolo(identificador,None,None)
    simbolo = simbolo.crearSimboloDeValor(valor)
    simbolo.setValue(valor)
    simbolo.activado = True
    return simbolo
 def run(self):
     """
     Corrida de la instruccion
     """
     global BotSymbolTable
     global currentBotType
     global currentBotValue
     global currentBotHorPosicion
     global currentBotVerPosicion
     j = 0
     # Por cada bot
     for j in range(0,len(self.identList)):
         # Buscamos los datos actuales del bot
         simbolo = BotSymbolTable.buscarSimbolo(self.identList[j])
         # Guardamos sus datos en variables globales
         currentBotType = simbolo.obtenerTipo()
         currentBotValue = simbolo.obtenerValor()
         currentBotHorPosicion = simbolo.horPosicion
         currentBotVerPosicion = simbolo.verPosicion
         # Creamos un nuevo nivel de tabla de simbolos
         BotSymbolTable = TablaDeSimbolos(deepcopy(BotSymbolTable))
         # Creamos un simbolo Me con los datos del bot actual
         symbolMe = Simbolo("me",currentBotType,currentBotValue)
         symbolMe.horPosicion = currentBotHorPosicion
         symbolMe.verPosicion = currentBotVerPosicion
         symbolMe.activado = True
         # Agregamos el simbolo a la tabla
         BotSymbolTable = BotSymbolTable.agregarATabla(symbolMe.obtenerIdentificador(),symbolMe)
         # Si el bot esta desactivado procedemos
         if simbolo.activado == False:
             # Marcamos el bot como activado
             BotSymbolTable.actualizarEstadoSimbolo(self.identList[j],True)
             # Buscamos el comportamiento correspondiente
             for behavior in simbolo.tablaDeComportamientos:
                 if behavior.condition == 'activation':
                     # Corremos las instrucciones del comportamiento
                     result = behavior.run()
                     # Si la operacion devuelve un resultado actualizamos el valor del bot
                     if result != None:
                         BotSymbolTable.actualizarValorDeSimbolo(self.identList[j],result.obtenerValor())
                         BotSymbolTable.actualizarPosicionHorSimbolo(self.identList[j],result.horPosicion)
                         BotSymbolTable.actualizarPosicionVerSimbolo(self.identList[j],result.verPosicion)
                     break
         # El Bot ya estaba activo, ERROR
         else:
             print("ERROR: " +self.identList[j]+ " ya se encontraba activo")
             exit()
 def run(self):
     """
     Corrida de la instruccion
     """
     global BotSymbolTable
     global currentBotType
     global currentBotValue
     global currentBotHorPosicion
     global currentBotVerPosicion
     # Por cada bot
     for j in range(0,len(self.identList)):
         # Buscamos los datos actuales del bot
         simbolo = BotSymbolTable.buscarSimbolo(self.identList[j])
         # Guardamos sus datos en variables globales
         currentBotType = simbolo.obtenerTipo()
         currentBotValue = simbolo.obtenerValor()
         currentBotHorPosicion = simbolo.horPosicion
         currentBotVerPosicion = simbolo.verPosicion
         # Creamos un nuevo nivel de tabla de simbolos
         BotSymbolTable = TablaDeSimbolos(deepcopy(BotSymbolTable))
         # Creamos un simbolo Me con los datos del bot actual
         symbolMe = Simbolo("me",currentBotType,currentBotValue)
         symbolMe.horPosicion = currentBotHorPosicion
         symbolMe.verPosicion = currentBotVerPosicion
         symbolMe.activado = simbolo.activado
         # Agregamos el simbolo a la tabla
         BotSymbolTable = BotSymbolTable.agregarATabla(symbolMe.obtenerIdentificador(),symbolMe)
         # Inicializamos las variables referentes al comportamiento default
         defaultEnabled = True
         defaultPosicion = None
         # Si el bot esta activado procedemos
         if simbolo.activado == True:
             # Buscamos comportamientos personalizados
             for i in range(0,len(simbolo.tablaDeComportamientos)):
                 # Buscamos los comportamientos con expresiones
                 if (type(simbolo.tablaDeComportamientos[i].condition) is ExpresionParentizada or
                     type(simbolo.tablaDeComportamientos[i].condition) is ExpresionBooleana or
                     type(simbolo.tablaDeComportamientos[i].condition) is ExpresionRelacional):
                     # Si ya se ha encontrado default entonces hay un ERROR
                     if defaultPosicion != None:
                         print("ERROR: Default definido antes que comportamiento con expresion")
                         exit()
                     # Buscamos el primero que se cumpla
                     if simbolo.tablaDeComportamientos[i].condition.evaluar(BotSymbolTable) == True:
                         result = simbolo.tablaDeComportamientos[i].run()
                         # Si la operacion devuelve un resultado actualizamos el valor del bot
                         if result != None:
                             BotSymbolTable.actualizarValorDeSimbolo(self.identList[j],result.obtenerValor())
                             BotSymbolTable.actualizarPosicionHorSimbolo(self.identList[j],result.horPosicion)
                             BotSymbolTable.actualizarPosicionVerSimbolo(self.identList[j],result.verPosicion)
                         defaultEnabled = False
                         break
                 # Si encontramos el comportamiento default anotamos su posicion para compararla con la
                 # de los demas comportamientos
                 elif simbolo.tablaDeComportamientos[i].condition == 'default':
                     defaultPosicion = i
             # Si no se encontro ninguna condicion que se cumpla, utilizamos el comportamiento default
             if defaultEnabled: 
                 # Buscamos el comportamiento default
                 for behavior in simbolo.tablaDeComportamientos:
                     if behavior.condition == 'default':
                         result = behavior.run()
                         # Si la operacion devuelve un resultado actualizamos el valor del bot
                         if result != None:
                             BotSymbolTable.actualizarValorDeSimbolo(self.identList[j],result.obtenerValor())
                             BotSymbolTable.actualizarPosicionHorSimbolo(self.identList[j],result.horPosicion)
                             BotSymbolTable.actualizarPosicionVerSimbolo(self.identList[j],result.verPosicion)
                         break
         # El Bot no estaba activo, ERROR
         else:
             print("ERROR: " +self.identList[j]+ " no se encontraba activo")
             exit()