📄 frmmain.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace SimpleLL1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textboxEndall;
private System.Windows.Forms.TextBox textboxNotEndall;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textboxLabel;
private System.Windows.Forms.Button btnSaveSymbols;
private System.Windows.Forms.Button btnLoadSymbols;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnSaveProducts;
private System.Windows.Forms.Button btnLoadProducts;
private System.Windows.Forms.Button btnAddProduct;
private System.Windows.Forms.Button btnDeleltProduct;
private System.Windows.Forms.TabControl tabcolMain;
private System.Windows.Forms.TabPage tabpageLang;
private System.Windows.Forms.TextBox textboxInput;
private System.Windows.Forms.TabPage tabpageProducts;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label lblNotes;
private System.Windows.Forms.TabPage tabpageCheck;
private System.Windows.Forms.ListBox listboxProducts;
private AxSHDocVw.AxWebBrowser brwResult;
private System.Windows.Forms.SaveFileDialog sfiledlg;
private System.Windows.Forms.Button btnTuichu;
private System.Windows.Forms.OpenFileDialog ofiledlg;
private System.Windows.Forms.Button btnOKSymbols;
private System.Windows.Forms.Button btnEditSymbols;
private System.Windows.Forms.Button btnCheckString;
public static bool showButtons, showAddress, showStatus = true;
public static System.Object nullObject = 0;
public static String str = "";
public static System.Object nullObjStr = str;
ArrayList emptyList=new ArrayList(); //用来记录空字符串
ArrayList LeftItem=new ArrayList(); //用来记录有多少个不同的左部
ArrayList NotEndSet=new ArrayList(); //使用到的非终结符
ArrayList EndSet=new ArrayList(); //使用到的非终结符
string strAnalysisTable=""; //最后的分析表
private System.Windows.Forms.Button btnExport;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TextBox textboxTestString;
private System.Windows.Forms.Button btnAbout;
//Queue queue;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.tabcolMain = new System.Windows.Forms.TabControl();
this.tabpageCheck = new System.Windows.Forms.TabPage();
this.btnExport = new System.Windows.Forms.Button();
this.btnCheckString = new System.Windows.Forms.Button();
this.brwResult = new AxSHDocVw.AxWebBrowser();
this.textboxTestString = new System.Windows.Forms.TextBox();
this.tabpageLang = new System.Windows.Forms.TabPage();
this.btnTuichu = new System.Windows.Forms.Button();
this.lblNotes = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.btnDeleltProduct = new System.Windows.Forms.Button();
this.btnAddProduct = new System.Windows.Forms.Button();
this.btnLoadProducts = new System.Windows.Forms.Button();
this.btnSaveProducts = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textboxInput = new System.Windows.Forms.TextBox();
this.listboxProducts = new System.Windows.Forms.ListBox();
this.tabpageProducts = new System.Windows.Forms.TabPage();
this.btnEditSymbols = new System.Windows.Forms.Button();
this.btnOKSymbols = new System.Windows.Forms.Button();
this.btnLoadSymbols = new System.Windows.Forms.Button();
this.btnSaveSymbols = new System.Windows.Forms.Button();
this.textboxLabel = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textboxEndall = new System.Windows.Forms.TextBox();
this.textboxNotEndall = new System.Windows.Forms.TextBox();
this.ofiledlg = new System.Windows.Forms.OpenFileDialog();
this.sfiledlg = new System.Windows.Forms.SaveFileDialog();
this.btnAbout = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.tabcolMain.SuspendLayout();
this.tabpageCheck.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.brwResult)).BeginInit();
this.tabpageLang.SuspendLayout();
this.tabpageProducts.SuspendLayout();
this.SuspendLayout();
//
// tabcolMain
//
this.tabcolMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabcolMain.Controls.Add(this.tabpageCheck);
this.tabcolMain.Controls.Add(this.tabpageLang);
this.tabcolMain.Controls.Add(this.tabpageProducts);
this.tabcolMain.Location = new System.Drawing.Point(0, 16);
this.tabcolMain.Name = "tabcolMain";
this.tabcolMain.SelectedIndex = 0;
this.tabcolMain.Size = new System.Drawing.Size(520, 384);
this.tabcolMain.TabIndex = 0;
//
// tabpageCheck
//
this.tabpageCheck.Controls.Add(this.btnExport);
this.tabpageCheck.Controls.Add(this.btnCheckString);
this.tabpageCheck.Controls.Add(this.brwResult);
this.tabpageCheck.Controls.Add(this.textboxTestString);
this.tabpageCheck.Location = new System.Drawing.Point(4, 21);
this.tabpageCheck.Name = "tabpageCheck";
this.tabpageCheck.Size = new System.Drawing.Size(512, 359);
this.tabpageCheck.TabIndex = 2;
this.tabpageCheck.Text = "输入符合串";
//
// btnExport
//
this.btnExport.Location = new System.Drawing.Point(432, 16);
this.btnExport.Name = "btnExport";
this.btnExport.Size = new System.Drawing.Size(64, 24);
this.btnExport.TabIndex = 3;
this.btnExport.Text = "导出(&E)";
this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
//
// btnCheckString
//
this.btnCheckString.Location = new System.Drawing.Point(360, 16);
this.btnCheckString.Name = "btnCheckString";
this.btnCheckString.Size = new System.Drawing.Size(64, 24);
this.btnCheckString.TabIndex = 2;
this.btnCheckString.Text = "检测(&C)";
this.btnCheckString.Click += new System.EventHandler(this.btnCheckString_Click);
//
// brwResult
//
this.brwResult.ContainingControl = this;
this.brwResult.Enabled = true;
this.brwResult.Location = new System.Drawing.Point(8, 48);
this.brwResult.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("brwResult.OcxState")));
this.brwResult.Size = new System.Drawing.Size(496, 296);
this.brwResult.TabIndex = 1;
//
// textboxTestString
//
this.textboxTestString.Location = new System.Drawing.Point(8, 16);
this.textboxTestString.Name = "textboxTestString";
this.textboxTestString.Size = new System.Drawing.Size(328, 21);
this.textboxTestString.TabIndex = 0;
this.textboxTestString.Text = "";
//
// tabpageLang
//
this.tabpageLang.Controls.Add(this.btnTuichu);
this.tabpageLang.Controls.Add(this.lblNotes);
this.tabpageLang.Controls.Add(this.label4);
this.tabpageLang.Controls.Add(this.btnDeleltProduct);
this.tabpageLang.Controls.Add(this.btnAddProduct);
this.tabpageLang.Controls.Add(this.btnLoadProducts);
this.tabpageLang.Controls.Add(this.btnSaveProducts);
this.tabpageLang.Controls.Add(this.label1);
this.tabpageLang.Controls.Add(this.textboxInput);
this.tabpageLang.Controls.Add(this.listboxProducts);
this.tabpageLang.Location = new System.Drawing.Point(4, 21);
this.tabpageLang.Name = "tabpageLang";
this.tabpageLang.Size = new System.Drawing.Size(512, 359);
this.tabpageLang.TabIndex = 0;
this.tabpageLang.Text = "语言设置";
//
// btnTuichu
//
this.btnTuichu.Location = new System.Drawing.Point(480, 48);
this.btnTuichu.Name = "btnTuichu";
this.btnTuichu.Size = new System.Drawing.Size(24, 24);
this.btnTuichu.TabIndex = 9;
this.btnTuichu.Text = "→";
this.btnTuichu.Click += new System.EventHandler(this.btnTuichu_Click);
//
// lblNotes
//
this.lblNotes.ForeColor = System.Drawing.SystemColors.HotTrack;
this.lblNotes.Location = new System.Drawing.Point(288, 88);
this.lblNotes.Name = "lblNotes";
this.lblNotes.Size = new System.Drawing.Size(96, 64);
this.lblNotes.TabIndex = 8;
this.lblNotes.Text = "注意:1.第一个表达式的左部为该文法开始符 2.$符号为空串";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(248, 16);
this.label4.TabIndex = 7;
this.label4.Text = "表达式列表:";
//
// btnDeleltProduct
//
this.btnDeleltProduct.Location = new System.Drawing.Point(424, 120);
this.btnDeleltProduct.Name = "btnDeleltProduct";
this.btnDeleltProduct.Size = new System.Drawing.Size(72, 24);
this.btnDeleltProduct.TabIndex = 6;
this.btnDeleltProduct.Text = "删除(&D)";
this.btnDeleltProduct.Click += new System.EventHandler(this.btnDeleltProduct_Click);
//
// btnAddProduct
//
this.btnAddProduct.Location = new System.Drawing.Point(424, 88);
this.btnAddProduct.Name = "btnAddProduct";
this.btnAddProduct.Size = new System.Drawing.Size(72, 24);
this.btnAddProduct.TabIndex = 5;
this.btnAddProduct.Text = "添加(&A)";
this.btnAddProduct.Click += new System.EventHandler(this.btnAddProduct_Click);
//
// btnLoadProducts
//
this.btnLoadProducts.Location = new System.Drawing.Point(400, 304);
this.btnLoadProducts.Name = "btnLoadProducts";
this.btnLoadProducts.Size = new System.Drawing.Size(104, 24);
this.btnLoadProducts.TabIndex = 4;
this.btnLoadProducts.Text = "加载列表(&L)";
this.btnLoadProducts.Click += new System.EventHandler(this.btnLoadProducts_Click);
//
// btnSaveProducts
//
this.btnSaveProducts.Location = new System.Drawing.Point(400, 272);
this.btnSaveProducts.Name = "btnSaveProducts";
this.btnSaveProducts.Size = new System.Drawing.Size(104, 24);
this.btnSaveProducts.TabIndex = 3;
this.btnSaveProducts.Text = "保存列表(&S)";
this.btnSaveProducts.Click += new System.EventHandler(this.btnSaveProducts_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(296, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(192, 16);
this.label1.TabIndex = 2;
this.label1.Text = "表达式输入:";
//
// textboxInput
//
this.textboxInput.Location = new System.Drawing.Point(296, 48);
this.textboxInput.Name = "textboxInput";
this.textboxInput.Size = new System.Drawing.Size(176, 21);
this.textboxInput.TabIndex = 1;
this.textboxInput.Text = "";
//
// listboxProducts
//
this.listboxProducts.ItemHeight = 12;
this.listboxProducts.Location = new System.Drawing.Point(8, 48);
this.listboxProducts.Name = "listboxProducts";
this.listboxProducts.Size = new System.Drawing.Size(272, 280);
this.listboxProducts.TabIndex = 0;
//
// tabpageProducts
//
this.tabpageProducts.Controls.Add(this.btnEditSymbols);
this.tabpageProducts.Controls.Add(this.btnOKSymbols);
this.tabpageProducts.Controls.Add(this.btnLoadSymbols);
this.tabpageProducts.Controls.Add(this.btnSaveSymbols);
this.tabpageProducts.Controls.Add(this.textboxLabel);
this.tabpageProducts.Controls.Add(this.label3);
this.tabpageProducts.Controls.Add(this.label2);
this.tabpageProducts.Controls.Add(this.textboxEndall);
this.tabpageProducts.Controls.Add(this.textboxNotEndall);
this.tabpageProducts.Location = new System.Drawing.Point(4, 21);
this.tabpageProducts.Name = "tabpageProducts";
this.tabpageProducts.Size = new System.Drawing.Size(512, 359);
this.tabpageProducts.TabIndex = 1;
this.tabpageProducts.Text = "符号集设置";
//
// btnEditSymbols
//
this.btnEditSymbols.Location = new System.Drawing.Point(384, 280);
this.btnEditSymbols.Name = "btnEditSymbols";
this.btnEditSymbols.Size = new System.Drawing.Size(96, 24);
this.btnEditSymbols.TabIndex = 10;
this.btnEditSymbols.Text = "编辑(&E)";
this.btnEditSymbols.Click += new System.EventHandler(this.btnEditSymbols_Click);
//
// btnOKSymbols
//
this.btnOKSymbols.Location = new System.Drawing.Point(384, 312);
this.btnOKSymbols.Name = "btnOKSymbols";
this.btnOKSymbols.Size = new System.Drawing.Size(96, 24);
this.btnOKSymbols.TabIndex = 8;
this.btnOKSymbols.Text = "确定(&O)";
this.btnOKSymbols.Click += new System.EventHandler(this.btnOKSymbols_Click);
//
// btnLoadSymbols
//
this.btnLoadSymbols.Location = new System.Drawing.Point(384, 248);
this.btnLoadSymbols.Name = "btnLoadSymbols";
this.btnLoadSymbols.Size = new System.Drawing.Size(96, 24);
this.btnLoadSymbols.TabIndex = 7;
this.btnLoadSymbols.Text = "加载(&L)";
this.btnLoadSymbols.Click += new System.EventHandler(this.btnLoadSymbols_Click);
//
// btnSaveSymbols
//
this.btnSaveSymbols.Location = new System.Drawing.Point(384, 216);
this.btnSaveSymbols.Name = "btnSaveSymbols";
this.btnSaveSymbols.Size = new System.Drawing.Size(96, 24);
this.btnSaveSymbols.TabIndex = 6;
this.btnSaveSymbols.Text = "保存(&S)";
this.btnSaveSymbols.Click += new System.EventHandler(this.btnSaveSymbols_Click);
//
// textboxLabel
//
this.textboxLabel.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textboxLabel.Location = new System.Drawing.Point(328, 56);
this.textboxLabel.Multiline = true;
this.textboxLabel.Name = "textboxLabel";
this.textboxLabel.ReadOnly = true;
this.textboxLabel.Size = new System.Drawing.Size(152, 88);
this.textboxLabel.TabIndex = 5;
this.textboxLabel.Text = "说明:\r\n\r\n1.非终结符集和终结符集均为一行一个字符\r\n2.\'#\' 和 \'$\' 符号均为空串,不要使用";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(168, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(54, 17);
this.label3.TabIndex = 4;
this.label3.Text = "终结符集";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 17);
this.label2.TabIndex = 3;
this.label2.Text = "非终结符集";
//
// textboxEndall
//
this.textboxEndall.Location = new System.Drawing.Point(160, 56);
this.textboxEndall.Multiline = true;
this.textboxEndall.Name = "textboxEndall";
this.textboxEndall.ReadOnly = true;
this.textboxEndall.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textboxEndall.Size = new System.Drawing.Size(136, 280);
this.textboxEndall.TabIndex = 1;
this.textboxEndall.Text = "";
//
// textboxNotEndall
//
this.textboxNotEndall.Location = new System.Drawing.Point(8, 56);
this.textboxNotEndall.Multiline = true;
this.textboxNotEndall.Name = "textboxNotEndall";
this.textboxNotEndall.ReadOnly = true;
this.textboxNotEndall.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textboxNotEndall.Size = new System.Drawing.Size(144, 280);
this.textboxNotEndall.TabIndex = 0;
this.textboxNotEndall.Text = "";
//
// ofiledlg
//
this.ofiledlg.Filter = "*.txt|*.txt";
//
// btnAbout
//
this.btnAbout.Location = new System.Drawing.Point(344, 408);
this.btnAbout.Name = "btnAbout";
this.btnAbout.Size = new System.Drawing.Size(72, 24);
this.btnAbout.TabIndex = 1;
this.btnAbout.Text = "关于(&A)";
this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(424, 408);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(72, 24);
this.btnExit.TabIndex = 2;
this.btnExit.Text = "退出(&X)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(520, 437);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnAbout);
this.Controls.Add(this.tabcolMain);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "frmMain";
this.Text = "简单LL(1)文法示例";
this.Load += new System.EventHandler(this.frmMain_Load);
this.tabcolMain.ResumeLayout(false);
this.tabpageCheck.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.brwResult)).EndInit();
this.tabpageLang.ResumeLayout(false);
this.tabpageProducts.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void frmMain_Load(object sender, System.EventArgs e)
{
}
#region 添加表达式到列表
private void btnAddProduct_Click(object sender, System.EventArgs e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -