/***************************************************************
  * Function: reset
  * Description: Resets CMakeNfa member variables.
  **************************************************************/
 private void reset
 (
 )
 {
     m_input  = null;
     m_lexGen = null;
     m_spec   = null;
 }
        /***************************************************************
         * Function: thompson
         * Description: High level access function to module.
         * Deposits result in input CSpec.
         **************************************************************/
        public void thompson
        (
            CLexGen lexGen,
            CSpec spec,
            CInput input
        )
        {
            int  i;
            CNfa elem;
            int  size;

            /* Set member variables. */
            reset();
            Set(lexGen, spec, input);

            size = m_spec.m_states.Count;
            m_spec.m_state_rules = new Vector[size];
            for (i = 0; i < size; ++i)
            {
                m_spec.m_state_rules[i] = new Vector();
            }

            /* Initialize current token variable
             * and create nfa. */
            /*m_spec.m_current_token = m_lexGen.EOS;
             * m_lexGen.advance();*/

            m_spec.m_nfa_start = machine();

            /* Set labels in created nfa machine. */
            size = m_spec.m_nfa_states.size();
            for (i = 0; i < size; ++i)
            {
                elem         = (CNfa)m_spec.m_nfa_states.elementAt(i);
                elem.m_label = i;
            }

            /* Debugging output. */
            if (CUtility.DO_DEBUG)
            {
                m_lexGen.print_nfa();
            }

            if (m_spec.m_verbose)
            {
                System.Console.WriteLine("NFA comprised of "
                                         + (m_spec.m_nfa_states.Count + 1)
                                         + " states.");
            }

            reset();
        }
        /***************************************************************
         * Function: Set
         * Description: Sets CMakeNfa member variables.
         **************************************************************/
        private void Set
        (
            CLexGen lexGen,
            CSpec spec,
            CInput input
        )
        {
            if (CUtility.DEBUG)
            {
                CUtility.ASSERT(null != input);
                CUtility.ASSERT(null != lexGen);
                CUtility.ASSERT(null != spec);
            }

            m_input  = input;
            m_lexGen = lexGen;
            m_spec   = spec;
        }
        /***************************************************************
          Function: thompson
          Description: High level access function to module.
          Deposits result in input CSpec.
          **************************************************************/
        public void thompson(
            CLexGen lexGen,
            CSpec spec,
            CInput input
            )
        {
            int i;
            CNfa elem;
            int size;

            /* Set member variables. */
            reset();
            Set(lexGen,spec,input);

            size = m_spec.m_states.Count;
            m_spec.m_state_rules = new Vector[size];
            for (i = 0; i < size; ++i)
            {
                m_spec.m_state_rules[i] = new Vector();
            }

            /* Initialize current token variable
               and create nfa. */
            /*m_spec.m_current_token = m_lexGen.EOS;
            m_lexGen.advance();*/

            m_spec.m_nfa_start = machine();

            /* Set labels in created nfa machine. */
            size = m_spec.m_nfa_states.size();
            for (i = 0; i < size; ++i)
            {
                elem = (CNfa) m_spec.m_nfa_states.elementAt(i);
                elem.m_label = i;
            }

            /* Debugging output. */
            if (CUtility.DO_DEBUG)
            {
                m_lexGen.print_nfa();
            }

            if (m_spec.m_verbose)
            {
                System.Console.WriteLine("NFA comprised of "
                    + (m_spec.m_nfa_states.Count + 1)
                    + " states.");
            }

            reset();
        }
        /***************************************************************
          Function: Set
          Description: Sets CMakeNfa member variables.
          **************************************************************/
        private void Set(
            CLexGen lexGen,
            CSpec spec,
            CInput input
            )
        {
            if (CUtility.DEBUG)
            {
                CUtility.ASSERT(null != input);
                CUtility.ASSERT(null != lexGen);
                CUtility.ASSERT(null != spec);
            }

            m_input = input;
            m_lexGen = lexGen;
            m_spec = spec;
        }
 /***************************************************************
   Function: reset
   Description: Resets CMakeNfa member variables.
   **************************************************************/
 private void reset(
     )
 {
     m_input = null;
     m_lexGen = null;
     m_spec = null;
 }
        /***************************************************************
          Function: CLexGen
          **************************************************************/
        public CLexGen(
            string filename
            )
        {
            /* Successful initialization flag. */
            m_init_flag = false;

            /* Open input stream. */
            m_instream = new StreamReader(filename);
            if (null == m_instream)
            {
                System.Console.WriteLine("Error: Unable to open input file "
                    + filename + ".");
                return;
            }

            /* Open output stream. */
            m_outstream
                = new StreamWriter(filename+".cs");
            if (null == m_outstream)
            {
                System.Console.WriteLine("Error: Unable to open output file "
                    + filename + ".java.");
                return;
            }

            /* Create input buffer class. */
            m_input = new CInput(m_instream);

            /* Initialize character hash table. */
            m_tokens = new Hashtable();
            m_tokens.Add('$',AT_EOL);
            m_tokens.Add('(',OPEN_PAREN);
            m_tokens.Add(')',CLOSE_PAREN);
            m_tokens.Add('*',CLOSURE);
            m_tokens.Add('+',PLUS_CLOSE);
            m_tokens.Add('-',DASH);
            m_tokens.Add('.',ANY);
            m_tokens.Add('?',OPTIONAL);
            m_tokens.Add('[',CCL_START);
            m_tokens.Add(']',CCL_END);
            m_tokens.Add('^',AT_BOL);
            m_tokens.Add('{',OPEN_CURLY);
            m_tokens.Add('|',OR);
            m_tokens.Add('}',CLOSE_CURLY);

            /* Initialize spec structure. */
            m_spec = new CSpec(this);

            /* Nfa to dfa converter. */
            m_nfa2dfa = new CNfa2Dfa();
            m_minimize = new CMinimize();
            m_makeNfa = new CMakeNfa();
            m_simplifyNfa = new CSimplifyNfa();

            m_emit = new CEmit();

            /* Successful initialization flag. */
            m_init_flag = true;
        }