Exemplo n.º 1
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.º 2
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;
        }
Exemplo n.º 3
0
 /********************************************************
  *    Function: mimic
  *******************************************************/
 public void mimic
 (
     CSet Set
 )
 {
     m_complement = Set.m_complement;
     m_set        = (SparseBitSet)Set.m_set.Clone();
 }
Exemplo n.º 4
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.º 5
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.º 6
0
        /***************************************************************
         *    Function: dodash
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void dodash
        (
            CSet Set
        )
        {
            int first = -1;

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

            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 (DESCENT_DEBUG)
            {
                CUtility.leave("dodash", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }