def click(self): gram=self.textEdit.toPlainText().split('\n') sentence=self.lineEdit.text() grammar=Grammar() grammar.insert_from_arr(gram) if grammar.have_left_recursion()==True: grammar.eliminating_left_recursion() if grammar.have_left_factor()==True: grammar.left_factoring() follow=grammar.follow() if grammar.is_LL1()==False: print('不是LL(1)文法') return table=grammar.consuct_predictive_parsing_table(follow) step = grammar.predictive_parsing(table, sentence) for i in range(len(step)): self.tableWidget.insertRow(self.tableWidget.rowCount()) for i in range(self.tableWidget.rowCount()): for j in range(self.tableWidget.columnCount()): self.tableWidget.setItem(i,j,QTableWidgetItem(step[i][j])) #把分析过程写入Excel文件中 from pyexcelerate import Workbook data = step # data is a 2D array wb = Workbook() wb.new_sheet("step", data=data) wb.save("output.xlsx")