//button:完成单个单词分析 private void toolStripButton_next_Click(object sender, EventArgs e) { gr.rebuilt(); //每次都把堆栈清空 if (myLex.filePath != "") { //词法分析 nResult = myLex.GetAWord(); //词法分析,识别下一个单词 if (nResult == myLex.OK && myLex.myToken.g_nWordsIndex >= 1) { if (myLex.myToken.judgecomment == false) { myLex.getPrintInLexis(myLex.myToken.g_nWordsIndex - 1, myString); //准备打印一个单词 PrintInLexisToListView(myString); //词法显示 //语法工作 for (int i = 0; i < myLex.myToken.g_nWordsIndex; i++) //把所有的已读好的符号放入栈中 { syntaxString = new string[6]; syntaxString[0] = Convert.ToString(myLex.myToken.g_nWordsIndex - (i + 1)); //序号 syntaxString[1] = myLex.myToken.g_Words[myLex.myToken.g_nWordsIndex - (i + 1)].szName; //名称 syntaxString[2] = myLex.enumToString(myLex.myToken.g_nWordsIndex - (i + 1)); //类型 syntaxString[3] = Convert.ToString(myLex.myToken.g_Words[myLex.myToken.g_nWordsIndex - (i + 1)].nNumberValue); syntaxString[4] = Convert.ToString(myLex.myToken.g_Words[myLex.myToken.g_nWordsIndex - (i + 1)].nLineNo); syntaxString[5] = Convert.ToString(myLex.myToken.g_Words[myLex.myToken.g_nWordsIndex - (i + 1)].nColumnNo); gr.Input_Stack_Push(syntaxString); } //怼栈 gr.match(gr.input_stack, gr, nResult); //语法显示 PrintInSyntaxToSyntax(); //错误输出 textBox_error.Text = gr.errorshow; } thisStatus.Text = " 成功读入一个token"; //更新状态 } else { thisStatus.Text = " 读入失败或者文件编译结束"; } } else //没有导入文件 { MessageBox.Show("代码框不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); thisStatus.Text = " 请选择待编译文件"; } }