private int original_charset_size; // original charset size

        #endregion Fields

        #region Methods

        public void simplify(CSpec m_spec)
        {
            computeClasses(m_spec); // initialize fields.

            // now rewrite the NFA using our character class mapping.
              IEnumerator e=m_spec.m_nfa_states.elements();
            while ( e.MoveNext() )
            {
                CNfa nfa = (CNfa) e.Current;
                if (nfa.m_edge==CNfa.EMPTY || nfa.m_edge==CNfa.EPSILON)
                    continue; // no change.
                if (nfa.m_edge==CNfa.CCL)
                {
                    CSet ncset = new CSet();
                    ncset.map(nfa.m_set, ccls); // map it.
                    nfa.m_set = ncset;
                }
                else
                { // single character
                    nfa.m_edge = ccls[nfa.m_edge]; // map it.
                }
            }

            // now update m_spec with the mapping.
            m_spec.m_ccls_map = ccls;
            m_spec.m_dtrans_ncols = mapped_charset_size;
        }
Exemplo n.º 2
0
        /********************************************************
         * Function: mimic
         * Description: Converts this NFA state into a copy of
         * the input one.
         *******************************************************/
        public void mimic
        (
            CNfa nfa
        )
        {
            m_edge = nfa.m_edge;

            if (null != nfa.m_set)
            {
                if (null == m_set)
                {
                    m_set = new CSet();
                }
                m_set.mimic(nfa.m_set);
            }
            else
            {
                m_set = null;
            }

            m_next   = nfa.m_next;
            m_next2  = nfa.m_next2;
            m_accept = nfa.m_accept;
            m_anchor = nfa.m_anchor;

            if (null != nfa.m_states)
            {
                m_states = (SparseBitSet)nfa.m_states.Clone();
            }
            else
            {
                m_states = null;
            }
        }
Exemplo n.º 3
0
        private int mapped_charset_size;   // reduced charset size

        public void simplify(CSpec m_spec)
        {
            computeClasses(m_spec); // initialize fields.

            // now rewrite the NFA using our character class mapping.
            IEnumerator e = m_spec.m_nfa_states.elements();

            while (e.MoveNext())
            {
                CNfa nfa = (CNfa)e.Current;
                if (nfa.m_edge == CNfa.EMPTY || nfa.m_edge == CNfa.EPSILON)
                {
                    continue; // no change.
                }
                if (nfa.m_edge == CNfa.CCL)
                {
                    CSet ncset = new CSet();
                    ncset.map(nfa.m_set, ccls); // map it.
                    nfa.m_set = ncset;
                }
                else
                {                                  // single character
                    nfa.m_edge = ccls[nfa.m_edge]; // map it.
                }
            }

            // now update m_spec with the mapping.
            m_spec.m_ccls_map     = ccls;
            m_spec.m_dtrans_ncols = mapped_charset_size;
        }
        /***************************************************************
         * Function: dodash
         * Description: Recursive descent regular expression parser.
         **************************************************************/
        private void dodash
        (
            CSet Set
        )
        {
            int first = -1;

            if (CUtility.DESCENT_DEBUG)
            {
                CUtility.enter("dodash", m_spec.m_lexeme, m_spec.m_current_token);
            }

            while (CLexGen.EOS != m_spec.m_current_token &&
                   CLexGen.CCL_END != m_spec.m_current_token)
            {
                // DASH loses its special meaning if it is first in class.
                if (CLexGen.DASH == m_spec.m_current_token && -1 != first)
                {
                    m_lexGen.advance();
                    // DASH loses its special meaning if it is last in class.
                    if (m_spec.m_current_token == CLexGen.CCL_END)
                    {
                        // 'first' already in Set.
                        Set.add('-');
                        break;
                    }
                    for ( ; first <= m_spec.m_lexeme; ++first)
                    {
                        if (m_spec.m_ignorecase)
                        {
                            Set.addncase((char)first);
                        }
                        else
                        {
                            Set.add(first);
                        }
                    }
                }
                else
                {
                    first = m_spec.m_lexeme;
                    if (m_spec.m_ignorecase)
                    {
                        Set.addncase(m_spec.m_lexeme);
                    }
                    else
                    {
                        Set.add(m_spec.m_lexeme);
                    }
                }

                m_lexGen.advance();
            }

            if (CUtility.DESCENT_DEBUG)
            {
                CUtility.leave("dodash", m_spec.m_lexeme, m_spec.m_current_token);
            }
        }
Exemplo n.º 5
0
 /********************************************************
  * Function: mimic
  *******************************************************/
 public void mimic
 (
     CSet Set
 )
 {
     m_complement = Set.m_complement;
     m_set        = (SparseBitSet)Set.m_set.Clone();
 }
Exemplo n.º 6
0
 /********************************************************
  * Function: CNfa
  *******************************************************/
 public CNfa
 (
 )
 {
     m_edge   = EMPTY;
     m_set    = null;
     m_next   = null;
     m_next2  = null;
     m_accept = null;
     m_anchor = CSpec.NONE;
     m_label  = NO_LABEL;
     m_states = null;
 }
Exemplo n.º 7
0
        /** Map Set using character classes [CSA] */
        public void map(CSet Set, int[] mapping)
        {
            m_complement = Set.m_complement;
            m_set.clearAll();
            IEnumerator e = Set.m_set.elements();

            while (e.MoveNext())
            {
                int old_value = (int)e.Current;
                if (old_value < mapping.Length) // skip unmapped characters
                {
                    m_set.Set(mapping[old_value]);
                }
            }
        }
Exemplo n.º 8
0
 /********************************************************
   Function: CNfa
   *******************************************************/
 public CNfa(
     )
 {
     m_edge = EMPTY;
     m_set = null;
     m_next = null;
     m_next2 = null;
     m_accept = null;
     m_anchor = CSpec.NONE;
     m_label = NO_LABEL;
     m_states = null;
 }
Exemplo n.º 9
0
        /********************************************************
          Function: mimic
          Description: Converts this NFA state into a copy of
          the input one.
          *******************************************************/
        public void mimic(
            CNfa nfa
            )
        {
            m_edge = nfa.m_edge;

            if (null != nfa.m_set)
            {
                if (null == m_set)
                {
                    m_set = new CSet();
                }
                m_set.mimic(nfa.m_set);
            }
            else
            {
                m_set = null;
            }

            m_next = nfa.m_next;
            m_next2 = nfa.m_next2;
            m_accept = nfa.m_accept;
            m_anchor = nfa.m_anchor;

            if (null != nfa.m_states)
            {
                m_states = (SparseBitSet) nfa.m_states.Clone();
            }
            else
            {
                m_states = null;
            }
        }
Exemplo n.º 10
0
        /***************************************************************
          Function: dodash
          Description: Recursive descent regular expression parser.
          **************************************************************/
        private void dodash(
            CSet Set
            )
        {
            int first = -1;

            if (CUtility.DESCENT_DEBUG)
            {
                CUtility.enter("dodash",m_spec.m_lexeme,m_spec.m_current_token);
            }

            while (CLexGen.EOS != m_spec.m_current_token
                && CLexGen.CCL_END != m_spec.m_current_token)
            {
                // DASH loses its special meaning if it is first in class.
                if (CLexGen.DASH == m_spec.m_current_token && -1 != first)
                {
                    m_lexGen.advance();
                    // DASH loses its special meaning if it is last in class.
                    if (m_spec.m_current_token == CLexGen.CCL_END)
                    {
                        // 'first' already in Set.
                        Set.add('-');
                        break;
                    }
                    for ( ; first <= m_spec.m_lexeme; ++first)
                    {
                        if (m_spec.m_ignorecase)
                            Set.addncase((char)first);
                        else
                            Set.add(first);
                    }
                }
                else
                {
                    first = m_spec.m_lexeme;
                    if (m_spec.m_ignorecase)
                        Set.addncase(m_spec.m_lexeme);
                    else
                        Set.add(m_spec.m_lexeme);
                }

                m_lexGen.advance();
            }

            if (CUtility.DESCENT_DEBUG)
            {
                CUtility.leave("dodash",m_spec.m_lexeme,m_spec.m_current_token);
            }
        }
Exemplo n.º 11
0
        /***************************************************************
          Function: printccl
          Description: Debugging routine that outputs readable form
          of character class.
          **************************************************************/
        private void printccl(
            CSet Set
            )
        {
            int i;

            System.Console.Write(" [");
            for (i = 0; i < m_spec.m_dtrans_ncols; ++i)
            {
                if (Set.contains(i))
                {
                    System.Console.Write(interp_int(i));
                }
            }
            System.Console.Write(']');
        }
Exemplo n.º 12
0
 /********************************************************
   Function: mimic
   *******************************************************/
 public void mimic(
     CSet Set
     )
 {
     m_complement = Set.m_complement;
     m_set = (SparseBitSet) Set.m_set.Clone();
 }
Exemplo n.º 13
0
 /** Map Set using character classes [CSA] */
 public void map(CSet Set, int[] mapping)
 {
     m_complement = Set.m_complement;
     m_set.clearAll();
     IEnumerator e=Set.m_set.elements();
     while (e.MoveNext() )
     {
         int old_value =(int)e.Current;
         if (old_value<mapping.Length) // skip unmapped characters
             m_set.Set(mapping[old_value]);
     }
 }