Esempio n. 1
0
        /***************************************************************
         *    Function: emit
         *    Description: High-level access function to module.
         **************************************************************/
        public void emit
        (
            CSpec spec,
            System.IO.TextWriter outstream
        )
        {
            Set(spec, outstream);

      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

//      #if (OLD_DEBUG)
//      {
//        print_details();
//      }

            emit_header();
            emit_construct();
            emit_helpers();
            emit_driver();
            emit_footer();

            reset();
        }
Esempio n. 2
0
        /***************************************************************
         *    Function: emit_header
         *    Description: Emits class header.
         **************************************************************/
        private void emit_header
        (
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            m_outstream.WriteLine();
            m_outstream.WriteLine();
            if (m_spec.m_public)
            {
                m_outstream.Write("public ");
            }
            m_outstream.Write("sealed class ");
            m_outstream.Write(new string(m_spec.m_class_name, 0,
                                         m_spec.m_class_name.Length));
            if (m_spec.m_implements_name.Length > 0)
            {
                m_outstream.Write(" : ");
                m_outstream.Write(new string(m_spec.m_implements_name, 0,
                                             m_spec.m_implements_name.Length));
            }
            m_outstream.WriteLine(" {");
        }
Esempio n. 3
0
        /** Self-test. */
        public static void _Main(string[] args)
        {
            const int    ITER  = 500;
            const int    RANGE = 65536;
            SparseBitSet a     = new SparseBitSet();

            CUtility.ASSERT(!a.Get(0) && !a.Get(1));
            CUtility.ASSERT(!a.Get(123329));
            a.Set(0); CUtility.ASSERT(a.Get(0) && !a.Get(1));
            a.Set(1); CUtility.ASSERT(a.Get(0) && a.Get(1));
            a.clearAll();
            CUtility.ASSERT(!a.Get(0) && !a.Get(1));
            Random r = new Random();
            Vector v = new Vector();

            for (int n = 0; n < ITER; n++)
            {
                int rr = ((r.Next() >> 1) % RANGE) << 1;
                a.Set(rr); v.addElement(rr);
                // check that all the numbers are there.
                CUtility.ASSERT(a.Get(rr) && !a.Get(rr + 1) && !a.Get(rr - 1));
                for (int i = 0; i < v.size(); i++)
                {
                    CUtility.ASSERT(a.Get((int)v.elementAt(i)));
                }
            }
            SparseBitSet b = (SparseBitSet)a.Clone();

            CUtility.ASSERT(a.Equals(b) && b.Equals(a));
            for (int n = 0; n < ITER / 2; n++)
            {
                int rr = (r.Next() >> 1) % v.size();
                int m  = (int)v.elementAt(rr);
                b.clear(m); v.removeElementAt(rr);
                // check that numbers are removed properly.
                CUtility.ASSERT(!b.Get(m));
            }
            CUtility.ASSERT(!a.Equals(b));
            SparseBitSet c = (SparseBitSet)a.Clone();
            SparseBitSet d = (SparseBitSet)a.Clone();

            c.and(a);
            CUtility.ASSERT(c.Equals(a) && a.Equals(c));
            c.xor(a);
            CUtility.ASSERT(!c.Equals(a) && c.size() == 0);
            d.or(b);
            CUtility.ASSERT(d.Equals(a) && !b.Equals(d));
            d.and(b);
            CUtility.ASSERT(!d.Equals(a) && b.Equals(d));
            d.xor(a);
            CUtility.ASSERT(!d.Equals(a) && !b.Equals(d));
            c.or(d); c.or(b);
            CUtility.ASSERT(c.Equals(a) && a.Equals(c));
            c = (SparseBitSet)d.Clone();
            c.and(b);
            CUtility.ASSERT(c.size() == 0);
            System.Console.WriteLine("Success.");
        }
Esempio n. 4
0
 /***************************************************************
  *    Function: allocate_BOL_EOF
  *    Description: Expands character class to include special BOL and
  *    EOF characters.  Puts numeric index of these characters in
  *    input CSpec.
  **************************************************************/
 public void allocate_BOL_EOF
 (
     CSpec spec
 )
 {
     CUtility.ASSERT(CSpec.NUM_PSEUDO == 2);
     spec.BOL = spec.m_dtrans_ncols++;
     spec.EOF = spec.m_dtrans_ncols++;
 }
Esempio n. 5
0
 private void insert_block(int idx, int bnum)
 {
     CUtility.ASSERT(idx <= _size);
     CUtility.ASSERT(idx == _size || offs[idx] != bnum);
     // System.arraycopy(bits, idx, bits, idx+1, size-idx);
     Array.Copy(bits, idx, bits, idx + 1, _size - idx);
     //System.arraycopy(offs, idx, offs, idx+1, size-idx);
     Array.Copy(offs, idx, offs, idx + 1, _size - idx);
     offs[idx] = bnum;
     bits[idx] = 0; //clear them bits.
     _size++;
 }
Esempio n. 6
0
        /***************************************************************
         *    Function: emit_footer
         *    Description:
         **************************************************************/
        private void emit_footer
        (
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            m_outstream.WriteLine("}");
        }
Esempio n. 7
0
        /***************************************************************
         *    Function: factor
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void factor
        (
            CNfaPair pair
        )
        {
            CNfa start = null;
            CNfa end   = null;

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

            term(pair);

            if (CLexGen.CLOSURE == m_spec.m_current_token ||
                CLexGen.PLUS_CLOSE == m_spec.m_current_token ||
                CLexGen.OPTIONAL == m_spec.m_current_token)
            {
                start = CAlloc.newCNfa(m_spec);
                end   = CAlloc.newCNfa(m_spec);

                start.m_next      = pair.m_start;
                pair.m_end.m_next = end;

                if (CLexGen.CLOSURE == m_spec.m_current_token ||
                    CLexGen.OPTIONAL == m_spec.m_current_token)
                {
                    start.m_next2 = end;
                }

                if (CLexGen.CLOSURE == m_spec.m_current_token ||
                    CLexGen.PLUS_CLOSE == m_spec.m_current_token)
                {
                    pair.m_end.m_next2 = pair.m_start;
                }

                pair.m_start = start;
                pair.m_end   = end;
                m_lexGen.advance();
            }

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("factor", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }
Esempio n. 8
0
        /***************************************************************
         *    Function: Set
         *    Description: Sets member variables.
         **************************************************************/
        private void Set
        (
            CSpec spec
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != spec);
            }
      #endif

            m_spec    = spec;
            m_group   = null;
            m_ingroup = null;
        }
Esempio n. 9
0
 private void new_block(int idx, int bnum)
 {
     if (_size == bits.Length)
     { // resize
         long[] nbits = new long[_size * 3];
         int [] noffs = new int [_size * 3];
         // System.arraycopy(bits, 0, nbits, 0, size);
         Array.Copy(bits, nbits, _size);
         //  System.arraycopy(offs, 0, noffs, 0, size);
         Array.Copy(offs, noffs, _size);
         bits = nbits;
         offs = noffs;
     }
     CUtility.ASSERT(_size < bits.Length);
     insert_block(idx, bnum);
 }
Esempio n. 10
0
        /***************************************************************
         *    Function: Set
         *    Description: Initializes member variables.
         **************************************************************/
        private void Set
        (
            CSpec spec,
            TextWriter outstream
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != spec);
                CUtility.ASSERT(null != outstream);
            }
      #endif

            m_spec      = spec;
            m_outstream = outstream;
        }
Esempio n. 11
0
        /***************************************************************
         *    Function: expr
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void expr
        (
            CNfaPair pair
        )
        {
            CNfaPair e2_pair;
            CNfa     p;

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

      #if (DEBUG)
            {
                CUtility.ASSERT(null != pair);
            }
      #endif

            e2_pair = CAlloc.newCNfaPair();

            cat_expr(pair);

            while (CLexGen.OR == m_spec.m_current_token)
            {
                m_lexGen.advance();
                cat_expr(e2_pair);

                p            = CAlloc.newCNfa(m_spec);
                p.m_next2    = e2_pair.m_start;
                p.m_next     = pair.m_start;
                pair.m_start = p;

                p = CAlloc.newCNfa(m_spec);
                pair.m_end.m_next    = p;
                e2_pair.m_end.m_next = p;
                pair.m_end           = p;
            }

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }
Esempio n. 12
0
        /***************************************************************
         *    Function: cat_expr
         *    Description: Recursive descent regular expression parser.
         **************************************************************/
        private void cat_expr
        (
            CNfaPair pair
        )
        {
            CNfaPair e2_pair;

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

      #if (DEBUG)
            {
                CUtility.ASSERT(null != pair);
            }
      #endif

            e2_pair = CAlloc.newCNfaPair();

            if (first_in_cat(m_spec.m_current_token))
            {
                factor(pair);
            }

            while (first_in_cat(m_spec.m_current_token))
            {
                factor(e2_pair);

                /* Destroy */
                pair.m_end.mimic(e2_pair.m_start);
                discardCNfa(e2_pair.m_start);

                pair.m_end = e2_pair.m_end;
            }

      #if (DESCENT_DEBUG)
            {
                CUtility.leave("cat_expr", m_spec.m_lexeme, m_spec.m_current_token);
            }
      #endif
        }
Esempio n. 13
0
        /***************************************************************
         *    Function: Set
         *    Description: Sets CMakeNfa member variables.
         **************************************************************/
        private void Set
        (
            CLexGen lexGen,
            CSpec spec,
            CInput input
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != input);
                CUtility.ASSERT(null != lexGen);
                CUtility.ASSERT(null != spec);
            }
      #endif

            m_input  = input;
            m_lexGen = lexGen;
            m_spec   = spec;
        }
Esempio n. 14
0
        /***************************************************************
         *    Function: emit_states
         *    Description: Emits constants that serve as lexical states,
         *    including YYINITIAL.
         **************************************************************/
        private void emit_states
        (
        )
        {
            IEnumerator states;
            string      state;
            int         index;

            states = m_spec.m_states.Keys.GetEnumerator();
            /*index = 0;*/
            while (states.MoveNext())
            {
                state = (string)states.Current;

        #if (DEBUG)
                {
                    CUtility.ASSERT(null != state);
                }
        #endif

                m_outstream.WriteLine("\tconst int "
                                      + state
                                      + " = "
                                      + (m_spec.m_states[state]).ToString()
                                      + ";");
                /*++index;*/
            }

            m_outstream.WriteLine("\treadonly int[] yy_state_dtrans = {");
            for (index = 0; index < m_spec.m_state_dtrans.Length; ++index)
            {
                m_outstream.Write("\t\t" + m_spec.m_state_dtrans[index]);
                if (index < m_spec.m_state_dtrans.Length - 1)
                {
                    m_outstream.Write(", ");
                }
                else
                {
                    m_outstream.WriteLine();
                }
            }
            m_outstream.WriteLine("\t};");
        }
Esempio n. 15
0
        /***************************************************************
         *    function: add_to_dstates
         *    Description: Takes as input a CBunch with details of
         *    a dfa state that needs to be created.
         *    1) Allocates a new dfa state and saves it in
         *    the appropriate CSpec vector.
         *    2) Initializes the fields of the dfa state
         *    with the information in the CBunch.
         *    3) Returns index of new dfa.
         **************************************************************/
        private int add_to_dstates
        (
            CBunch bunch
        )
        {
            CDfa dfa;

      #if (DEBUG)
            {
                CUtility.ASSERT(null != bunch.m_nfa_set);
                CUtility.ASSERT(null != bunch.m_nfa_bit);
                CUtility.ASSERT(null != bunch.m_accept ||
                                CSpec.NONE == bunch.m_anchor);
            }
      #endif

            /* Allocate, passing CSpec so dfa label can be Set. */
            dfa = CAlloc.newCDfa(m_spec);

            /* Initialize fields, including the mark field. */
            dfa.m_nfa_set = (Vector)bunch.m_nfa_set.Clone();
            dfa.m_nfa_bit = (SparseBitSet)bunch.m_nfa_bit.Clone();
            dfa.m_accept  = bunch.m_accept;
            dfa.m_anchor  = bunch.m_anchor;
            dfa.m_mark    = false;

            /* Register dfa state using BitSet in CSpec Hashtable. */
            m_spec.m_dfa_sets.Add(dfa.m_nfa_bit, dfa);
            /*registerCDfa(dfa);*/

      #if (OLD_DUMP_DEBUG)
            {
                System.Console.Write("Registering Set : ");
                m_lexGen.print_set(dfa.m_nfa_set);
                System.Console.WriteLine();
            }
      #endif

            return(dfa.m_label);
        }
Esempio n. 16
0
        private int bsearch(int bnum)
        {
            int l = 0, r = _size; // search interval is [l, r)

            while (l < r)
            {
                int p = (l + r) / 2;
                if (bnum < offs[p])
                {
                    r = p;
                }
                else if (bnum > offs[p])
                {
                    l = p + 1;
                }
                else
                {
                    return(p);
                }
            }
            CUtility.ASSERT(l == r);
            return(l); // index at which the bnum *should* be, if it's not.
        }
Esempio n. 17
0
        /***************************************************************
         *    Function: CInput
         *    Description:
         **************************************************************/
        public CInput
        (
            TextReader input
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != input);
            }
      #endif

            /* Initialize input stream. */
            m_input = input;

            /* Initialize buffers and index counters. */
            m_line       = null;
            m_line_read  = 0;
            m_line_index = 0;

            /* Initialize state variables. */
            m_eof_reached   = false;
            m_line_number   = 0;
            m_pushback_line = false;
        }
Esempio n. 18
0
        /***************************************************************
         *    Function: emit_table
         *    Description: Emits transition table.
         **************************************************************/
        private void emit_table
        (
        )
        {
            int     i;
            int     elem;
            int     size;
            CDTrans dtrans;
            bool    is_start;
            bool    is_end;
            CAccept accept;

      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            m_outstream.WriteLine("\treadonly int[] yy_acpt = {");
            size = m_spec.m_accept_vector.Count;
            for (elem = 0; elem < size; ++elem)
            {
                accept = (CAccept)m_spec.m_accept_vector.elementAt(elem);

                //m_outstream.Write("\t\t/* "+elem+" */ ");
                if (null != accept)
                {
                    is_start = (0 != (m_spec.m_anchor_array[elem] & CSpec.START));
                    is_end   = (0 != (m_spec.m_anchor_array[elem] & CSpec.END));

                    if (is_start && is_end)
                    {
                        m_outstream.Write(3);//"YY_START | YY_END");
                    }
                    else if (is_start)
                    {
                        m_outstream.Write(1);//"YY_START");
                    }
                    else if (is_end)
                    {
                        m_outstream.Write(2);//"YY_END");
                    }
                    else
                    {
                        m_outstream.Write(4);//"YY_NO_ANCHOR");
                    }
                }
                else
                {
                    m_outstream.Write(0);//"YY_NOT_ACCEPT");
                }

                if (elem < size - 1)
                {
                    m_outstream.Write(",");
                }

                if (elem % 16 == 0)
                {
                    m_outstream.WriteLine();
                }
            }
            m_outstream.WriteLine("\t};");

            // CSA: modified yy_cmap to use string packing 9-Aug-1999
            int[] yy_cmap = new int[m_spec.m_ccls_map.Length];
            for (i = 0; i < m_spec.m_ccls_map.Length; ++i)
            {
                yy_cmap[i] = m_spec.m_col_map[m_spec.m_ccls_map[i]];
            }
            m_outstream.WriteLine("\treadonly int[] yy_cmap = unpackFromString(");
            emit_table_as_string(new int[][] { yy_cmap });
            m_outstream.WriteLine(")[0];");
            m_outstream.WriteLine();

            // CSA: modified yy_rmap to use string packing 9-Aug-1999
            m_outstream.WriteLine("\treadonly int[] yy_rmap = {");
            emit_table(m_spec.m_row_map);
            m_outstream.WriteLine("};");
            m_outstream.WriteLine();

            // 6/24/98 Raimondas Lencevicius
            // modified to use
            //    int[][] unpackFromString(int size1, int size2, string st)
            size = m_spec.m_dtrans_vector.size();
            int[][] yy_nxt = new int[size][];
            for (elem = 0; elem < size; elem++)
            {
                dtrans = (CDTrans)m_spec.m_dtrans_vector.elementAt(elem);
                CUtility.ASSERT(dtrans.m_dtrans.Length == m_spec.m_dtrans_ncols);
                yy_nxt[elem] = dtrans.m_dtrans;
            }
            m_outstream.WriteLine
                ("\treadonly int[,] yy_nxt = {");
            emit_table(yy_nxt);
            m_outstream.WriteLine("};");
            m_outstream.WriteLine();
        }
Esempio n. 19
0
        /***************************************************************
         *    Function: init_groups
         *    Description:
         **************************************************************/
        private void init_groups
        (
        )
        {
            int i;
            int j;
            int group_count;
            int size;
            //  CAccept accept;
            CDTrans dtrans;
            Vector  dtrans_group;
            CDTrans first;
            bool    group_found;

            m_group     = new Vector();
            group_count = 0;

            size      = m_spec.m_dtrans_vector.size();
            m_ingroup = new int[size];

            for (i = 0; i < size; ++i)
            {
                group_found = false;
                dtrans      = (CDTrans)m_spec.m_dtrans_vector.elementAt(i);

        #if (DEBUG)
                {
                    CUtility.ASSERT(i == dtrans.m_label);
                    CUtility.ASSERT(false == group_found);
                    CUtility.ASSERT(group_count == m_group.size());
                }
        #endif

                for (j = 0; j < group_count; ++j)
                {
                    dtrans_group = (Vector)m_group.elementAt(j);

          #if (DEBUG)
                    {
                        CUtility.ASSERT(false == group_found);
                        CUtility.ASSERT(0 < dtrans_group.size());
                    }
          #endif

                    first = (CDTrans)dtrans_group.elementAt(0);

          #if (SLOW_DEBUG)
                    {
                        CDTrans check;
                        int     k;
                        int     s;

                        s = dtrans_group.size();
                        CUtility.ASSERT(0 < s);

                        for (k = 1; k < s; ++k)
                        {
                            check = (CDTrans)dtrans_group.elementAt(k);
                            CUtility.ASSERT(check.m_accept == first.m_accept);
                        }
                    }
          #endif

                    if (first.m_accept == dtrans.m_accept)
                    {
                        dtrans_group.addElement(dtrans);
                        m_ingroup[i] = j;
                        group_found  = true;

            #if (DEBUG)
                        {
                            CUtility.ASSERT(j == m_ingroup[dtrans.m_label]);
                        }
            #endif

                        break;
                    }
                }

                if (false == group_found)
                {
                    dtrans_group = new Vector();
                    dtrans_group.addElement(dtrans);
                    m_ingroup[i] = m_group.size();
                    m_group.addElement(dtrans_group);
                    ++group_count;
                }
            }

            if (m_spec.m_verbose &&
                CUtility.OLD_DUMP_DEBUG)
            {
                System.Console.WriteLine("Initial grouping:");
                pgroups();
                System.Console.WriteLine();
            }
        }
Esempio n. 20
0
        /***************************************************************
         *    Function: reduce
         *    Description:
         **************************************************************/
        private void reduce
        (
        )
        {
            int          i;
            int          j;
            int          k;
            int          nrows;
            int          reduced_ncols;
            int          reduced_nrows;
            SparseBitSet Set;
            CDTrans      dtrans;
            int          size;

            Set = new SparseBitSet();

            /* Save accept nodes and anchor entries. */
            size = m_spec.m_dtrans_vector.size();
            m_spec.m_anchor_array  = new int[size];
            m_spec.m_accept_vector = new Vector();
            for (i = 0; i < size; ++i)
            {
                dtrans = (CDTrans)m_spec.m_dtrans_vector.elementAt(i);
                m_spec.m_accept_vector.addElement(dtrans.m_accept);
                m_spec.m_anchor_array[i] = dtrans.m_anchor;
                dtrans.m_accept          = null;
            }

            /* Allocate column map. */
            m_spec.m_col_map = new int[m_spec.m_dtrans_ncols];
            for (i = 0; i < m_spec.m_dtrans_ncols; ++i)
            {
                m_spec.m_col_map[i] = -1;
            }

            /* Process columns for reduction. */
            for (reduced_ncols = 0; ; ++reduced_ncols)
            {
        #if (DEBUG)
                {
                    for (i = 0; i < reduced_ncols; ++i)
                    {
                        CUtility.ASSERT(-1 != m_spec.m_col_map[i]);
                    }
                }
        #endif

                for (i = reduced_ncols; i < m_spec.m_dtrans_ncols; ++i)
                {
                    if (-1 == m_spec.m_col_map[i])
                    {
                        break;
                    }
                }

                if (i >= m_spec.m_dtrans_ncols)
                {
                    break;
                }

        #if (DEBUG)
                {
                    CUtility.ASSERT(false == Set.Get(i));
                    CUtility.ASSERT(-1 == m_spec.m_col_map[i]);
                }
        #endif

                Set.Set(i);

                m_spec.m_col_map[i] = reduced_ncols;

                /* UNDONE: Optimize by doing all comparisons in one batch. */
                for (j = i + 1; j < m_spec.m_dtrans_ncols; ++j)
                {
                    if (-1 == m_spec.m_col_map[j] && col_equiv(i, j))
                    {
                        m_spec.m_col_map[j] = reduced_ncols;
                    }
                }
            }

            /* Reduce columns. */
            k = 0;
            for (i = 0; i < m_spec.m_dtrans_ncols; ++i)
            {
                if (Set.Get(i))
                {
                    ++k;

                    Set.clear(i);

                    j = m_spec.m_col_map[i];

          #if (DEBUG)
                    {
                        CUtility.ASSERT(j <= i);
                    }
          #endif

                    if (j == i)
                    {
                        continue;
                    }

                    col_copy(j, i);
                }
            }
            m_spec.m_dtrans_ncols = reduced_ncols;
            /* truncate m_dtrans at proper length (freeing extra) */
            trunc_col();

      #if (DEBUG)
            {
                CUtility.ASSERT(k == reduced_ncols);
            }
      #endif

            /* Allocate row map. */
            nrows            = m_spec.m_dtrans_vector.Count;
            m_spec.m_row_map = new int[nrows];
            for (i = 0; i < nrows; ++i)
            {
                m_spec.m_row_map[i] = -1;
            }

            /* Process rows to reduce. */
            for (reduced_nrows = 0; ; ++reduced_nrows)
            {
        #if (DEBUG)
                {
                    for (i = 0; i < reduced_nrows; ++i)
                    {
                        CUtility.ASSERT(-1 != m_spec.m_row_map[i]);
                    }
                }
        #endif

                for (i = reduced_nrows; i < nrows; ++i)
                {
                    if (-1 == m_spec.m_row_map[i])
                    {
                        break;
                    }
                }

                if (i >= nrows)
                {
                    break;
                }

        #if (DEBUG)
                {
                    CUtility.ASSERT(false == Set.Get(i));
                    CUtility.ASSERT(-1 == m_spec.m_row_map[i]);
                }
        #endif

                Set.Set(i);

                m_spec.m_row_map[i] = reduced_nrows;

                /* UNDONE: Optimize by doing all comparisons in one batch. */
                for (j = i + 1; j < nrows; ++j)
                {
                    if (-1 == m_spec.m_row_map[j] && row_equiv(i, j))
                    {
                        m_spec.m_row_map[j] = reduced_nrows;
                    }
                }
            }

            /* Reduce rows. */
            k = 0;
            for (i = 0; i < nrows; ++i)
            {
                if (Set.Get(i))
                {
                    ++k;

                    Set.clear(i);

                    j = m_spec.m_row_map[i];

          #if (DEBUG)
                    {
                        CUtility.ASSERT(j <= i);
                    }
          #endif

                    if (j == i)
                    {
                        continue;
                    }

                    row_copy(j, i);
                }
            }
            m_spec.m_dtrans_vector.setSize(reduced_nrows);

      #if (DEBUG)
            {
                /*System.Console.WriteLine("k = " + k + "\nreduced_nrows = " + reduced_nrows + "");*/
                CUtility.ASSERT(k == reduced_nrows);
            }
      #endif
        }
Esempio n. 21
0
        /***************************************************************
         *    Function: emit_helpers
         *    Description: Emits helper functions, particularly
         *    error handling and input buffering.
         **************************************************************/
        private void emit_helpers
        (
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            /* Function: yy_do_eof */
            //m_outstream.WriteLine("\tprivate bool yy_eof_done = false;");
            if (null != m_spec.m_eof_code)
            {
                m_outstream.Write("\tprivate void yy_do_eof ()");

                //SI:throw code not necessary

                /*  if (null != m_spec.m_eof_throw_code)
                 *      {
                 *          m_outstream.WriteLine();
                 *          m_outstream.Write("\t\tthrows ");
                 *          m_outstream.WriteLine(new string(m_spec.m_eof_throw_code,0,
                 *              m_spec.m_eof_throw_read));
                 *          m_outstream.WriteLine("\t\t{");
                 *      }
                 *      else
                 *      {*/
                m_outstream.WriteLine(" {");


                m_outstream.WriteLine("\t\tif (false == yy_eof_done) {");
                m_outstream.Write(new string(m_spec.m_eof_code, 0, m_spec.m_eof_read));
                m_outstream.WriteLine("\t\t}");
                m_outstream.WriteLine("\t\tyy_eof_done = true;");
                m_outstream.WriteLine("\t}");
            }

            emit_states();

            /* Function: yybegin */
//      m_outstream.WriteLine("\tpublic override void yybegin (int state) {");
//      m_outstream.WriteLine("\t\tyy_lexical_state = state;");
//      m_outstream.WriteLine("\t}");


            /* Function: yy_advance */
//      m_outstream.WriteLine("\tprivate int yy_advance ()");
//      //SI:     m_outstream.WriteLine("\t\tthrows java.io.IOException {");
//      /*m_outstream.WriteLine("\t\t{");*/
//      m_outstream.WriteLine("\t{");
//      m_outstream.WriteLine("\t\tint next_read;");
//      m_outstream.WriteLine("\t\tint i;");
//      m_outstream.WriteLine("\t\tint j;");
//      m_outstream.WriteLine();
//
//      m_outstream.WriteLine("\t\tif (yy_buffer_index < yy_buffer_read) {");
//      m_outstream.WriteLine("\t\t\treturn yy_buffer[yy_buffer_index++];");
//      /*m_outstream.WriteLine("\t\t\t++yy_buffer_index;");*/
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine();
//
//      m_outstream.WriteLine("\t\tif (0 != yy_buffer_start) {");
//      m_outstream.WriteLine("\t\t\ti = yy_buffer_start;");
//      m_outstream.WriteLine("\t\t\tj = 0;");
//      m_outstream.WriteLine("\t\t\twhile (i < yy_buffer_read) {");
//      m_outstream.WriteLine("\t\t\t\tyy_buffer[j] = yy_buffer[i];");
//      m_outstream.WriteLine("\t\t\t\t++i;");
//      m_outstream.WriteLine("\t\t\t\t++j;");
//      m_outstream.WriteLine("\t\t\t}");
//      m_outstream.WriteLine("\t\t\tyy_buffer_end = yy_buffer_end - yy_buffer_start;");
//      m_outstream.WriteLine("\t\t\tyy_buffer_start = 0;");
//      m_outstream.WriteLine("\t\t\tyy_buffer_read = j;");
//      m_outstream.WriteLine("\t\t\tyy_buffer_index = j;");
//      m_outstream.WriteLine("\t\t\tnext_read = yy_reader.Read(yy_buffer,");
//      m_outstream.WriteLine("\t\t\t\t\tyy_buffer_read,");
//      m_outstream.WriteLine("\t\t\t\t\tyy_buffer.Length - yy_buffer_read);");
//      m_outstream.WriteLine("\t\t\tif (-1 == next_read) {");
//      m_outstream.WriteLine("\t\t\t\treturn YY_EOF;");
//      m_outstream.WriteLine("\t\t\t}");
//      m_outstream.WriteLine("\t\t\tyy_buffer_read = yy_buffer_read + next_read;");
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine();
//
//      m_outstream.WriteLine("\t\twhile (yy_buffer_index >= yy_buffer_read) {");
//      m_outstream.WriteLine("\t\t\tif (yy_buffer_index >= yy_buffer.Length) {");
//      m_outstream.WriteLine("\t\t\t\tyy_buffer = yy_double(yy_buffer);");
//      m_outstream.WriteLine("\t\t\t}");
//      m_outstream.WriteLine("\t\t\tnext_read = yy_reader.Read(yy_buffer,");
//      m_outstream.WriteLine("\t\t\t\t\tyy_buffer_read,");
//      m_outstream.WriteLine("\t\t\t\t\tyy_buffer.Length - yy_buffer_read);");
//      m_outstream.WriteLine("\t\t\tif (-1 == next_read) {");
//      m_outstream.WriteLine("\t\t\t\treturn YY_EOF;");
//      m_outstream.WriteLine("\t\t\t}");
//      m_outstream.WriteLine("\t\t\tyy_buffer_read = yy_buffer_read + next_read;");
//      m_outstream.WriteLine("\t\t}");
//
//      m_outstream.WriteLine("\t\treturn yy_buffer[yy_buffer_index++];");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_move_end */
//      m_outstream.WriteLine("\tprivate void yy_move_end () {");
//      m_outstream.WriteLine("\t\tif (yy_buffer_end > yy_buffer_start &&");
//      m_outstream.WriteLine("\t\t    '\\n' == yy_buffer[yy_buffer_end-1])");
//      m_outstream.WriteLine("\t\t\tyy_buffer_end--;");
//      m_outstream.WriteLine("\t\tif (yy_buffer_end > yy_buffer_start &&");
//      m_outstream.WriteLine("\t\t    '\\r' == yy_buffer[yy_buffer_end-1])");
//      m_outstream.WriteLine("\t\t\tyy_buffer_end--;");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_mark_start */
//      m_outstream.WriteLine("\tprivate bool yy_last_was_cr=false;");
//      m_outstream.WriteLine("\tprivate void yy_mark_start () {");
//      if (m_spec.m_count_lines || true == m_spec.m_count_chars)
//      {
//        if (m_spec.m_count_lines)
//        {
//          m_outstream.WriteLine("\t\tint i;");
//          m_outstream.WriteLine("\t\tfor (i = yy_buffer_start; i < yy_buffer_index; ++i) {");
//          m_outstream.WriteLine("\t\t\tif ('\\n' == yy_buffer[i] && !yy_last_was_cr) {");
//          m_outstream.WriteLine("\t\t\t\t++yyline;");
//          m_outstream.WriteLine("\t\t\t}");
//          m_outstream.WriteLine("\t\t\tif ('\\r' == yy_buffer[i]) {");
//          m_outstream.WriteLine("\t\t\t\t++yyline;");
//          m_outstream.WriteLine("\t\t\t\tyy_last_was_cr=true;");
//          m_outstream.WriteLine("\t\t\t} else yy_last_was_cr=false;");
//          m_outstream.WriteLine("\t\t}");
//        }
//        if (m_spec.m_count_chars)
//        {
//          m_outstream.WriteLine("\t\tyychar = yychar");
//          m_outstream.WriteLine("\t\t\t+ yy_buffer_index - yy_buffer_start;");
//        }
//      }
//      m_outstream.WriteLine("\t\tyy_buffer_start = yy_buffer_index;");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_mark_end */
//      m_outstream.WriteLine("\tprivate void yy_mark_end () {");
//      m_outstream.WriteLine("\t\tyy_buffer_end = yy_buffer_index;");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_to_mark */
//      m_outstream.WriteLine("\tprivate void yy_to_mark () {");
//      m_outstream.WriteLine("\t\tyy_buffer_index = yy_buffer_end;");
//      m_outstream.WriteLine("\t\tyy_at_bol = (yy_buffer_end > yy_buffer_start) &&");
//      m_outstream.WriteLine("\t\t            ('\\r' == yy_buffer[yy_buffer_end-1] ||");
//      m_outstream.WriteLine("\t\t             '\\n' == yy_buffer[yy_buffer_end-1] ||");
//      m_outstream.WriteLine("\t\t             2028/*LS*/ == yy_buffer[yy_buffer_end-1] ||");
//      m_outstream.WriteLine("\t\t             2029/*PS*/ == yy_buffer[yy_buffer_end-1]);");
//      m_outstream.WriteLine("\t}");

            /* Function: yytext */
//      m_outstream.WriteLine("\tpublic override string yytext () {");
//      m_outstream.WriteLine("\t\treturn (new string(yy_buffer,");
//      m_outstream.WriteLine("\t\t\tyy_buffer_start,");
//      m_outstream.WriteLine("\t\t\tyy_buffer_end - yy_buffer_start));");
//      m_outstream.WriteLine("\t}");

            /* Function: yylength */
//      m_outstream.WriteLine("\tpublic override int yylength () {");
//      m_outstream.WriteLine("\t\treturn yy_buffer_end - yy_buffer_start;");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_double */
//      m_outstream.WriteLine("\tprivate char[] yy_double (char[] buf) {");
//      m_outstream.WriteLine("\t\tint i;");
//      m_outstream.WriteLine("\t\tchar[] newbuf;");
//      m_outstream.WriteLine("\t\tnewbuf = new char[2*buf.Length];");
//      m_outstream.WriteLine("\t\tfor (i = 0; i < buf.Length; ++i) {");
//      m_outstream.WriteLine("\t\t\tnewbuf[i] = buf[i];");
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine("\t\treturn newbuf;");
//      m_outstream.WriteLine("\t}");

            /* Function: yy_error */
//      m_outstream.WriteLine("\tprivate const int YY_E_INTERNAL = 0;");
//      m_outstream.WriteLine("\tprivate const int YY_E_MATCH = 1;");
//      m_outstream.WriteLine("\tprivate string[] yy_error_string = {");
//      m_outstream.WriteLine("\t\t\"Error: Internal error.\\n\",");
//      m_outstream.WriteLine("\t\t\"Error: Unmatched input.\\n\"");
//      m_outstream.WriteLine("\t};");
//      m_outstream.WriteLine("\tprivate void yy_error (int code,bool fatal) {");
//      m_outstream.WriteLine("\t\t System.Console.Write(yy_error_string[code]);");
//      m_outstream.WriteLine("\t\t System.Console.Out.Flush();");
//      m_outstream.WriteLine("\t\tif (fatal) {");
//      m_outstream.WriteLine("\t\t\tthrow new System.Exception(\"Fatal Error.\\n\");");
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine("\t}");



            // Function: private int [][] unpackFromString(int size1, int size2, string st)
            // Added 6/24/98 Raimondas Lencevicius
            // May be made more efficient by replacing string operations
            // Assumes correctly formed input string. Performs no error checking
//      m_outstream.WriteLine("\tprivate static int[][] unpackFromString(int size1, int size2, string st) {");
//      m_outstream.WriteLine("\t\tint colonIndex = -1;");
//      m_outstream.WriteLine("\t\tstring lengthString;");
//      m_outstream.WriteLine("\t\tint sequenceLength = 0;");
//      m_outstream.WriteLine("\t\tint sequenceInteger = 0;");
//      m_outstream.WriteLine();
//      m_outstream.WriteLine("\t\tint commaIndex;");
//      m_outstream.WriteLine("\t\tstring workString;");
//      m_outstream.WriteLine();
//      m_outstream.WriteLine("\t\tint[][] res = new int[size1][];");
//      m_outstream.WriteLine("\t\tfor(int i=0;i<size1;i++) res[i]=new int[size2];");
//      m_outstream.WriteLine("\t\tfor (int i= 0; i < size1; i++) {");
//      m_outstream.WriteLine("\t\t\tfor (int j= 0; j < size2; j++) {");
//      m_outstream.WriteLine("\t\t\t\tif (sequenceLength != 0) {");
//      m_outstream.WriteLine("\t\t\t\t\tres[i][j] = sequenceInteger;");
//      m_outstream.WriteLine("\t\t\t\t\tsequenceLength--;");
//      m_outstream.WriteLine("\t\t\t\t\tcontinue;");
//      m_outstream.WriteLine("\t\t\t\t}");
//      m_outstream.WriteLine("\t\t\t\tcommaIndex = st.IndexOf(',');");
//      m_outstream.WriteLine("\t\t\t\tworkString = (commaIndex==-1) ? st :");
//      m_outstream.WriteLine("\t\t\t\t\tst.Substring(0, commaIndex);");
//      m_outstream.WriteLine("\t\t\t\tst = st.Substring(commaIndex+1);");
//      m_outstream.WriteLine("\t\t\t\tcolonIndex = workString.IndexOf(':');");
//      m_outstream.WriteLine("\t\t\t\tif (colonIndex == -1) {");
//      m_outstream.WriteLine("\t\t\t\t\tres[i][j]=System.Int32.Parse(workString);");
//      m_outstream.WriteLine("\t\t\t\t\tcontinue;");
//      m_outstream.WriteLine("\t\t\t\t}");
//      m_outstream.WriteLine("\t\t\t\tlengthString =");
//      m_outstream.WriteLine("\t\t\t\t\tworkString.Substring(colonIndex+1);");
//      m_outstream.WriteLine("\t\t\t\tsequenceLength=System.Int32.Parse(lengthString);");
//      m_outstream.WriteLine("\t\t\t\tworkString=workString.Substring(0,colonIndex);");
//      m_outstream.WriteLine("\t\t\t\tsequenceInteger=System.Int32.Parse(workString);");
//      m_outstream.WriteLine("\t\t\t\tres[i][j] = sequenceInteger;");
//      m_outstream.WriteLine("\t\t\t\tsequenceLength--;");
//      m_outstream.WriteLine("\t\t\t}");
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine("\t\treturn res;");
//      m_outstream.WriteLine("\t}");
        }
Esempio n. 22
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
        }
Esempio n. 23
0
        /***************************************************************
         *    Function: emit_construct
         *    Description: Emits constructor, member variables,
         *    and constants.
         **************************************************************/
        private void emit_construct
        (
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            /* Constants */
//      m_outstream.WriteLine("\tprivate const int YY_BUFFER_SIZE = 512;");
//
//      m_outstream.WriteLine("\tprivate const int YY_F = -1;");
//      m_outstream.WriteLine("\tprivate const int YY_NO_STATE = -1;");
//
//      m_outstream.WriteLine("\tprivate const int YY_NOT_ACCEPT = 0;");
//      m_outstream.WriteLine("\tprivate const int YY_START = 1;");
//      m_outstream.WriteLine("\tprivate const int YY_END = 2;");
//      m_outstream.WriteLine("\tprivate const int YY_NO_ANCHOR = 4;");

            // internal
//      m_outstream.WriteLine("\tprivate const int YY_BOL = "+m_spec.BOL+";");
//      m_outstream.WriteLine("\tprivate const int YY_EOF = "+m_spec.EOF+";");
            // external
            if (m_spec.m_integer_type || m_spec.m_yyeof)
            {
                m_outstream.WriteLine("\tpublic const int YYEOF = -1;");
            }

            /* User specified class code. */
            if (null != m_spec.m_class_code)
            {
                m_outstream.Write(new string(m_spec.m_class_code, 0,
                                             m_spec.m_class_read));
            }

            /* Member Variables */
//      m_outstream.WriteLine("\tprivate System.IO.TextReader yy_reader;");
//      m_outstream.WriteLine("\tprivate int yy_buffer_index;");
//      m_outstream.WriteLine("\tprivate int yy_buffer_read;");
//      m_outstream.WriteLine("\tprivate int yy_buffer_start;");
//      m_outstream.WriteLine("\tprivate int yy_buffer_end;");
//      m_outstream.WriteLine("\tprivate char[] yy_buffer;");
            if (m_spec.m_count_chars)
            {
                //m_outstream.WriteLine("\tprivate int yychar;");
            }
            if (m_spec.m_count_lines)
            {
                //m_outstream.WriteLine("\tprivate int yyline;");
            }
//      m_outstream.WriteLine("\tprivate bool yy_at_bol;");
//      m_outstream.WriteLine("\tprivate int yy_lexical_state;");

            /*if (m_spec.m_count_lines || true == m_spec.m_count_chars)
             *      {
             *        m_outstream.WriteLine("\tprivate int yy_buffer_prev_start;");
             *      }*/
            m_outstream.WriteLine();


            /* Function: first constructor (Reader) */
            m_outstream.Write("\t");
            m_outstream.Write("public ");
            m_outstream.Write(new string(m_spec.m_class_name));
            m_outstream.Write(" ()");

            //SI:

            /*if (null != m_spec.m_init_throw_code)
             *    {
             *        m_outstream.WriteLine();
             *        m_outstream.Write("\t\tthrows ");
             *        m_outstream.Write(new string(m_spec.m_init_throw_code,0,
             *            m_spec.m_init_throw_read));
             *        m_outstream.WriteLine();
             *        m_outstream.WriteLine("\t\t{");
             *    }
             *    else
             *    {*/
            m_outstream.WriteLine(" {");

            m_outstream.WriteLine("\tYY_BOL = " + m_spec.BOL + ";");
            m_outstream.WriteLine("\tYY_EOF = " + m_spec.EOF + ";");

            //SI:   m_outstream.WriteLine("\t\tthis ();");
//      m_outstream.WriteLine("\t\tif (null == yy_reader1) {");
//      m_outstream.WriteLine("\t\t\tthrow (new System.Exception(\"Error: Bad input stream initializer.\"));");
//      m_outstream.WriteLine("\t\t}");
//      m_outstream.WriteLine("\t\tyy_reader = yy_reader1;");
//      m_outstream.WriteLine("\t}");
            m_outstream.WriteLine();


            /*
             *    m_outstream.Write("\t");
             *    if (true == m_spec.m_public)
             *    {
             *        m_outstream.Write("public ");
             *    }
             *    m_outstream.Write(new string(m_spec.m_class_name));
             *    m_outstream.Write(" (java.io.InputStream instream)");
             *
             *    if (null != m_spec.m_init_throw_code)
             *    {
             *        m_outstream.WriteLine();
             *        m_outstream.Write("\t\tthrows ");
             *        m_outstream.WriteLine(new string(m_spec.m_init_throw_code,0,
             *            m_spec.m_init_throw_read));
             *        m_outstream.WriteLine("\t\t{");
             *    }
             *    else
             *    {
             *        m_outstream.WriteLine(" {");
             *    }
             *
             *    m_outstream.WriteLine("\t\tthis ();");
             *    m_outstream.WriteLine("\t\tif (null == instream) {");
             *    m_outstream.WriteLine("\t\t\tthrow (new Error(\"Error: Bad input "
             + "stream initializer.\"));");
             +    m_outstream.WriteLine("\t\t}");
             +    m_outstream.WriteLine("\t\tyy_reader = new java.io.BufferedReader(new java.io.InputStreamReader(instream));");
             +    m_outstream.WriteLine("\t}");
             +    m_outstream.WriteLine();
             */

            /* Function: third, private constructor - only for internal use */
//      m_outstream.Write("\tprivate ");
//      m_outstream.Write(new string(m_spec.m_class_name));
//      m_outstream.Write(" ()");

            //SI:throw code not necceasary

            /*if (null != m_spec.m_init_throw_code)
             *    {
             *        m_outstream.WriteLine();
             *        m_outstream.Write("\t\tthrows ");
             *        m_outstream.WriteLine(new string(m_spec.m_init_throw_code,0,
             *            m_spec.m_init_throw_read));
             *        m_outstream.WriteLine("\t\t{");
             *    }
             *    else
             *    {*/
//      m_outstream.WriteLine(" {");
//
//
//      m_outstream.WriteLine("\t\tyy_buffer = new char[YY_BUFFER_SIZE];");
//      m_outstream.WriteLine("\t\tyy_buffer_read = 0;");
//      m_outstream.WriteLine("\t\tyy_buffer_index = 0;");
//      m_outstream.WriteLine("\t\tyy_buffer_start = 0;");
//      m_outstream.WriteLine("\t\tyy_buffer_end = 0;");
//      if (m_spec.m_count_chars)
//      {
//        m_outstream.WriteLine("\t\tyychar = 0;");
//      }
//      if (m_spec.m_count_lines)
//      {
//        m_outstream.WriteLine("\t\tyyline = 0;");
//      }
//      m_outstream.WriteLine("\t\tyy_at_bol = true;");
//      m_outstream.WriteLine("\t\tyy_lexical_state = YYINITIAL;");

            /*if (m_spec.m_count_lines || true == m_spec.m_count_chars)
             *      {
             *        m_outstream.WriteLine("\t\tyy_buffer_prev_start = 0;");
             *      }*/

            /* User specified constructor code. */
            if (null != m_spec.m_init_code)
            {
                m_outstream.Write(new string(m_spec.m_init_code, 0,
                                             m_spec.m_init_read));
            }

            m_outstream.WriteLine("\t}");
            m_outstream.WriteLine();
        }
Esempio n. 24
0
        /***************************************************************
         *    Function: e_closure
         *    Description: Alters and returns input Set.
         **************************************************************/
        private void e_closure
        (
            CBunch bunch
        )
        {
            Stack nfa_stack;
            int   size;
            int   i;
            CNfa  state;

            /* Debug checks. */
      #if (DEBUG)
            {
                CUtility.ASSERT(null != bunch);
                CUtility.ASSERT(null != bunch.m_nfa_set);
                CUtility.ASSERT(null != bunch.m_nfa_bit);
            }
      #endif

            bunch.m_accept       = null;
            bunch.m_anchor       = CSpec.NONE;
            bunch.m_accept_index = CUtility.INT_MAX;

            /* Create initial stack. */
            nfa_stack = new Stack();
            size      = bunch.m_nfa_set.size();
            for (i = 0; i < size; ++i)
            {
                state = (CNfa)bunch.m_nfa_set.elementAt(i);

        #if (DEBUG)
                {
                    CUtility.ASSERT(bunch.m_nfa_bit.Get(state.m_label));
                }
        #endif

                nfa_stack.Push(state);
            }

            /* Main loop. */
            //while (false == nfa_stack.empty())
            while (nfa_stack.Count > 0)
            {
                state = (CNfa)nfa_stack.Pop();

        #if (OLD_DUMP_DEBUG)
                {
                    if (null != state.m_accept)
                    {
                        System.Console.WriteLine("Looking at accepting state " + state.m_label
                                                 + " with <"
                                                 + (new string(state.m_accept.m_action, 0,
                                                               state.m_accept.m_action_read))
                                                 + ">");
                    }
                }
        #endif

                if (null != state.m_accept &&
                    state.m_label < bunch.m_accept_index)
                {
                    bunch.m_accept_index = state.m_label;
                    bunch.m_accept       = state.m_accept;
                    bunch.m_anchor       = state.m_anchor;

          #if (OLD_DUMP_DEBUG)
                    {
                        System.Console.WriteLine("Found accepting state " + state.m_label
                                                 + " with <"
                                                 + (new string(state.m_accept.m_action, 0,
                                                               state.m_accept.m_action_read))
                                                 + ">");
                    }
          #endif

          #if (DEBUG)
                    {
                        CUtility.ASSERT(null != bunch.m_accept);
                        CUtility.ASSERT(CSpec.NONE == bunch.m_anchor ||
                                        0 != (bunch.m_anchor & CSpec.END) ||
                                        0 != (bunch.m_anchor & CSpec.START));
                    }
          #endif
                }

                if (CNfa.EPSILON == state.m_edge)
                {
                    if (null != state.m_next)
                    {
                        if (false == bunch.m_nfa_set.contains(state.m_next))
                        {
              #if (DEBUG)
                            {
                                CUtility.ASSERT(false == bunch.m_nfa_bit.Get(state.m_next.m_label));
                            }
              #endif

                            bunch.m_nfa_bit.Set(state.m_next.m_label);
                            bunch.m_nfa_set.addElement(state.m_next);
                            nfa_stack.Push(state.m_next);
                        }
                    }

                    if (null != state.m_next2)
                    {
                        if (false == bunch.m_nfa_set.contains(state.m_next2))
                        {
              #if (DEBUG)
                            {
                                CUtility.ASSERT(false == bunch.m_nfa_bit.Get(state.m_next2.m_label));
                            }
              #endif

                            bunch.m_nfa_bit.Set(state.m_next2.m_label);
                            bunch.m_nfa_set.addElement(state.m_next2);
                            nfa_stack.Push(state.m_next2);
                        }
                    }
                }
            }

            if (null != bunch.m_nfa_set)
            {
                sortStates(bunch.m_nfa_set);
            }

            return;
        }
Esempio n. 25
0
        /***************************************************************
         *    Function: emit_actions
         *    Description:
         **************************************************************/
        private void emit_actions
        (
            string tabs
        )
        {
            int size;

      #if (DEBUG)
            {
                CUtility.ASSERT(m_spec.m_accept_vector.size()
                                == m_spec.m_anchor_array.Length);
            }
      #endif

            //minimise output states
            size = m_spec.m_accept_vector.size();
            Hashtable states = new Hashtable();

            for (int elem = 0; elem < size; ++elem)
            {
                object accept = m_spec.m_accept_vector.elementAt(elem);
                if (accept != null)
                {
                    ArrayList ii = states[accept] as ArrayList;
                    if (ii == null)
                    {
                        states[accept] = ii = new ArrayList();
                    }
                    ii.Add(elem);
                }
            }

            //for (elem = 0; elem < size; ++elem)
            foreach (CAccept accept in states.Keys)
            {
                //accept = (CAccept) m_spec.m_accept_vector.elementAt(elem);
                ArrayList ii = states[accept] as ArrayList;

                int i = 0;

                m_outstream.Write(tabs);

                foreach (int elem in ii)
                {
                    m_outstream.Write("case " + elem
                                      + ": ");
                    if (++i % 8 == 0)
                    {
                        m_outstream.WriteLine();
                        if (i != ii.Count - 1)
                        {
                            m_outstream.Write(tabs);
                        }
                    }
                }
                if (i % 8 != 0)
                {
                    m_outstream.WriteLine();
                }
                string tmp   = new string(accept.m_action, 0, accept.m_action_read);
                int    lines = tmp.Split('\n').Length;
                //m_outstream.WriteLine("#line {0} \"{1}\"", accept.m_line_number + 1 - lines, m_spec.inputfilename);
                //m_outstream.Write(tabs + "\t");

                //Added by SI:
//          if (tmp.Equals("{ }")) tmp="break;";
//          //Added by SI:
//          if (tmp.Equals("")) tmp="break;";
                m_outstream.Write(tmp);
                m_outstream.WriteLine();
                //m_outstream.WriteLine("#line {0} \"{1}\"", accept.m_line_number, m_spec.inputfilename);
                m_outstream.WriteLine(tabs + "\tbreak;");
//          m_outstream.WriteLine(tabs + "case " + bogus_index + ":");
//          m_outstream.WriteLine(tabs + "\tbreak;");
//          --bogus_index;
            }
        }
Esempio n. 26
0
        /***************************************************************
         *   Function: make_dtrans
         *   Description: Creates uncompressed CDTrans transition table.
         **************************************************************/
        private void make_dtrans
        (
        )
        /* throws java.lang.CloneNotSupportedException*/
        {
            //CDfa next;
            CDfa    dfa;
            CBunch  bunch;
            int     i;
            int     nextstate;
            int     size;
            CDTrans dtrans;
            CNfa    nfa;
            int     istate;
            int     nstates;

            if (m_spec.m_verbose)
            {
                System.Console.Write("Working on DFA states.");
            }

            /* Reference passing type and initializations. */
            bunch          = new CBunch();
            m_unmarked_dfa = 0;

            /* Allocate mapping array. */
            nstates = m_spec.m_state_rules.Length;
            m_spec.m_state_dtrans = new int[nstates];

            for (istate = 0; nstates > istate; ++istate)
            {
                /* CSA bugfix: if we skip all zero size rules, then
                 *         an specification with no rules produces an illegal
                 *         lexer (0 states) instead of a lexer that rejects
                 *         everything (1 nonaccepting state). [27-Jul-1999]
                 *      if (0 == m_spec.m_state_rules[istate].size())
                 *        {
                 *      m_spec.m_state_dtrans[istate] = CDTrans.F;
                 *      continue;
                 *        }
                 */

                /* Create start state and initialize fields. */
                //SI:testing
                //bunch.m_nfa_set = (Vector) m_spec.m_state_rules[istate].Clone();
                bunch.m_nfa_set = (Vector)((m_spec.m_state_rules[istate]).Clone());
                sortStates(bunch.m_nfa_set);

                bunch.m_nfa_bit = new SparseBitSet();

                /* Initialize bit Set. */
                size = bunch.m_nfa_set.size();
                for (i = 0; size > i; ++i)
                {
                    nfa = (CNfa)bunch.m_nfa_set.elementAt(i);
                    bunch.m_nfa_bit.Set(nfa.m_label);
                }

                bunch.m_accept       = null;
                bunch.m_anchor       = CSpec.NONE;
                bunch.m_accept_index = CUtility.INT_MAX;

                e_closure(bunch);
                add_to_dstates(bunch);

                m_spec.m_state_dtrans[istate] = m_spec.m_dtrans_vector.size();

                /* Main loop of CDTrans creation. */
                while (null != (dfa = get_unmarked()))
                {
                    if (m_spec.m_verbose)
                    {
                        System.Console.Write(".");
                        System.Console.Out.Flush();
                    }

          #if (DEBUG)
                    {
                        CUtility.ASSERT(false == dfa.m_mark);
                    }
          #endif

                    /* Get first unmarked node, then mark it. */
                    dfa.m_mark = true;

                    /* Allocate new CDTrans, then initialize fields. */
                    dtrans          = new CDTrans(m_spec.m_dtrans_vector.size(), m_spec);
                    dtrans.m_accept = dfa.m_accept;
                    dtrans.m_anchor = dfa.m_anchor;

                    /* Set CDTrans array for each character transition. */
                    for (i = 0; i < m_spec.m_dtrans_ncols; ++i)
                    {
            #if (DEBUG)
                        {
                            CUtility.ASSERT(0 <= i);
                            CUtility.ASSERT(m_spec.m_dtrans_ncols > i);
                        }
            #endif

                        /* Create new dfa Set by attempting character transition. */
                        move(dfa.m_nfa_set, dfa.m_nfa_bit, i, bunch);
                        if (null != bunch.m_nfa_set)
                        {
                            e_closure(bunch);
                        }

            #if (DEBUG)
                        {
                            CUtility.ASSERT((null == bunch.m_nfa_set &&
                                             null == bunch.m_nfa_bit) ||
                                            (null != bunch.m_nfa_set &&
                                             null != bunch.m_nfa_bit));
                        }
            #endif

                        /* Create new state or Set state to empty. */
                        if (null == bunch.m_nfa_set)
                        {
                            nextstate = CDTrans.F;
                        }
                        else
                        {
                            nextstate = in_dstates(bunch);

                            if (NOT_IN_DSTATES == nextstate)
                            {
                                nextstate = add_to_dstates(bunch);
                            }
                        }

            #if (DEBUG)
                        {
                            CUtility.ASSERT(nextstate < m_spec.m_dfa_states.Count);
                        }
            #endif

                        dtrans.m_dtrans[i] = nextstate;
                    }

          #if (DEBUG)
                    {
                        CUtility.ASSERT(m_spec.m_dtrans_vector.size() == dfa.m_label);
                    }
          #endif

                    m_spec.m_dtrans_vector.addElement(dtrans);
                }
            }
            if (m_spec.m_verbose)
            {
                System.Console.WriteLine();
            }
        }
Esempio n. 27
0
        /***************************************************************
         *    Function: minimize
         *    Description: Removes redundant transition table states.
         **************************************************************/
        private void minimize
        (
        )
        {
            Vector  dtrans_group;
            Vector  new_group;
            int     i;
            int     j;
            int     old_group_count;
            int     group_count;
            CDTrans next;
            CDTrans first;
            int     goto_first;
            int     goto_next;
            int     c;
            int     group_size;
            bool    added;

            init_groups();

            group_count     = m_group.size();
            old_group_count = group_count - 1;

            while (old_group_count != group_count)
            {
                old_group_count = group_count;

        #if (DEBUG)
                {
                    CUtility.ASSERT(m_group.Count == group_count);
                }
        #endif

                for (i = 0; i < group_count; ++i)
                {
                    dtrans_group = (Vector)m_group.elementAt(i);

                    group_size = dtrans_group.size();
                    if (group_size <= 1)
                    {
                        continue;
                    }

                    new_group = new Vector();
                    added     = false;

                    first = (CDTrans)dtrans_group.elementAt(0);
                    for (j = 1; j < group_size; ++j)
                    {
                        next = (CDTrans)dtrans_group.elementAt(j);

                        for (c = 0; c < m_spec.m_dtrans_ncols; ++c)
                        {
                            goto_first = first.m_dtrans[c];
                            goto_next  = next.m_dtrans[c];

                            if (goto_first != goto_next &&
                                (goto_first == CDTrans.F ||
                                 goto_next == CDTrans.F ||
                                 m_ingroup[goto_next] != m_ingroup[goto_first]))
                            {
                #if (DEBUG)
                                {
                                    CUtility.ASSERT(dtrans_group.elementAt(j) == next);
                                }
                #endif

                                dtrans_group.removeElementAt(j);
                                --j;
                                --group_size;
                                new_group.addElement(next);
                                if (false == added)
                                {
                                    added = true;
                                    ++group_count;
                                    m_group.addElement(new_group);
                                }
                                m_ingroup[next.m_label] = m_group.Count - 1;

                #if (DEBUG)
                                {
                                    CUtility.ASSERT(m_group.contains(new_group)
                                                    == true);
                                    CUtility.ASSERT(m_group.contains(dtrans_group)
                                                    == true);
                                    CUtility.ASSERT(dtrans_group.contains(first)
                                                    == true);
                                    CUtility.ASSERT(dtrans_group.contains(next)
                                                    == false);
                                    CUtility.ASSERT(new_group.contains(first)
                                                    == false);
                                    CUtility.ASSERT(new_group.contains(next)
                                                    == true);
                                    CUtility.ASSERT(dtrans_group.size() == group_size);
                                    CUtility.ASSERT(i == m_ingroup[first.m_label]);
                                    CUtility.ASSERT((m_group.size() - 1)
                                                    == m_ingroup[next.m_label]);
                                }
                #endif

                                break;
                            }
                        }
                    }
                }
            }

            if (m_spec.m_verbose)
            {
                System.Console.WriteLine(m_group.size() + " states after removal of redundant states.");
            }

            if (m_spec.m_verbose &&
                CUtility.OLD_DUMP_DEBUG)
            {
                System.Console.WriteLine();
                System.Console.WriteLine("States grouped as follows after minimization");
                pgroups();
            }

            fix_dtrans();
        }
Esempio n. 28
0
        /***************************************************************
         *    Function: move
         *    Description: Returns null if resulting NFA Set is empty.
         **************************************************************/
        void move
        (
            Vector nfa_set,
            SparseBitSet nfa_bit,
            int b,
            CBunch bunch
        )
        {
            int  size;
            int  index;
            CNfa state;

            bunch.m_nfa_set = null;
            bunch.m_nfa_bit = null;

            size = nfa_set.Count;
            //  System.Console.WriteLine(size);
            for (index = 0; index < size; ++index)
            {
                state = (CNfa)nfa_set.elementAt(index);
                //   System.Console.WriteLine(index+" "+state.m_set);

                if (b == state.m_edge ||
                    (CNfa.CCL == state.m_edge &&
                     state.m_set.contains(b)))
                {
                    //     System.Console.WriteLine(state.m_edge+" "+b);
                    if (null == bunch.m_nfa_set)
                    {
            #if (DEBUG)
                        {
                            CUtility.ASSERT(null == bunch.m_nfa_bit);
                        }
            #endif

                        bunch.m_nfa_set = new Vector();

                        /*bunch.m_nfa_bit
                         *          = new SparseBitSet(m_spec.m_nfa_states.size());*/
                        bunch.m_nfa_bit = new SparseBitSet();
                    }

                    bunch.m_nfa_set.addElement(state.m_next);

                    /*System.Console.WriteLine("Size of bitset: " + bunch.m_nfa_bit.size());
                     *        System.Console.WriteLine("Reference index: " + state.m_next.m_label);
                     *        System.out.flush();*/
                    bunch.m_nfa_bit.Set(state.m_next.m_label);
                }
            }

            if (null != bunch.m_nfa_set)
            {
        #if (DEBUG)
                {
                    CUtility.ASSERT(null != bunch.m_nfa_bit);
                }
        #endif

                sortStates(bunch.m_nfa_set);
            }

            return;
        }
Esempio n. 29
0
        /***************************************************************
         *    Function: emit_driver
         *    Description:
         **************************************************************/
        private void emit_driver
        (
        )
        {
      #if (DEBUG)
            {
                CUtility.ASSERT(null != m_spec);
                CUtility.ASSERT(null != m_outstream);
            }
      #endif

            emit_table();

//      if (m_spec.m_integer_type)
//      {
//        m_outstream.Write("\tpublic int ");
//        m_outstream.Write(new string(m_spec.m_function_name));
//        m_outstream.WriteLine(" ()");
//      }
//      else if (m_spec.m_intwrap_type)
//      {
//        m_outstream.Write("\tpublic int ");
//        m_outstream.Write(new string(m_spec.m_function_name));
//        m_outstream.WriteLine(" ()");
//      }
//      else
            {
                m_outstream.Write("\tpublic override ");
                m_outstream.Write(new string(m_spec.m_type_name));
                m_outstream.Write(" ");
                m_outstream.Write(new string(m_spec.m_function_name));
                m_outstream.WriteLine(" ()");
            }

            /*m_outstream.WriteLine("\t\tthrows java.io.IOException {");*/
            //     m_outstream.Write("\t\tthrows java.io.IOException");
            if (null != m_spec.m_yylex_throw_code)
            {
                m_outstream.Write(", ");
                m_outstream.Write(new string(m_spec.m_yylex_throw_code, 0,
                                             m_spec.m_yylex_throw_read));
                m_outstream.WriteLine();
                m_outstream.WriteLine("\t\t{");
            }
            else
            {
                m_outstream.WriteLine(" {");
            }

            m_outstream.WriteLine("\t\tint yy_lookahead;");
            m_outstream.WriteLine("\t\tint yy_anchor = YY_NO_ANCHOR;");

            /*m_outstream.WriteLine("\t\tint yy_state "
             + "= yy_initial_dtrans(yy_lexical_state);");*/
            m_outstream.WriteLine("\t\tint yy_state = yy_state_dtrans[yy_lexical_state];");
            m_outstream.WriteLine("\t\tint yy_next_state = YY_NO_STATE;");
            /*m_outstream.WriteLine("\t\tint yy_prev_stave = YY_NO_STATE;");*/
            m_outstream.WriteLine("\t\tint yy_last_accept_state = YY_NO_STATE;");
            m_outstream.WriteLine("\t\tbool yy_initial = true;");
            m_outstream.WriteLine("\t\tint yy_this_accept;");
            m_outstream.WriteLine();

            m_outstream.WriteLine("\t\tyy_mark_start();");
            /*m_outstream.WriteLine("\t\tyy_this_accept = yy_accept(yy_state);");*/
            m_outstream.WriteLine("\t\tyy_this_accept = yy_acpt[yy_state];");
            m_outstream.WriteLine("\t\tif (YY_NOT_ACCEPT != yy_this_accept) {");
            m_outstream.WriteLine("\t\t\tyy_last_accept_state = yy_state;");
            m_outstream.WriteLine("\t\t\tyy_mark_end();");
            m_outstream.WriteLine("\t\t}");

#if (NOT_EDBG)
            {
                m_outstream.WriteLine("\t\tSystem.Console.WriteLine(\"Begin\");");
            }
#endif

            m_outstream.WriteLine("\t\twhile (true) {");

            m_outstream.WriteLine("\t\t\tif (yy_initial && yy_at_bol) " +
                                  "yy_lookahead = YY_BOL;");
            m_outstream.WriteLine("\t\t\telse yy_lookahead = yy_advance();");
            m_outstream.WriteLine("\t\t\tyy_next_state = YY_F;");

            /*m_outstream.WriteLine("\t\t\t\tyy_next_state = "
             + "yy_next(yy_state,yy_lookahead);");*/
            m_outstream.WriteLine("\t\t\tyy_next_state = "
                                  + "yy_nxt[yy_rmap[yy_state],yy_cmap[yy_lookahead]];");

#if (NOT_EDBG)
            {
                m_outstream.WriteLine("System.Console.WriteLine(\"Current state: \""
                                      + " + yy_state");
                m_outstream.WriteLine("+ \"\tCurrent input: \"");
                m_outstream.WriteLine(" + ((char) yy_lookahead));");
            }
#endif
#if (NOT_EDBG)
            {
                m_outstream.WriteLine("\t\t\tSystem.Console.WriteLine(\"State = \""
                                      + "+ yy_state);");
                m_outstream.WriteLine("\t\t\tSystem.Console.WriteLine(\"Accepting status = \""
                                      + "+ yy_this_accept);");
                m_outstream.WriteLine("\t\t\tSystem.Console.WriteLine(\"Last accepting state = \""
                                      + "+ yy_last_accept_state);");
                m_outstream.WriteLine("\t\t\tSystem.Console.WriteLine(\"Next state = \""
                                      + "+ yy_next_state);");
                m_outstream.WriteLine("\t\t\tSystem.Console.WriteLine(\"Lookahead input = \""
                                      + "+ ((char) yy_lookahead));");
            }
#endif
            // handle bare EOF.
            m_outstream.WriteLine("\t\t\tif (YY_EOF == yy_lookahead "
                                  + "&& true == yy_initial) {");
            if (null != m_spec.m_eof_code)
            {
                m_outstream.WriteLine("\t\t\t\tyy_do_eof();");
            }
            if (m_spec.m_integer_type)
            {
                m_outstream.WriteLine("\t\t\t\treturn Yytoken.EOF;");
            }
            else if (null != m_spec.m_eof_value_code)
            {
                m_outstream.Write(new string(m_spec.m_eof_value_code, 0,
                                             m_spec.m_eof_value_read));
            }
            else
            {
                m_outstream.WriteLine("\t\t\t\treturn Yytoken.EOF;");
            }
            m_outstream.WriteLine("\t\t\t}");

            m_outstream.WriteLine("\t\t\tif (YY_F != yy_next_state) {");
            m_outstream.WriteLine("\t\t\t\tyy_state = yy_next_state;");
            m_outstream.WriteLine("\t\t\t\tyy_initial = false;");
            /*m_outstream.WriteLine("\t\t\t\tyy_this_accept = yy_accept(yy_state);");*/
            m_outstream.WriteLine("\t\t\t\tyy_this_accept = yy_acpt[yy_state];");
            m_outstream.WriteLine("\t\t\t\tif (YY_NOT_ACCEPT != yy_this_accept) {");
            m_outstream.WriteLine("\t\t\t\t\tyy_last_accept_state = yy_state;");
            m_outstream.WriteLine("\t\t\t\t\tyy_mark_end();");
            m_outstream.WriteLine("\t\t\t\t}");
            /*m_outstream.WriteLine("\t\t\t\tyy_prev_state = yy_state;");*/
            /*m_outstream.WriteLine("\t\t\t\tyy_state = yy_next_state;");*/
            m_outstream.WriteLine("\t\t\t}");

            m_outstream.WriteLine("\t\t\telse {");

            m_outstream.WriteLine("\t\t\t\tif (YY_NO_STATE == yy_last_accept_state) {");

            //m_outstream.WriteLine("\t\t\t\t\tthrow (new System.Exception(\"Lexical Error: Unmatched Input.\"));");
            m_outstream.WriteLine("\t\t\t\t\treturn Error();");
            m_outstream.WriteLine("\t\t\t\t}");

            m_outstream.WriteLine("\t\t\t\telse {");

            m_outstream.WriteLine("\t\t\t\t\tyy_anchor = yy_acpt[yy_last_accept_state];");
            m_outstream.WriteLine("\t\t\t\t\tif (0 != (YY_END & yy_anchor)) {");
            m_outstream.WriteLine("\t\t\t\t\t\tyy_move_end();");
            m_outstream.WriteLine("\t\t\t\t\t}");
            m_outstream.WriteLine("\t\t\t\t\tyy_to_mark();");

            m_outstream.WriteLine("\t\t\t\t\tswitch (yy_last_accept_state) {");

            emit_actions("\t\t\t\t\t");

            m_outstream.WriteLine("\t\t\t\t\tdefault:");
            //SI:break added
            m_outstream.WriteLine("\t\t\t\t\t\tyy_error(YY_E_INTERNAL,false);break;");
            /*m_outstream.WriteLine("\t\t\t\t\t\treturn null;");*/
            //SI:removed
            // m_outstream.WriteLine("\t\t\t\t\tcase -1:");
            m_outstream.WriteLine("\t\t\t\t\t}");


            m_outstream.WriteLine("\t\t\t\t\tyy_initial = true;");
            m_outstream.WriteLine("\t\t\t\t\tyy_state "
                                  + "= yy_state_dtrans[yy_lexical_state];");
            m_outstream.WriteLine("\t\t\t\t\tyy_next_state = YY_NO_STATE;");
            /*m_outstream.WriteLine("\t\t\t\t\tyy_prev_state = YY_NO_STATE;");*/
            m_outstream.WriteLine("\t\t\t\t\tyy_last_accept_state = YY_NO_STATE;");

            m_outstream.WriteLine("\t\t\t\t\tyy_mark_start();");

            /*m_outstream.WriteLine("\t\t\t\t\tyy_this_accept = yy_accept(yy_state);");*/
            m_outstream.WriteLine("\t\t\t\t\tyy_this_accept = yy_acpt[yy_state];");
            m_outstream.WriteLine("\t\t\t\t\tif (YY_NOT_ACCEPT != yy_this_accept) {");
            m_outstream.WriteLine("\t\t\t\t\t\tyy_last_accept_state = yy_state;");
            m_outstream.WriteLine("\t\t\t\t\t\tyy_mark_end();");
            m_outstream.WriteLine("\t\t\t\t\t}");

            m_outstream.WriteLine("\t\t\t\t}");
            m_outstream.WriteLine("\t\t\t}");
            m_outstream.WriteLine("\t\t}");
            m_outstream.WriteLine("\t}");
        }
Esempio n. 30
0
        /***************************************************************
         *    Function: getLine
         *    Description: Returns true on EOF, false otherwise.
         *    Guarantees not to return a blank line, or a line
         *    of zero length.
         **************************************************************/
        public bool getLine
        (
        )
        {
            string lineStr;
            int    elem;

            /* Has EOF already been reached? */
            if (m_eof_reached)
            {
                return(EOF);
            }

            /* Pushback current line? */
            if (m_pushback_line)
            {
                m_pushback_line = false;

                /* Check for empty line. */
                for (elem = 0; elem < m_line_read; ++elem)
                {
                    if (false == CUtility.isspace(m_line[elem]))
                    {
                        break;
                    }
                }

                /* Nonempty? */
                if (elem < m_line_read)
                {
                    m_line_index = 0;
                    return(NOT_EOF);
                }
            }

            while (true)
            {
                if (null == (lineStr = m_input.ReadLine()))
                {
                    m_eof_reached = true;
                    m_line_index  = 0;
                    return(EOF);
                }
                m_line      = (lineStr + "\n").ToCharArray();
                m_line_read = m_line.Length;
                ++m_line_number;

                /* Check for empty lines and discard them. */
                elem = 0;
                while (CUtility.isspace(m_line[elem]))
                {
                    ++elem;
                    if (elem == m_line_read)
                    {
                        break;
                    }
                }

                if (elem < m_line_read)
                {
                    break;
                }
            }

            m_line_index = 0;
            return(NOT_EOF);
        }