编译原理经典算法的可视化实现 - 图文

编译原理经典算法的可视化实现 rtSource.Clear(); listShow.Items.Clear(); paint(); rtSource.Text = reader.ReadToEnd(); } } else {

return; }

}

private void rtSource_TextChanged(object sender, EventArgs e) {

rtSource.SelectionColor = Color.Black; if (this.rtSource.Text.Length == 0) {

this.toolExcute.Enabled = false; this.toolRecovery.Enabled = false; this.toolStop.Enabled = false; } else {

this.toolStop.Enabled = true; this.toolExcute.Enabled = true; this.toolRecovery.Enabled = true; } }

/*颜色改变*/

private void changecolor() {

rtSource.SelectionStart = i-1; rtSource.SelectionLength = 1;

rtSource.SelectionColor = Color.Red; i++; }

/*文件删除*/

33

编译原理经典算法的可视化实现 /*实现执行*/ private void fileSave() { if (File.Exists(\)) File.Delete(\); FileStream fs = new FileStream(\, FileMode.OpenOrCreate, FileAccess.Write); StreamWriter m_streamWriter = new StreamWriter(fs); m_streamWriter.Flush(); m_streamWriter.BaseStream.Seek(0, SeekOrigin.Begin); m_streamWriter.Write(rtSource.Text); m_streamWriter.Flush(); m_streamWriter.Close();

}

private void cmdExcute() {

System.Diagnostics.Process lexProcess = new System.Diagnostics.Process(); lexProcess.StartInfo.FileName = \; lexProcess.StartInfo.UseShellExecute = false; lexProcess.StartInfo.RedirectStandardInput = true; lexProcess.StartInfo.RedirectStandardOutput = true; lexProcess.StartInfo.RedirectStandardError = true; lexProcess.StartInfo.CreateNoWindow = true; lexProcess.Start();

lexProcess.StandardInput.WriteLine(\); System.Threading.Thread.Sleep(1000); lexProcess.StandardInput.WriteLine(\);

lexProcess.Close(); }

private void toolExcute_Click(object sender, EventArgs e) {

fileSave(); cmdExcute(); tm.Start();

this.toolExcute.Enabled = false; i = 1;

Thread thSeperate = new Thread(new ThreadStart(Seperate));

34

编译原理经典算法的可视化实现 listShow.Items.Clear(); thSeperate.Start(); // MessageBox.Show(thSave.ThreadState.ToString()); // MessageBox.Show(thSeperate.ThreadState.ToString()); } /*实现恢复*/ private void toolRecovery_Click(object sender, EventArgs e) { i = 1; paint(); listShow.Items.Clear(); this.toolExcute.Enabled = true ; } /*字符判别*/ private int judge( string str) { string str1, str2; int f=0; char[] charArray=new Char []{'('}; string[] strArray = str.Split(charArray); if (!str.Equals(\)) { str1 = strArray[0].Trim(); str2 = strArray[1].Trim(); f = int.Parse(str2); } if(str.Equals (\)) return 0; if ((258<=f&&f<285)||(f==297)) return 1; if(str.Equals (\)) return 3; return 2; } /*从文件中分离出二元组*/ private void Seperate() { 35

编译原理经典算法的可视化实现 string str1, str2,str3; string strLine; string[] strArray; char[] charArray=new Char []{' '}; while (!(File.Exists(\))) ; StreamReader sr = File.OpenText(\); str1 = null; str2 = null; str3 = null; while ((strLine = sr.ReadLine()) != null) { strArray = strLine.Split(charArray); str1 = strArray[0].Trim(); str2 = strArray[1].Trim(); str3 = strArray[2].Trim(); //数符 int length; if (judge(str2) == 0) { int j; length = str1.Length ; for (j = 0; j < length; j++) { changecolor(); if (j == 0) draw(4); else draw(5); autoEvent.WaitOne(); } changecolor(); draw(6); i--; inputListview(str1, str2,str3); 36

联系客服:779662525#qq.com(#替换为@)