def on_actionTabelaParsing_triggered(self): self.tabGramaticas.currentIndex() aba = self.tabGramaticas.currentWidget() parser = aba.parser if parser is None: aba.gerarParser() parser = aba.parser if parser: gramatica = parser.gramatica dialog = QDialog(self) janela = Ui_dialogTabela() janela.setupUi(dialog) tabela = janela.tabela cabecalhoLinhas = sorted(list(gramatica.Vn - {"&"})) cabecalhoColunas = sorted(list(gramatica.Vt - {"&"} | {"$"})) tabela.setColumnCount(len(cabecalhoColunas)) tabela.setRowCount(len(cabecalhoLinhas)) tabela.setHorizontalHeaderLabels(cabecalhoColunas) tabela.setVerticalHeaderLabels(cabecalhoLinhas) for i in range(len(cabecalhoLinhas)): for j in range(len(cabecalhoColunas)): t = cabecalhoColunas[j] nt = cabecalhoLinhas[i] try: num = parser.tabela[(nt, t)] tabela.setItem(i, j, QTableWidgetItem(str(num))) except KeyError: pass dialog.show()
def on_actionFirstFollow_triggered(self): aba = self.tabGramaticas.currentWidget() if aba.firsts is None or aba.follows is None: gramatica = aba.abaGramatica.textEditGramatica.toPlainText() resposta = verificarFormatoGramatica(gramatica) if resposta.correta: prods = resposta.prods prodsNumeradas = resposta.prodsNumeradas numProducoes = resposta.numProducoes Vn = resposta.Vn Vt = resposta.Vt inicial = resposta.inicial gramatica = GLC(Vn=Vn, Vt=Vt, inicial=inicial, prods=prods, prodsNumeradas=prodsNumeradas, numProducoes=numProducoes) aba.firsts = construirFirsts(gramatica) aba.follows = construirFollows(gramatica) else: QMessageBox.warning(self, resposta.tipoErro, resposta.mensagemErro) return firsts = aba.firsts follows = aba.follows dialog = QDialog(self) janela = Ui_dialogTabela() janela.setupUi(dialog) Vt = sorted(list(follows.keys())) tabela = janela.tabela tabela.setRowCount(len(Vt)) tabela.setColumnCount(2) tabela.setVerticalHeaderLabels(Vt) tabela.setHorizontalHeaderLabels(["First", "Follow"]) for i in range(len(Vt)): tabela.setItem(i, 0 , QTableWidgetItem( ",".join(firsts[Vt[i]]) ) ) tabela.setItem(i, 1 , QTableWidgetItem( ",".join(follows[Vt[i]]) ) ) dialog.show()