コード例 #1
0
ファイル: NFATable.cs プロジェクト: JackWangCUMT/lcc-1
        /// <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);
        }
コード例 #2
0
ファイル: NFATable.cs プロジェクト: JackWangCUMT/lcc-1
        /// <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);
        }
コード例 #3
0
ファイル: NFATable.cs プロジェクト: JackWangCUMT/lcc-1
        /// <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);
        }