예제 #1
0
파일: AST.cs 프로젝트: JackWangCUMT/lcc-1
        protected internal override NFATable GenNFATable(int[] map, List <char[]> revMap)
        {
            NFATable ret = new NFATable(map, revMap);

            ret.AddState();
            ret.SetStateFinal(1);
            ret.AddTransition(0, 1, set);
            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Cat two NFATables together.
        /// </summary>
        /// <param name="nfa1"> The first NFATable. </param>
        /// <param name="nfa2"> The second NFATable. </param>
        /// <returns> A new NFATable. </returns>
        public static NFATable operator +(NFATable nfa1, NFATable nfa2)
        {
            NFATable ret    = nfa1.Merge(nfa2);
            int      offset = nfa1.table.Count();

            // Connect this.final to other.start.
            foreach (int final in nfa1.finals)
            {
                ret.AddEpsilonTransition(final, offset);
            }

            // Set the final states.
            foreach (int final in nfa2.finals)
            {
                ret.SetStateFinal(final + offset);
            }

            return(ret);
        }
예제 #3
0
        /// <summary>
        /// Or operation.
        /// </summary>
        /// <param name="nfa1"> The first NFATable. </param>
        /// <param name="nfa2"> The second NFATable. </param>
        /// <returns> A new NFATable. </returns>
        public static NFATable operator |(NFATable nfa1, NFATable nfa2)
        {
            NFATable ret    = nfa1.Merge(nfa2);
            int      offset = nfa1.table.Count();

            ret.AddEpsilonTransition(0, offset);

            foreach (int final in nfa1.finals)
            {
                ret.SetStateFinal(final);
            }

            int end = nfa1.finals.First();

            foreach (int final in nfa2.finals)
            {
                ret.AddEpsilonTransition(final + offset, end);
            }

            return(ret);
        }
예제 #4
0
        /// <summary>
        /// Match one or more.
        /// </summary>
        /// <returns> A new NFATable. </returns>
        public NFATable Ques()
        {
            NFATable nfa = new NFATable(map, revMap);

            nfa.AddState();
            nfa.AddEpsilonTransition(0, 1);

            NFATable ret = nfa.Merge(this);

            ret.AddEpsilonTransition(0, 2);

            ret.SetStateFinal(1);

            int offset = 2;

            foreach (int final in finals)
            {
                ret.AddEpsilonTransition(final + offset, 1);
            }

            return(ret);
        }