Exemple #1
0
        //*
        // * Returns a string representation of a production pattern.
        // *
        // * @param prod the production pattern
        // *
        // * @return a detailed string representation of the pattern
        //

        private string ToString(ProductionPattern prod)
        {
            StringBuilder buffer = new StringBuilder();
            StringBuilder indent = new StringBuilder();
            LookAheadSet  @set   = default(LookAheadSet);
            int           i      = 0;

            buffer.Append(prod.Name);
            buffer.Append(" (");
            buffer.Append(prod.Id);
            buffer.Append(") ");
            for (i = 0; i <= buffer.Length - 1; i++)
            {
                indent.Append(" ");
            }
            buffer.Append("= ");
            indent.Append("| ");
            for (i = 0; i <= prod.Count - 1; i++)
            {
                if (i > 0)
                {
                    buffer.Append(indent);
                }
                buffer.Append(ToString(prod[i]));
                buffer.Append("" + Convert.ToChar(10) + "");
            }
            for (i = 0; i <= prod.Count - 1; i++)
            {
                @set = prod[i].LookAhead;
                if (@set.GetMaxLength() > 1)
                {
                    buffer.Append("Using ");
                    buffer.Append(@set.GetMaxLength());
                    buffer.Append(" token look-ahead for alternative ");
                    buffer.Append(i + 1);
                    buffer.Append(": ");
                    buffer.Append(@set.ToString(m_tokenizer));
                    buffer.Append("" + Convert.ToChar(10) + "");
                }
            }
            return(buffer.ToString());
        }
        //*
        // * Returns the union of all alternative look-ahead sets in a
        // * production pattern.
        // *
        // * @param pattern the production pattern
        // *
        // * @return a unified look-ahead set
        //

        private LookAheadSet FindUnion(ProductionPattern pattern)
        {
            LookAheadSet result = default(LookAheadSet);
            int          length = 0;
            int          i      = 0;

            for (i = 0; i <= pattern.Count - 1; i++)
            {
                result = pattern[i].LookAhead;
                if (result.GetMaxLength() > length)
                {
                    length = result.GetMaxLength();
                }
            }
            result = new LookAheadSet(length);
            for (i = 0; i <= pattern.Count - 1; i++)
            {
                result.AddAll(pattern[i].LookAhead);
            }

            return(result);
        }