• 大小: 84KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签: C#实现LL1  LL1文法  

资源简介

C#实现LL1文法编译原理课设

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Analysis
{
    class Arithmetic
    {
        char preChar;
        List option = new List();
        List First = new List();
        public List getFirst
        {
            get
            {
                return First;
            }
        }
        public Arithmetic(List option)
        {
            this.option = option;
        }
        public List FindLeftVn(char Vn)
        {
            List ls = new List();
            foreach (string s in option)
            {
                if (Vn == s[0])
                {
                    ls.Add(s);
                }
            }
            return ls;
        }
        public void FindFirst(char Vn)
        {
            List option = FindLeftVn(Vn);
            foreach (string op in option)
            {
                if ((Char.IsUpper(op[3])))
                {
                    FindFirst(op[3]);
                }
                else
                {
                    First.Add(new sponser(preChar op[3]));
                }
            }
        }
        public void GetAllFirst()
        {
            First.Clear();
            foreach (char c in FirstDeleteVn())
            {
                preChar = c;
                FindFirst(c);
            }
            DeleteFirstResultVn();
            CombineResult();
        }
        public List FirstDeleteVn()           //获取候选式左边的非终结符
        {
            List lc = new List();
            foreach (string s in option)
            {
                lc.Add(s[0]);
            }
            for (int i = lc.Count - 1; i >= 0; i--)
            {
                if (lc.IndexOf(lc[i]) != i)
                {
                    lc.RemoveAt(i);
                }
            }
            return lc;
        }
        public void DeleteFirstResultVn()           //删除相同的非终结符的first集
        {
            for (int j = 0; j < First.Count - 1; j++)
            {
                for (int m = First.Count - 1; m > j; m--)
                {
                    if (First[m].getVn() == First[j].getVn())
                    {
                        foreach (char c in First[m].getfirst())
                        {
                            if (!First[j].getfirst().Contains(c))
                            {
                                First[j].addfirst(c);
                            }
                        }
                        First.RemoveAt(m);
                    }
                }
            }
        }
        public void CombineResult()     //含有空
        {
            foreach (sponser s in First)
            {
                List ls = FindLeftVn(s.getVn());
                int isEmpty = 0;
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        914  2009-11-06 14:12  Analysis\Analysis.sln

    ..A..H.     34304  2009-11-16 16:16  Analysis\Analysis.suo

     文件       3996  2009-11-13 14:41  Analysis\Analysis\Analysis.csproj

     文件      12448  2009-11-13 14:28  Analysis\Analysis\Arithmetic.cs

     文件       1413  2009-11-08 19:13  Analysis\Analysis\Grammar.cs

     文件        489  2009-11-06 15:49  Analysis\Analysis\Program.cs

     文件        816  2009-11-08 20:28  Analysis\Analysis\sposer.cs

     文件       1074  2009-11-13 15:08  Analysis\Analysis\StrToOption.cs

     文件        680  2009-11-08 22:22  Analysis\Analysis\TableSort.cs

     文件       3557  2009-11-15 13:55  Analysis\Analysis\Table.cs

     文件       6223  2009-11-16 16:07  Analysis\Analysis\Form1.resx

     文件      20527  2009-11-16 16:07  Analysis\Analysis\Form1.Designer.cs

     文件      12293  2009-11-16 16:07  Analysis\Analysis\Form1.cs

     文件       1356  2009-11-06 14:12  Analysis\Analysis\Properties\AssemblyInfo.cs

     文件       2866  2009-11-06 14:12  Analysis\Analysis\Properties\Resources.Designer.cs

     文件       5612  2009-11-06 14:12  Analysis\Analysis\Properties\Resources.resx

     文件       1093  2009-11-06 14:12  Analysis\Analysis\Properties\Settings.Designer.cs

     文件        249  2009-11-06 14:12  Analysis\Analysis\Properties\Settings.settings

     文件       4708  2009-11-16 16:07  Analysis\Analysis\obj\Debug\Analysis.csproj.FileListAbsolute.txt

     文件      29184  2009-11-16 16:07  Analysis\Analysis\obj\Debug\Analysis.exe

     文件        180  2009-11-16 16:07  Analysis\Analysis\obj\Debug\Analysis.Form1.resources

     文件      87552  2009-11-16 16:07  Analysis\Analysis\obj\Debug\Analysis.pdb

     文件        180  2009-11-13 15:38  Analysis\Analysis\obj\Debug\Analysis.Properties.Resources.resources

     文件        847  2009-11-16 16:07  Analysis\Analysis\obj\Debug\Analysis.csproj.GenerateResource.Cache

     文件      29184  2009-11-16 16:07  Analysis\Analysis\bin\Debug\Analysis.exe

     文件      87552  2009-11-16 16:07  Analysis\Analysis\bin\Debug\Analysis.pdb

     文件      14328  2009-11-16 16:07  Analysis\Analysis\bin\Debug\Analysis.vshost.exe

     文件        490  2007-07-21 01:33  Analysis\Analysis\bin\Debug\Analysis.vshost.exe.manifest

     目录          0  2009-11-16 22:36  Analysis\Analysis\obj\Debug\TempPE

     目录          0  2009-11-16 22:36  Analysis\Analysis\obj\Debug\Refactor

............此处省略13个文件信息

评论

共有 条评论