private bool runParser() { bool ret = true; Parser parser = new Parser(wordList); Hashtable result = parser.Run(); //accept if ((int)result[Message.KEY] == Message.SUCCESS) { ret = true; wordList = (List <Pascal>)result[Message.VALUE]; MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = (string)result[Message.MSG]; info.ShowDialog(); linkLabelSemantic.Text = Semantic.outputPath; linkLabelSemantic.Visible = true; } else //error { ret = false; MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = (string)result[Message.MSG]; info.ShowDialog(); } labelParserResult.Text = (string)result[Message.MSG]; labelParserResult.Visible = true; return(ret); }
private void buttonCompiling_Click(object sender, EventArgs e) { //文本框为空 if (richTextBoxMain.Text.Length == 0) { //空代码 提示输入 MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = "输入代码不能为空"; info.ShowDialog(); return; } saveCode(saveFilePath); if (!runLexical()) { //词法分析失败或存在错误词法 return; } if (!runParser()) { //语法错误 return; } }
/// <summary> /// 词法分析 /// </summary> private bool runLexical() { Lexical lexical = new Lexical(saveFilePath); Hashtable result = lexical.Run(); bool ret = true; if ((int)result[Message.KEY] == Message.SUCCESS) { ret = true; wordList = (List <Pascal>)result[Message.VALUE]; if (wordList[wordList.Count - 1].Type != Type.FINISH) { ret = false; MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = "词法分析完成,未识别合法结束符!部分词法分析结果下:"; info.linkLabel.Text = Lexical.outputPath; info.linkLabel.Visible = true; info.ShowDialog(); linkLabelLexResult.Text = Lexical.outputPath; linkLabelLexResult.Visible = true; } else { foreach (Pascal pascal in wordList) { if (pascal.Type < 0) { ret = false; break; } } MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = ret ? "词法分析完成,结果在文件:" : "词法分析完成,存在词法错误,在文件中查看:"; info.linkLabel.Text = Lexical.outputPath; info.linkLabel.Visible = true; info.ShowDialog(); linkLabelLexResult.Text = Lexical.outputPath; linkLabelLexResult.Visible = true; } } else { ret = false; wordList = null; MainInfoForm info = new MainInfoForm(); info.labelInfo.Text = "词法分析失败!"; info.ShowDialog(); } return(ret); }