Ejemplo n.º 1
0
 def compsemanticas(self):
     self.izdo.compsemanticas()
     self.dcho.compsemanticas()
     if not tipos.igualOError(self.izdo.tipo, tipos.Entero) or \
        not tipos.igualOError(self.dcho.tipo, tipos.Entero):
         errores.semantico(
             "Las operaciones de comparacion solo pueden operar con enteros.",
             self.linea)
         self.tipo = tipos.Error
     else:
         self.tipo = tipos.Logico
Ejemplo n.º 2
0
 def compsemanticas(self):
     self.cond.compsemanticas()
     for sent in self.sentencias:
         sent.compsemanticas()
     if not tipos.igualOError(self.cond.tipo, tipos.Logico):
         errores.semantico("La condicion del si debe ser de tipo logico.",
                           self.linea)
Ejemplo n.º 3
0
 def compsemanticas(self):
     self.izdo.compsemanticas()
     self.dcho.compsemanticas()
     if tipos.igualOError(self.izdo.tipo, tipos.Cadena) or \
        tipos.igualOError(self.dcho.tipo, tipos.Cadena):
         errores.semantico(
             "Las operaciones aritmeticas solo pueden operar con enteros y reales.",
             self.linea)
         self.tipo = tipos.Error
     else:
         if tipos.igualOError(self.izdo.tipo, self.dcho.tipo):
             self.tipo = self.izdo.tipo
         elif tipos.igualOError(self.izdo.tipo,
                                tipos.Real) or tipos.igualOError(
                                    self.dcho.tipo, tipos.Real):
             self.tipo = tipos.Real
         else:
             self.tipo = tipos.Entero
Ejemplo n.º 4
0
 def compsemanticas(self):
     self.izda.compsemanticas()
     self.exp.compsemanticas()
     if not tipos.igualOError(self.izda.tipo, self.exp.tipo):
         if not self.izda.tipo == tipos.Real and self.exp.tipo == tipos.Entero:
             errores.semantico(
                 "Tipos incompatibles en asignacion (%s y %s)." %
                 (self.izda.tipo, self.exp.tipo), self.linea)
     else:
         if not self.izda.tipo.elemental() or not self.exp.tipo.elemental():
             errores.semantico(
                 "Solo puedo asignar objetos de tipos elementales.",
                 self.linea)
Ejemplo n.º 5
0
 def compsemanticas(self):
     self.izda.compsemanticas()
     self.exp.compsemanticas()
     if self.izda.tipo != tipos.Error:
         if self.izda.tipo.elemental():
             errores.semantico(
                 "Estas accediendo a una expresion de tipo %s como si fuera un vector."
                 % self.izda.tipo, self.linea)
             self.tipo = tipos.Error
         elif self.izda.tipo == tipos.Funcion:
             errores.semantico(
                 "Estas accediendo a la funcion %s como si fuera un vector."
                 % self.izda.var.id, self.linea)
             self.tipo = tipos.Error
         else:
             self.tipo = self.izda.tipo.base
     else:
         self.tipo = tipos.Error
     if not (tipos.igualOError(self.exp.tipo, tipos.Entero) and \
        not tipos.igualOError(self.exp.tipo, tipos.Real)):
         errores.semantico(
             "El tipo de la expresion de acceso al vector debe ser entero.",
             self.linea)
Ejemplo n.º 6
0
 def compsemanticas(self):
     for arg in self.args:
         arg.compsemanticas()
     if not self.f.tipo == tipos.Funcion:
         errores.semantico(
             "Estas intentando llamar a algo que no es una funcion.",
             self.linea)
         self.tipo = tipos.Error
         return
     self.tipo = self.f.tipoDevuelto
     if self.f.tipoDevuelto == tipos.Error:
         return
     if len(self.args) != len(self.f.parametros):
         errores.semantico(
             "La llamada a %s deberia tener %d parametros en lugar de %d." %
             (self.f.id, len(self.f.parametros), len(self.args)),
             self.linea)
     else:
         for i in range(len(self.args)):
             arg = self.args[i]
             pf = self.f.parametros[i]
             if not tipos.igualOError(arg.tipo, pf.tipo):
                 if not pf.referencia:
                     if not tipos.igualOError(
                             arg.tipo, tipos.Real) and tipos.igualOError(
                                 pf.tipo, tipos.Real):
                         arg = NodoEnteroAReal(arg, self.linea)
                         self.args[i] = arg
                     else:
                         errores.semantico(
                             "No coincide el tipo del parametro %d (deberia ser %s)."
                             % (i + 1, pf.tipo), self.linea)
                 else:
                     if not arg.__class__.__name__ == "NodoAccesoVariable":
                         errores.semantico(
                             "No coincide el tipo del parametro %d (deberia ser %s)."
                             % (i + 1, pf.tipo), self.linea)
Ejemplo n.º 7
0
 def compsemanticas(self):
     self.exp.compsemanticas()
     if not tipos.igualOError(self.exp.tipo, self.f.tipoDevuelto):
         errores.semantico(
             "El tipo de la expresion del devuelve debe coincidir con el de la funcion.",
             self.linea)