def callback(res): lexical = Lexical() lexical.get_dfa('./help/dfa.json') # 读取DFA转换表 lexical_res = lexical.lexical_run(str(res).replace( '\r\n', '\n')) # 得到词法分析的token序列 tokens, nums_attr = [], [] if not lexical_res[0] and not lexical_res[1]: QMessageBox.warning(self, '输入无效', '请输入有效程序文本') return for idx in range(len( lexical_res[0])): # item[1]为种别码,item[3]为行号,item[2]为属性值 item = lexical_res[0][idx] if 'comment' not in item[1]: tokens.append(item[1]) nums_attr.append((item[3], item[2])) if not self.syntax: self.syntax = Syntax() self.syntax.syntax_init('./help/semantic.json') semantic = Semantic() res_lst, res_err = semantic.semantic_run(tokens, nums_attr, self.syntax) self.semantic_win = QDialog() ui = semantic_res.Ui_Dialog() init_win(self.semantic_win, ui) set_semantic_win(ui, semantic)
def callback(res): lexical = Lexical() lexical.get_dfa('./help/dfa.json') res = lexical.lexical_run(str(res).replace( '\r\n', '\n')) # 词法分析的token序列,要将window换行符'\r\n'转换 self.lexical_window = LexicalWindow(res) self.lexical_window.show()