예제 #1
0
        //语法
        private void Button3_Click(object sender, EventArgs e)
        {
            lexical = new Lexical.Lexical();
            ArrayList source = lexical.ReadFromScreen(richTextBox1.Text);

            lexical.GetToken(source);

            if (lexical == null)  //如果为空,退出
            {
                return;
            }
            grammar = new Grammar.Grammar();
            grammar.Init();
            ArrayList infos = new ArrayList();                 //语法推导过程

            if (lexical.Errors.Count == 0)
            {
                infos = grammar.SyntaxAnalysis(lexical.Coding, lexical.Errors);
            }
            richTextBox3.Text = "";
            foreach (string info in infos)
            {
                richTextBox3.Text = richTextBox3.Text + info + "\r\n";
            }
            ArrayList errorInfos = lexical.ErrorInfo();      //推导过程中的错误

            foreach (string error in errorInfos)
            {
                richTextBox3.Text = richTextBox3.Text + error + "\r\n";
            }
            tree = grammar.treeView;
        }
예제 #2
0
        //语义
        private void Button2_Click(object sender, EventArgs e)
        {
            lexical = new Lexical.Lexical();  //执行语义前,先执行词法和语法部分
            ArrayList source = lexical.ReadFromScreen(richTextBox1.Text);

            lexical.GetToken(source);

            Semantics.IdentifierAnalysis identifier = new Semantics.IdentifierAnalysis(lexical.Coding, lexical.Errors);
            Semantics.MidCode            midCode    = new Semantics.MidCode(lexical.Coding, lexical.Errors);
            identifier.Init();
            ArrayList VarSet      = identifier.VarSet; //初始化变量、数组、函数、多维数组集合
            ArrayList ListSet     = identifier.ListSet;
            ArrayList FunctionSet = identifier.FunctionSet;
            ArrayList ArraySet    = identifier.ArraySet;

            if (lexical.Errors.Count == 0)
            {
                midCode.Init(VarSet, ListSet, FunctionSet, ArraySet);
            }

            ArrayList Output = midCode.OutputInfo;

            richTextBox3.Text = "";
            foreach (string info in Output)
            {
                richTextBox3.Text = richTextBox3.Text + info + "\r\n";
            }
            ArrayList errorInfos = lexical.ErrorInfo();      //推导过程中的错误

            foreach (string error in errorInfos)
            {
                richTextBox3.Text = richTextBox3.Text + error + "\r\n";
            }
        }
예제 #3
0
        //词法
        private void Button1_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text == "")
            {
                return;
            }
            lexical = new Lexical.Lexical();
            ArrayList source = lexical.ReadFromScreen(richTextBox1.Text); //源文件字符数组

            lexical.GetToken(source);
            string[] infos = lexical.SaveToken();
            richTextBox3.Text = "";
            foreach (string info in infos)
            {
                richTextBox3.Text = richTextBox3.Text + info + "\r\n";
            }
            ArrayList errorInfos = lexical.ErrorInfo();      //推导过程中的错误

            foreach (string error in errorInfos)
            {
                richTextBox3.Text = richTextBox3.Text + error + "\r\n";
            }
        }