Example #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;
            }
        }
Example #2
0
 /***************************************************************
  * Function: CAcceptAnchor
  **************************************************************/
 CAcceptAnchor
 (
 )
 {
     m_accept = null;
     m_anchor = CSpec.NONE;
 }
        public Vector m_nfa_set; /* Vector of CNfa states in dfa state. */

        #endregion Fields

        #region Constructors

        /***************************************************************
          Function: CBunch
          Description: Constructor.
          **************************************************************/
        public CBunch(
            )
        {
            m_nfa_set = null;
            m_nfa_bit = null;
            m_accept = null;
            m_anchor = CSpec.NONE;
            m_accept_index = -1;
        }
Example #4
0
        public int m_accept_index;     /* CNfa index corresponding to accepting actions. */

        /***************************************************************
         * Function: CBunch
         * Description: Constructor.
         **************************************************************/
        public CBunch
        (
        )
        {
            m_nfa_set      = null;
            m_nfa_bit      = null;
            m_accept       = null;
            m_anchor       = CSpec.NONE;
            m_accept_index = -1;
        }
 /*************************************************************
   Function: CTrans
   ***********************************************************/
 public CDTrans(
     int label,
     CSpec spec
     )
 {
     m_dtrans = new int[spec.m_dtrans_ncols];
     m_accept = null;
     m_anchor = CSpec.NONE;
     m_label = label;
 }
Example #6
0
 /*************************************************************
  * Function: CTrans
  ***********************************************************/
 public CDTrans
 (
     int label,
     CSpec spec
 )
 {
     m_dtrans = new int[spec.m_dtrans_ncols];
     m_accept = null;
     m_anchor = CSpec.NONE;
     m_label  = label;
 }
Example #7
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;
 }
Example #8
0
        /***************************************************************
          Function: CDfa
          **************************************************************/
        public CDfa(
            int label
            )
        {
            m_group = 0;
            m_mark = false;

            m_accept = null;
            m_anchor = CSpec.NONE;

            m_nfa_set = null;
            m_nfa_bit = null;

            m_label = label;
        }
        /***************************************************************
         * Function: mimic
         **************************************************************/
        public void mimic
        (
            CAccept accept
        )
        {
            int elem;

            m_action_read = accept.m_action_read;

            m_action = new char[m_action_read];
            for (elem = 0; elem < m_action_read; ++elem)
            {
                m_action[elem] = accept.m_action[elem];
            }
        }
Example #10
0
        /***************************************************************
         * Function: CDfa
         **************************************************************/
        public CDfa
        (
            int label
        )
        {
            m_group = 0;
            m_mark  = false;

            m_accept = null;
            m_anchor = CSpec.NONE;

            m_nfa_set = null;
            m_nfa_bit = null;

            m_label = label;
        }
        /***************************************************************
          Function: CAccept
          **************************************************************/
        public CAccept(
            CAccept accept
            )
        {
            int elem;

            m_action_read = accept.m_action_read;

            m_action = new char[m_action_read];
            for (elem = 0; elem < m_action_read; ++elem)
            {
                m_action[elem] = accept.m_action[elem];
            }

            m_line_number = accept.m_line_number;
        }
        /***************************************************************
         * Function: CAccept
         **************************************************************/
        public CAccept
        (
            CAccept accept
        )
        {
            int elem;

            m_action_read = accept.m_action_read;

            m_action = new char[m_action_read];
            for (elem = 0; elem < m_action_read; ++elem)
            {
                m_action[elem] = accept.m_action[elem];
            }

            m_line_number = accept.m_line_number;
        }
 /***************************************************************
   Function: CAcceptAnchor
   **************************************************************/
 CAcceptAnchor(
     )
 {
     m_accept = null;
     m_anchor = CSpec.NONE;
 }
Example #14
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;
 }
Example #15
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;
            }
        }
        /***************************************************************
          Function: mimic
          **************************************************************/
        public void mimic(
            CAccept accept
            )
        {
            int elem;

            m_action_read = accept.m_action_read;

            m_action = new char[m_action_read];
            for (elem = 0; elem < m_action_read; ++elem)
            {
                m_action[elem] = accept.m_action[elem];
            }
        }
        /********************************************************
          Function: packAccept
          Description: Packages and returns CAccept
          for action next in input stream.
          *******************************************************/
        public CAccept packAccept(
            )
        {
            CAccept accept;
            char[] action;
            int action_index;
            int brackets;
            bool insinglequotes;
            bool indoublequotes;
            bool instarcomment;
            bool inslashcomment;
            bool escaped;
            bool slashed;

            action = new char[BUFFER_SIZE];
            action_index = 0;

            if (CUtility.DEBUG)
            {
                CUtility.ASSERT(null != this);
                CUtility.ASSERT(null != m_outstream);
                CUtility.ASSERT(null != m_input);
                CUtility.ASSERT(null != m_tokens);
                CUtility.ASSERT(null != m_spec);
            }

            /* Get a new line, if needed. */
            while (m_input.m_line_index >= m_input.m_line_read)
            {
                if (m_input.getLine())
                {
                    CError.parse_error(CError.E_EOF,m_input.m_line_number);
                    return null;
                }
            }

            /* Look for beginning of action. */
            while (CUtility.isspace(m_input.m_line[m_input.m_line_index]))
            {
                ++m_input.m_line_index;

                /* Get a new line, if needed. */
                while (m_input.m_line_index >= m_input.m_line_read)
                {
                    if (m_input.getLine())
                    {
                        CError.parse_error(CError.E_EOF,m_input.m_line_number);
                        return null;
                    }
                }
            }

            /* Look for brackets. */
            if ('{' != m_input.m_line[m_input.m_line_index])
            {
                CError.parse_error(CError.E_BRACE,m_input.m_line_number);
            }

            /* Copy new line into action buffer. */
            brackets = 0;
            insinglequotes = indoublequotes = inslashcomment = instarcomment =
                escaped  = slashed = false;
            while (true)
            {
                action[action_index] = m_input.m_line[m_input.m_line_index];

                /* Look for quotes. */
                if ((insinglequotes || indoublequotes) && escaped)
                    escaped=false; // only protects one char, but this is enough.
                else if ((insinglequotes || indoublequotes) &&
                    '\\' == m_input.m_line[m_input.m_line_index])
                    escaped=true;
                else if (!(insinglequotes || inslashcomment || instarcomment) &&
                    '\"' == m_input.m_line[m_input.m_line_index])
                    indoublequotes=!indoublequotes; // unescaped double quote.
                else if (!(indoublequotes || inslashcomment || instarcomment) &&
                    '\'' == m_input.m_line[m_input.m_line_index])
                    insinglequotes=!insinglequotes; // unescaped single quote.
                /* Look for comments. */
                if (instarcomment)
                { // inside "/*" comment; look for "*/"
                    if (slashed && '/' == m_input.m_line[m_input.m_line_index])
                        instarcomment = slashed = false;
                    else // note that inside a star comment, slashed means starred
                        slashed = ('*' == m_input.m_line[m_input.m_line_index]);
                }
                else if (!inslashcomment && !insinglequotes && !indoublequotes)
                {
                    // not in comment, look for /* or //
                    inslashcomment =
                        (slashed && '/' == m_input.m_line[m_input.m_line_index]);
                    instarcomment =
                        (slashed && '*' == m_input.m_line[m_input.m_line_index]);
                    slashed = ('/' == m_input.m_line[m_input.m_line_index]);
                }

                /* Look for brackets. */
                if (!insinglequotes && !indoublequotes &&
                    !instarcomment && !inslashcomment)
                {
                    if ('{' == m_input.m_line[m_input.m_line_index])
                    {
                        ++brackets;
                    }
                    else if ('}' == m_input.m_line[m_input.m_line_index])
                    {
                        --brackets;

                        if (0 == brackets)
                        {
                            ++action_index;
                            ++m_input.m_line_index;

                            break;
                        }
                    }
                }

                ++action_index;
                /* Double the buffer size, if needed. */
                if (action_index >= action.Length)
                {
                    action = CUtility.doubleSize(action);
                }

                ++m_input.m_line_index;
                /* Get a new line, if needed. */
                while (m_input.m_line_index >= m_input.m_line_read)
                {
                    inslashcomment = slashed = false;
                    if (insinglequotes || indoublequotes)
                    { // non-fatal
                        CError.parse_error(CError.E_NEWLINE,m_input.m_line_number);
                        insinglequotes = indoublequotes = false;
                    }
                    if (m_input.getLine())
                    {
                        CError.parse_error(CError.E_SYNTAX,m_input.m_line_number);
                        return null;
                    }
                }
            }

            accept = new CAccept(action,action_index,m_input.m_line_number);

            if (CUtility.DEBUG)
            {
                CUtility.ASSERT(null != accept);
            }

            if (CUtility.DESCENT_DEBUG)
            {
                System.Console.Write("Accepting action:");
                System.Console.WriteLine(new string(accept.m_action,0,accept.m_action_read));
            }

            return accept;
        }