def parse_var_decl(self, base, offset): last_id = '' added = False self.log.info('Parseaando declaracion de variables.') while self.next_token.type != "semicolon": self.read_token() if self.next_token.type == "semicolon": if not added: try: self.table.add_var(last_id, base) except ValueError: print("Error, identificador duplicado: " + last_id) self.writer = NullWriter() offset -= 1 self.read_token() break elif self.next_token.type == "ident": if not added and last_id: print('Se esperaba coma, se encontro identificador.') self.table.add_var(last_id, base) offset += 1 last_id = self.next_token.value added = False self.log.info("Declaro variable " + self.next_token.value) elif self.next_token.type == "comma": self.table.add_var(last_id, base) added = True self.log.info("Inicializo variable %s con valor por defecto" % last_id) elif self.next_token.type == 'semicolon': self.table.add_var(last_id, base) self.read_token() return offset else: print("Error, token inesperado: " + str(self.next_token)) self._panic_synchronize(['comma', 'semicolon', 'ident']) if not added: offset -= 1 return offset
def error_expected(self, expected): print("Se esperaba %s se recibio %s" % (expected, self.next_token.value)) self.writer = NullWriter()