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

编译原理经典算法的可视化实现 } //标识符 if (judge(str2) ==1) { int j; length = str1.Length ; for (j = 0; j< length;j++) { changecolor(); if (j == 0) draw(1); else draw(2);

autoEvent.WaitOne(); }

changecolor(); draw(3); i--;

inputListview(str1, str2,str3); }

if (judge(str2) == 2) {

int j;

length = str1.Length ; for (j= 0; j < length; j++) {

changecolor();

autoEvent.WaitOne(); }

changecolor(); i--;

inputListview(str1, str2,str3);

}

if(judge(str2)==3) {

changecolor();

autoEvent.WaitOne(); }

37

编译原理经典算法的可视化实现 } sr.Close(); } /*输入二元组*/ private void inputListview(string str1,string str2,string str3) { ListViewItem item = new ListViewItem(); item.Text = str1; item.SubItems.Add(str2); item.SubItems.Add(str3); listShow.Items.Add(item); listShow.Update(); } /*画图*/ private void paint() { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Black, 2); int x = rtSource.Location.X + rtSource.Width + 50; int y = rtSource.Location.Y; int width = this.Width - x - 100; int heigh = this.Height - listShow.Height - 220; Rectangle rect = new Rectangle(x, y, width, heigh); g.DrawRectangle(p, rect); //画S Rectangle rect1 = new Rectangle(x + 30, y + 45, 50, 50); g.DrawEllipse(p, rect1); Brush brush = new SolidBrush(Color.LawnGreen); Font font = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font, brush, x + 40, y + 55); //画A Rectangle rect2 = new Rectangle(x + 120, y + 45, 50, 50); g.DrawEllipse(p, rect2); Brush brush1 = new SolidBrush(Color.LawnGreen); Brush bru = new SolidBrush(Color.IndianRed); Font font1 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font1, brush1, x + 130, y + 45); //画B Rectangle rect3 = new Rectangle(x + 200, y + 45, 50, 50); Rectangle rect31 = new Rectangle(x + 210, y + 55, 35, 35); g.DrawEllipse(p, rect3); 38

编译原理经典算法的可视化实现 g.DrawEllipse(p, rect31); Brush brush2 = new SolidBrush(Color.LawnGreen); Font font2 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font2, brush2, x + 210, y + 55); //画C Rectangle rect4 = new Rectangle(x + 120, y + 140, 50, 50); g.DrawEllipse(p, rect4); Brush brush3 = new SolidBrush(Color.LawnGreen); Font font3 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font3, brush1, x + 130, y + 150); //画D Rectangle rect5 = new Rectangle(x + 200, y + 140, 50, 50); Rectangle rect51 = new Rectangle(x + 210, y + 150, 35, 35); g.DrawEllipse(p, rect5); g.DrawEllipse(p, rect51); Brush brush5 = new SolidBrush(Color.LawnGreen); Font font5 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font5, brush5, x + 210, y + 150); //画线 Pen pline = new Pen(Color.Black, 5); pline.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pline.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; //画s->A g.DrawLine(pline, x + 80, y + 70, x + 120, y + 70); g.DrawString(\, font, bru, x + 80, y + 35); //画s->c g.DrawLine(pline, x + 80, y + 70, x + 120, y + 155); g.DrawString(\, font, bru, x + 70, y + 90); //A->B g.DrawLine(pline, x + 170, y + 70, x + 200, y + 70); g.DrawString(\, font, bru, x + 170, y + 35); //C->D g.DrawLine(pline, x + 170, y + 165, x + 200, y + 165); g.DrawString(\, font, bru, x + 170, y + 130); //画A->A Point[] points = new Point[3]; points[0] = new Point(x + 124, y + 55); points[1] = new Point(x + 140, y + 25); points[2] = new Point(x + 165, y + 55); g.DrawString(\, font, bru, x + 100, y - 5); g.DrawCurve(pline, points); //画C->C Point[] point = new Point[3]; point[0] = new Point(x + 124, y + 150); 39

编译原理经典算法的可视化实现 point[1] = new Point(x + 140, y + 120); point[2] = new Point(x + 165, y + 150); g.DrawString(\, font, bru, x + 130, y + 90); g.DrawCurve(pline, point); } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Pen p=new Pen(Color.Black ,2); int x = rtSource.Location.X + rtSource.Width + 50; int y=rtSource .Location .Y; int width = this.Width - x - 100; int heigh = this.Height - listShow.Height - 250; Rectangle rect = new Rectangle(x,y , width,heigh ); g.DrawRectangle(p, rect); //画S Rectangle rect1=new Rectangle (x+30,y+45,50,50); g.DrawEllipse(p, rect1); Brush brush = new SolidBrush(Color.LawnGreen); Font font = new Font(\楷体GB-2312\,25,FontStyle.Bold); g.DrawString(\, font, brush, x + 40, y + 55); //画A Rectangle rect2 = new Rectangle(x + 120, y + 45, 50, 50); g.DrawEllipse(p, rect2); Brush brush1 = new SolidBrush(Color.LawnGreen); Brush bru = new SolidBrush(Color.IndianRed); Font font1 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font1, brush1, x + 130, y + 45); //画B Rectangle rect3 = new Rectangle(x + 200, y + 45, 50, 50); Rectangle rect31 = new Rectangle(x + 210, y + 55, 35, 35); g.DrawEllipse(p, rect3); g.DrawEllipse(p, rect31); Brush brush2 = new SolidBrush(Color.LawnGreen); Font font2 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font2, brush2, x + 210, y +55); //画C Rectangle rect4 = new Rectangle(x + 120, y + 140, 50, 50); g.DrawEllipse(p, rect4); Brush brush3 = new SolidBrush(Color.LawnGreen); Font font3 = new Font(\楷体GB-2312\, 25, FontStyle.Bold); g.DrawString(\, font3, brush1, x + 130, y + 150); //画D 40