예제 #1
0
 public void AddDFA(string[] input, WordType type)
 {
     RegularGrammer rg = new RegularGrammer(input);
     NFA nfa = new NFA(rg);
     DFA dfa = new DFA(nfa);
     if (!DFAs.ContainsKey(type))
     {
         DFAs.Add(type, dfa);
     }
     else
     {
         DFAs[type] = dfa;
     }
 }
예제 #2
0
        public void AddDFA(string[] input, WordType type)
        {
            RegularGrammer rg  = new RegularGrammer(input);
            NFA            nfa = new NFA(rg);
            DFA            dfa = new DFA(nfa);

            if (!DFAs.ContainsKey(type))
            {
                DFAs.Add(type, dfa);
            }
            else
            {
                DFAs[type] = dfa;
            }
        }
예제 #3
0
        public NFA(RegularGrammer rg)
        {
            StatusMap = new Dictionary <int, Status>();
            Dictionary <char, int> Vn_dic = new Dictionary <char, int>();

            Vt = new HashSet <char>();
            char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0];

            for (int i = 0; i < rg.Vt.Count; ++i)
            {
                char ch = rg.Vt.ElementAt(i);
                Vt.Add(ch);
            }

            for (int i = 0; i < rg.Vn.Count; ++i)
            {
                char ch = rg.Vn.ElementAt(i);
                Vn_dic.Add(ch, i);
                StatusMap.Add(i, new Status(i, 0));
            }
            this.Start = Vn_dic[rg.Start];
            this.End   = rg.Vn.Count;
            StatusMap.Add(rg.Vn.Count, new Status(rg.Vn.Count, 1));
            foreach (Production pro in rg.Productions)
            {
                int st = Vn_dic[pro.Left];
                int next;
                if (pro.Right[0] == empty || pro.Right.Length == 1)
                {
                    next = End;
                }
                else
                {
                    next = Vn_dic[pro.Right[1]];
                }
                if (!StatusMap[st].Next.ContainsKey(pro.Right[0]))
                {
                    StatusMap[st].Next.Add(pro.Right[0], new HashSet <int>());
                }
                StatusMap[st].Next[pro.Right[0]].Add(next);
            }
        }
예제 #4
0
        public NFA(RegularGrammer rg)
        {
            StatusMap = new Dictionary<int, Status>();
            Dictionary<char, int> Vn_dic = new Dictionary<char,int >();
            Vt=new HashSet<char>();
            char empty=System.Configuration.ConfigurationManager.AppSettings["Empty"][0];
            for (int i = 0; i < rg.Vt.Count; ++i)
            {
                char ch = rg.Vt.ElementAt(i);
                Vt.Add(ch);
            }

            for (int i = 0; i < rg.Vn.Count; ++i)
            {
                char ch = rg.Vn.ElementAt(i);
                Vn_dic.Add(ch, i);
                StatusMap.Add(i, new Status(i, 0));
            }
            this.Start = Vn_dic[rg.Start];
            this.End = rg.Vn.Count;
            StatusMap.Add(rg.Vn.Count, new Status(rg.Vn.Count, 1));
            foreach (Production pro in rg.Productions)
            {
                int st = Vn_dic[pro.Left];
                int next;
                if (pro.Right[0] == empty || pro.Right.Length == 1)
                {
                    next = End;
                }
                else
                {
                    next=Vn_dic[pro.Right[1]];
                }
                if (!StatusMap[st].Next.ContainsKey(pro.Right[0]))
                    StatusMap[st].Next.Add(pro.Right[0], new HashSet<int>());
                StatusMap[st].Next[pro.Right[0]].Add(next);
            }
        }