def p_expre_call(p): 'expre : ID PARI exprelist PARD' p[0] = Node( 'call', [p[3]], p[1] ) typ = symtab.find_type(p[1]) try: p[0].typ = (typ[0], p[3].value) except AttributeError: p[0].typ= (typ[0], "unknow") pass
def p_expre_id(p): 'expre : ID' p[0] = Node('id', [], p[1]) p[0].value = p[1] # Validacion id no declarado. data = symtab.find_id( p[1] ) if not data : print ( ">>ERROR: identificador '%s' no declarada. Linea" % p[1] ) # tipo de dato typ = symtab.find_type(p[1]) if typ : p[0].typ = typ
def p_expre_array(p): 'expre : ID CORI expre CORD' p[0] = Node('array',[p[3]],p[1]) typ = symtab.find_type(p[1]) try: p[0].typ = (typ[0], p[3].value) except AttributeError: p[0].typ= (typ[0], "unknow") pass # indices enteros if hasattr(p[3],'typ') & hasattr(p[3],'value'): if p[3].typ != 'int': print (">>ERROR: El indice del array %s debe ser un valor entero" % typ[0])
def p_location_2(p): 'location : ID CORI expre CORD' p[0] = Node('array',[p[3]],p[1]) # Tipo del id typ = symtab.find_type(p[1]) try: p[0].typ = (typ[0], p[3].value) except AttributeError: p[0].typ= (typ[0], "unknow") pass p[0].value = p[1] # Indices enteros if hasattr(p[3],'typ'): if p[3].typ[0] != 'int': print (">>ERROR: El indice del array %s debe ser un valor entero" % typ[0]) # Validacion id no declarado. data = symtab.find_id( p[1] ) if not data : print ( ">>ERROR: identificador '%s' no declarada." % p[1] )