def load_errors(self, file_path): fields, errors = read_csv(file_path) assert fields == ["analisator", "terminal", "code", "message"] for analisator, terminal, code, message in errors: self.action[analisator, terminal] = code # recupera o erro self.action[analisator, code] = message # recupera o erro
def load_actions(self, file_path): fields, actions = read_csv(file_path) assert fields == ["analisator", "terminal", "state", "action"] for analisator, terminal, state, action in actions: self.action[analisator, terminal] = action # recupera a ação self.action[analisator, terminal, action] = state # realizará a ação no estado state
def load_dfa(transitions_file, accept_states_file, alphabet=None, states=None, start='s0'): fields, transitions = read_csv(transitions_file) fields, accept_states = read_csv(accept_states_file) for t in transitions: if t[1] == '\\t': t[1] = '\t' if t[1] == '\\n': t[1] = '\n' if t[1] == '\\.': t[1] = '.' if t[1] == '[A-z0-9]': t[1] = ANY alphabet = set(list(zip(*transitions))[1]).union(alphabet_ascii) states = set(list(zip(*transitions))[0] + list(zip(*transitions))[2]) accept_states = set(list(zip(*accept_states))[0]) D = DFA(alphabet=alphabet, states=states, start=start, transitions=transitions, accept=accept_states) return D
def load_tokens(self): d = {} fields, accept_states = read_csv('tables/tab_final_states.csv') for stt, token in accept_states: d[stt] = token return d
def load_goto(self, file_path): fields, deviations = read_csv(file_path) assert fields == ["state", "symbol", "next"] for state, symbol, next in deviations: self.goto[state, symbol] = next # recupera o desvio