예제 #1
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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)
예제 #2
0
 def define(self, id, info, linea):
     if self.tactual.has_key(id):
         errores.semantico(
             "Error, el identificador %s ya esta definido en este ambito." %
             id, linea)
     else:
         self.tactual[id] = info
예제 #3
0
파일: AST.py 프로젝트: rdonate/MiniComp
 def compsemanticas(self):
     self.izdo.compsemanticas()
     if self.izdo.tipo != tipos.Cadena:
         self.tipo = self.izdo.tipo
     else:
         errores.semantico("No se puede cambiar el signo de una cadena.",
                           self.linea)
예제 #4
0
파일: AST.py 프로젝트: rdonate/MiniComp
 def compsemanticas(self):
     for expresion in self.exp:
         expresion.compsemanticas()
         if expresion.tipo != tipos.Error:
             if expresion.tipo != tipos.Entero and expresion.tipo != tipos.Real and expresion.tipo != tipos.Cadena:
                 errores.semantico(
                     "Solo se escribir enteros, reales y cadenas.",
                     self.linea)
예제 #5
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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
예제 #6
0
파일: AST.py 프로젝트: rdonate/MiniComp
 def __init__(self, cond, siysino, linea):
     self.cond = cond
     self.linea = linea
     if len(siysino) == 2:
         self.si = siysino[0]
         self.sino = siysino[1]
     elif len(siysino) == 1:
         self.si = siysino[0]
         self.sino = None
     else:
         errores.semantico("El nodo si esta mal formado.", self.linea)
예제 #7
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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)
예제 #8
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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
예제 #9
0
 def compsemanticas(self):
   for par in self.parametros:
     if not par.tipo.elemental():
       errores.semantico("El parametro %s tiene tipo compuesto." % par.id, par.nlinea)
   for var in self.variables:
     if not var.tipo.elemental():
       errores.semantico("La variable %s es local y tiene tipo compuesto." % var.id, var.nlinea)
   if not self.tipoDevuelto.elemental():
     errores.semantico("El tipo devuelto de las funciones debe ser elemental.", self.nlinea)
   self.codigo.compsemanticas()
예제 #10
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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)
예제 #11
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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)
예제 #12
0
파일: AST.py 프로젝트: rdonate/MiniComp
 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)
예제 #13
0
파일: AST.py 프로젝트: rdonate/MiniComp
 def compsemanticas(self):
     self.exp.compsemanticas()
     if self.exp.tipo != tipos.Error:
         if self.exp.tipo != tipos.Entero and self.exp.tipo != tipos.Real:
             errores.semantico("Solo se lee enteros y reales.", self.linea)