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

编译原理经典算法的可视化实现 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); 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);

//解释语句

Font fontt = new Font(\楷体GB-2312\, 10, FontStyle.Bold); Brush brush6 = new SolidBrush(Color.OrangeRed); g.DrawString(\单词\, fontt, brush6, x + 300, y +10); g.DrawString(\标识符\, fontt, brush6, x + 300, y +40); g.DrawString(\无符号整数\, fontt, brush6, x + 300, y +70);

41

编译原理经典算法的可视化实现 g.DrawString(\字母\, fontt, brush6, x + 300, y +100); g.DrawString(\数字\, fontt, brush6, x + 300, y +130); g.DrawString(\非字母数字\, fontt, brush6, x + 300, y +160); g.DrawString(\非数字\, fontt, brush6, x + 300, y +190); base.OnPaint(e); } protected override void OnResize(EventArgs e) { Invalidate(); base.OnResize(e); } //动态画线

void drawDirectly(Point start, Point end) {

Graphics g = this.CreateGraphics(); int length = end.X - start.X; int ave = length / 5; int len = start.X;

Pen pline = new Pen(Color.Red , 5);

pline.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; while (len < end.X) {

g.DrawLine(pline, start.X ,start.Y , len + ave-5, end.Y);

System.Threading.Thread.Sleep(speed);//参数以毫秒为单位 len += ave; }

Pen pline1 = new Pen(Color.Orange, 5);

pline1.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pline1.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; g.DrawLine(pline1, start, end); }

void draw2(Point []point) {

Graphics g = this.CreateGraphics(); Pen pline = new Pen(Color.Red, 5);

pline.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pline.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; g.DrawCurve(pline, point);

System.Threading.Thread.Sleep(speed); Pen pline1 = new Pen(Color.Orange, 5);

pline1.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pline1.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;

42

编译原理经典算法的可视化实现 g.DrawCurve(pline1, point); // g.DrawCurve(pline, point); } void draw4(Point start, Point end) { Graphics g = this.CreateGraphics(); Pen pline = new Pen(Color.Red, 5); pline.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; int avex = (end.X - start.X) / 5; int avey = (end.Y - start.Y) / 5; for (int i = 1; i <= 5; i++) {

g.DrawLine(pline, start.X, start.Y,start.X +(i*avex),start.Y+(i*avey)); System.Threading.Thread.Sleep(speed);//参数以毫秒为单位 }

Pen pline1 = new Pen(Color.Orange, 5);

pline1.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; pline1.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; g.DrawLine(pline1, start, end);

}

43