Example #1
0
        /***************************************************************
          Function: main
          **************************************************************/
        public static void main(
            string[] arg
            )
        {
            CLexGen lg;

            if (arg.Length < 1)
            {
                System.Console.WriteLine("Usage: JLex.Main <filename>");
                return;
            }

            /* Note: For debuging, it may be helpful to remove the try/catch
               block and permit the Exception to propagate to the top level.
               This gives more information. */
            try
            {
                lg = new CLexGen(arg[0]);
                lg.generate();
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
        /***************************************************************
          Function: CSpec
          Description: Constructor.
          **************************************************************/
        public CSpec(
            CLexGen lexGen
            )
        {
            m_lexGen = lexGen;

            /* Initialize regular expression token variables. */
            m_current_token = CLexGen.EOS;
            m_lexeme = '\0';
            m_in_quote = false;
            m_in_ccl = false;

            /* Initialize hashtable for lexer states. */
            m_states = new Hashtable();
            m_states.Add("YYINITIAL",m_states.Count);

            /* Initialize hashtable for lexical macros. */
            m_macros = new Hashtable();

            /* Initialize variables for lexer options. */
            m_integer_type = false;
            m_intwrap_type = false;
            m_count_lines = false;
            m_count_chars = false;
            m_cup_compatible = false;
            m_unix = true;
            m_public = false;
            m_yyeof = false;
            m_ignorecase = false;

            /* Initialize variables for JLex runtime options. */
            m_verbose = true;

            m_nfa_start = null;
            m_nfa_states = new Vector();

            m_dfa_states = new Vector();
            m_dfa_sets = new Hashtable();

            m_dtrans_vector = new Vector();
            m_dtrans_ncols = CUtility.MAX_SEVEN_BIT + 1;
            m_row_map = null;
            m_col_map = null;

            m_accept_vector = null;
            m_anchor_array = null;

            m_init_code = null;
            m_init_read = 0;

            m_init_throw_code = null;
            m_init_throw_read = 0;

            m_yylex_throw_code = null;
            m_yylex_throw_read = 0;

            m_class_code = null;
            m_class_read = 0;

            m_eof_code = null;
            m_eof_read = 0;

            m_eof_value_code = null;
            m_eof_value_read = 0;

            m_eof_throw_code = null;
            m_eof_throw_read = 0;

            m_state_dtrans = null;

            m_state_rules = null;
        }
        /***************************************************************
          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: reset
   Description: Resets CMakeNfa member variables.
   **************************************************************/
 private void reset(
     )
 {
     m_input = null;
     m_lexGen = null;
     m_spec = null;
 }