Example #1
0
 /*-----------------------------------------------------------*/
 /*--- Constructor(s) ----------------------------------------*/
 /*-----------------------------------------------------------*/
 /// <summary>Full constructor. 
 /// </summary>
 /// <param name="prod">the production for the item.
 /// </param>
 /// <param name="pos"> the position of the "dot" within the production.
 /// </param>
 /// <param name="look">the set of lookahead symbols.
 /// 
 /// </param>
 public lalr_item(production prod, int pos, terminal_set look)
     : base(prod, pos)
 {
     _lookahead = look;
     _propagate_items = new CUP.runtime.SymbolStack();
     needs_propagation = true;
 }
Example #2
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /// <summary>Full constructor.
        /// </summary>
        /// <param name="prod">production this item uses.
        /// </param>
        /// <param name="pos"> position of the "dot" within the item.
        ///
        /// </param>
        public lr_item_core(production prod, int pos)
        {
            // symbol after_dot = null;
            production_part part;

            if (prod == null)
            {
                throw new internal_error("Attempt to create an lr_item_core with a null production");
            }

            _the_production = prod;

            if (pos < 0 || pos > _the_production.rhs_length())
            {
                throw new internal_error("Attempt to create an lr_item_core with a bad dot position");
            }

            _dot_pos = pos;

            /* compute and cache hash code now */
            _core_hash_cache = 13 * _the_production.GetHashCode() + pos;

            /* cache the symbol after the dot */
            if (_dot_pos < _the_production.rhs_length())
            {
                part = _the_production.rhs(_dot_pos);
                if (!part.is_action())
                {
                    _symbol_after_dot = ((symbol_part)part).the_symbol();
                }
            }
        }
Example #3
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/
        /// <summary>Full constructor.
        /// </summary>
        /// <param name="prod">production this item uses.
        /// </param>
        /// <param name="pos"> position of the "dot" within the item.
        /// 
        /// </param>
        public lr_item_core(production prod, int pos)
        {
            // symbol after_dot = null;
            production_part part;

            if (prod == null)
                throw new internal_error("Attempt to create an lr_item_core with a null production");

            _the_production = prod;

            if (pos < 0 || pos > _the_production.rhs_length())
                throw new internal_error("Attempt to create an lr_item_core with a bad dot position");

            _dot_pos = pos;

            /* compute and cache hash code now */
            _core_hash_cache = 13 * _the_production.GetHashCode() + pos;

            /* cache the symbol after the dot */
            if (_dot_pos < _the_production.rhs_length())
            {
                part = _the_production.rhs(_dot_pos);
                if (!part.is_action())
                    _symbol_after_dot = ((symbol_part) part).the_symbol();
            }
        }
Example #4
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/
        /// <summary>Simple constructor. 
        /// </summary>
        /// <param name="prod">the production this action reduces with.
        /// 
        /// </param>
        public reduce_action(production prod)
        {
            /* sanity check */
            if (prod == null)
                throw new internal_error("Attempt to create a reduce_action with a null production");

            _reduce_with = prod;
        }
Example #5
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Equality comparison.
        /// </summary>
        public virtual bool equals(production other)
        {
            if (other == null)
            {
                return(false);
            }
            return(other._index == _index);
        }
Example #6
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/


        /// <summary>Procedure that attempts to fix a shift/reduce error by using
        /// precedences.  --frankf 6/26/96
        ///
        /// if a production (also called rule) or the lookahead terminal
        /// has a precedence, then the table can be fixed.  if the rule
        /// has greater precedence than the terminal, a reduce by that rule
        /// in inserted in the table.  If the terminal has a higher precedence,
        /// it is shifted.  if they have equal precedence, then the associativity
        /// of the precedence is used to determine what to put in the table:
        /// if the precedence is left associative, the action is to reduce.
        /// if the precedence is right associative, the action is to shift.
        /// if the precedence is non associative, then it is a syntax error.
        /// *
        /// </summary>
        /// <param name="p">          the production
        /// </param>
        /// <param name="term_index"> the index of the lokahead terminal
        /// </param>
        /// <param name="parse_action_row"> a row of the action table
        /// </param>
        /// <param name="act">        the rule in conflict with the table entry
        ///
        /// </param>

        protected internal virtual bool fix_with_precedence(production p, int term_index, parse_action_row table_row, parse_action act)
        {
            terminal term = terminal.find(term_index);

            /* if the production has a precedence number, it can be fixed */
            if (p.precedence_num() > assoc.no_prec)
            {
                /* if production precedes terminal, put reduce in table */
                if (p.precedence_num() > term.precedence_num())
                {
                    table_row.under_term[term_index] = insert_reduce(table_row.under_term[term_index], act);
                    return(true);
                }
                else if (p.precedence_num() < term.precedence_num())
                {
                    table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                    return(true);
                }
                else
                {
                    /* they are == precedence */

                    /* equal precedences have equal sides, so only need to
                     * look at one: if it is right, put shift in table */
                    if (term.precedence_side() == assoc.right)
                    {
                        table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                        return(true);
                    }
                    else if (term.precedence_side() == assoc.left)
                    {
                        table_row.under_term[term_index] = insert_reduce(table_row.under_term[term_index], act);
                        return(true);
                    }
                    else if (term.precedence_side() == assoc.nonassoc)
                    {
                        table_row.under_term[term_index] = new nonassoc_action();
                        return(true);
                    }
                    else
                    {
                        /* something really went wrong */
                        throw new internal_error("Unable to resolve conflict correctly");
                    }
                }
            }
            else if (term.precedence_num() > assoc.no_prec)
            {
                table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                return(true);
            }

            /* otherwise, neither the rule nor the terminal has a precedence,
             * so it can't be fixed. */
            return(false);
        }
Example #7
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /// <summary>Simple constructor.
        /// </summary>
        /// <param name="prod">the production this action reduces with.
        ///
        /// </param>
        public reduce_action(production prod)
        {
            /* sanity check */
            if (prod == null)
            {
                throw new internal_error("Attempt to create a reduce_action with a null production");
            }

            _reduce_with = prod;
        }
Example #8
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Add a production to our set of productions.
        /// </summary>
        public virtual void  add_production(production prod)
        {
            /* catch improper productions */
            if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this)
            {
                throw new internal_error("Attempt to add invalid production to non terminal production table");
            }

            /* add it to the table, keyed with itself */
            SupportClass.PutElement(_productions, prod, prod);
        }
Example #9
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Produce a human readable dump of the grammar.
        /// </summary>
        public static void  dump_grammar()
        {
            System.Console.Error.WriteLine("===== Terminals =====");
            for (int tidx = 0, cnt = 0; tidx < terminal.number(); tidx++, cnt++)
            {
                System.Console.Error.Write("[" + tidx + "]" + terminal.find(tidx).name_Renamed_Method() + " ");
                if ((cnt + 1) % 5 == 0)
                {
                    System.Console.Error.WriteLine();
                }
            }
            System.Console.Error.WriteLine();
            System.Console.Error.WriteLine();

            System.Console.Error.WriteLine("===== Non terminals =====");
            for (int nidx = 0, cnt = 0; nidx < non_terminal.number(); nidx++, cnt++)
            {
                System.Console.Error.Write("[" + nidx + "]" + non_terminal.find(nidx).name_Renamed_Method() + " ");
                if ((cnt + 1) % 5 == 0)
                {
                    System.Console.Error.WriteLine();
                }
            }
            System.Console.Error.WriteLine();
            System.Console.Error.WriteLine();


            System.Console.Error.WriteLine("===== Productions =====");
            for (int pidx = 0; pidx < production.number(); pidx++)
            {
                production prod = production.find(pidx);
                System.Console.Error.Write("[" + pidx + "] " + prod.lhs().the_symbol().name_Renamed_Method() + " ::= ");
                for (int i = 0; i < prod.rhs_length(); i++)
                {
                    if (prod.rhs(i).is_action())
                    {
                        System.Console.Error.Write("{action} ");
                    }
                    else
                    {
                        System.Console.Error.Write(((symbol_part)prod.rhs(i)).the_symbol().name_Renamed_Method() + " ");
                    }
                }
                System.Console.Error.WriteLine();
            }
            System.Console.Error.WriteLine();
        }
Example #10
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Emit the production table.
        /// </summary>
        /// <param name="out">stream to produce output on.
        ///
        /// </param>
        protected internal static void  emit_production_table(System.IO.StreamWriter out_Renamed)
        {
            production[] all_prods;
            production   prod;

            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* collect up the productions in order */
            all_prods = new production[production.number()];
            for (System.Collections.IEnumerator p = production.all(); p.MoveNext();)
            {
                prod = (production)p.Current;
                all_prods[prod.index()] = prod;
            }

            // make short[,]
            short[][] prod_table = new short[production.number()][];
            for (int i = 0; i < production.number(); i++)
            {
                prod_table[i] = new short[2];
            }
            for (int i = 0; i < production.number(); i++)
            {
                prod = all_prods[i];
                // { lhs symbol , rhs size }
                prod_table[i][0] = (short)prod.lhs().the_symbol().index();
                prod_table[i][1] = (short)prod.rhs_length();
            }
            /* do the top of the table */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Production table. */");
            out_Renamed.Write("  private static string[] _strProductionTable = ");
            do_table_as_string(out_Renamed, prod_table);
            out_Renamed.WriteLine(";");
            out_Renamed.WriteLine("  protected static readonly short[][] _production_table  = CUP.runtime.lr_parser.unpackFromStrings(_strProductionTable);");
            // out_Renamed.Write("    unpackFromStrings(");
            // do_table_as_string(out_Renamed, prod_table);
            // out_Renamed.WriteLine(");");

            /* do the public accessor method */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Access to production table. */");
            out_Renamed.WriteLine("  public override short[][] production_table() " + "{return _production_table;}");

            production_table_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #11
0
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Constructor with default position and empty lookahead set. 
 /// </summary>
 /// <param name="prod">the production for the item.
 /// 
 /// </param>
 public lalr_item(production prod)
     : this(prod, 0, new terminal_set())
 {
 }
Example #12
0
 /// <summary>Constructor.
 /// </summary>
 /// <param name="base">      the production we are being factored out of.
 /// </param>
 /// <param name="lhs_sym">   the LHS symbol for this production.
 /// </param>
 /// <param name="rhs_parts"> array of production parts for the RHS.
 /// </param>
 /// <param name="rhs_len">   how much of the rhs_parts array is valid.
 /// </param>
 /// <param name="action_str">the trailing reduce action for this production.
 /// 
 /// </param>
 public action_production(production base_Renamed, non_terminal lhs_sym, production_part[] rhs_parts, int rhs_len, string action_str)
     : base(lhs_sym, rhs_parts, rhs_len, action_str)
 {
     _base_production = base_Renamed;
 }
Example #13
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Add a production to our set of productions. 
        /// </summary>
        public virtual void add_production(production prod)
        {
            /* catch improper productions */
            if (prod == null || prod.lhs() == null || prod.lhs().the_symbol() != this)
                throw new internal_error("Attempt to add invalid production to non terminal production table");

            /* add it to the table, keyed with itself */
            SupportClass.PutElement(_productions, prod, prod);
        }
Example #14
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Emit code for the non-public class holding the actual action code.
        /// </summary>
        /// <param name="out">       stream to produce output on.
        /// </param>
        /// <param name="start_prod">the start production of the grammar.
        ///
        /// </param>
        protected internal static void  emit_action_code(System.IO.StreamWriter out_Renamed, production start_prod)
        {
            production prod;

            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* class header */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("/** Cup generated class to encapsulate user supplied action code.*/");
            out_Renamed.WriteLine("public class " + pre("actions") + " {");

            /* user supplied code */
            if (action_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine(action_code);
            }

            /* field for parser object */
            out_Renamed.WriteLine("  private " + parser_class_name + " parser;");

            /* constructor */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Constructor */");
            out_Renamed.WriteLine("  public " + pre("actions") + "(" + parser_class_name + " parser) {");
            out_Renamed.WriteLine("    this.parser = parser;");
            out_Renamed.WriteLine("  }");

            /* action method head */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Method with the actual generated action code. */");
            out_Renamed.WriteLine("  public CUP.runtime.Symbol " + pre("do_action") + "(");
            out_Renamed.WriteLine("    int                        " + pre("act_num,"));
            out_Renamed.WriteLine("    CUP.runtime.lr_parser " + pre("parser,"));
            out_Renamed.WriteLine("    CUP.runtime.SymbolStack            " + pre("stack,"));
            out_Renamed.WriteLine("    int                        " + pre("top)"));
            out_Renamed.WriteLine("    {");

            /* declaration of result symbol */

            /* New declaration!! now return Symbol
             * 6/13/96 frankf */
            out_Renamed.WriteLine("      /* Symbol object for return from actions */");
            out_Renamed.WriteLine("      CUP.runtime.Symbol " + pre("result") + ";");
            out_Renamed.WriteLine();

            /* switch top */
            out_Renamed.WriteLine("      /* select the action based on the action number */");
            out_Renamed.WriteLine("      switch (" + pre("act_num") + ")");
            out_Renamed.WriteLine("        {");

            /* emit action code for each production as a separate case */
            for (System.Collections.IEnumerator p = production.all(); p.MoveNext();)
            {
                prod = (production)p.Current;

                /* case label */
                out_Renamed.WriteLine("          /*. . . . . . . . . . . . . . . . . . . .*/");
                out_Renamed.WriteLine("          case " + prod.index() + ": // " + prod.to_simple_string());

                /* give them their own block to work in */
                out_Renamed.WriteLine("            {");

                /* create the result symbol */

                /*make the variable RESULT which will point to the new Symbol (see below)
                 * and be changed by action code
                 * 6/13/96 frankf */
                string strSymType    = prod.lhs().the_symbol().stack_type().Trim();
                string strPrimitives = "int;float;double;short;char;byte;decimal;sbyte;bool;ushort;uint;long;ulong";
                if (strPrimitives.IndexOf(strSymType) > -1)
                {
                    string init = "";
                    switch (strSymType)
                    {
                    case "double":
                        init = " = 0.0";
                        break;

                    case "int":
                    case "uint":
                    case "short":
                    case "ushort":
                    case "byte":
                    case "sbyte":
                        init = " = 0";
                        break;

                    case "float":
                        init = " = 0.0f";
                        break;

                    case "decimal":
                        init = " = decimal.Zero";
                        break;

                    case "char":
                        init = " = '\\0'";
                        break;

                    case "long":
                    case "ulong":
                        init = " = 0L";
                        break;
                    }
                    if (strSymType == "double")
                    {
                        init = " = 0.0";
                    }

                    out_Renamed.WriteLine("              " + strSymType + " RESULT " + init + ";");
                }
                else
                {
                    out_Renamed.WriteLine("              " + strSymType + " RESULT = null;");
                }

                /* Add code to propagate RESULT assignments that occur in
                 * action code embedded in a production (ie, non-rightmost
                 * action code). 24-Mar-1998 CSA
                 */
                for (int i = 0; i < prod.rhs_length(); i++)
                {
                    // only interested in non-terminal symbols.
                    if (!(prod.rhs(i) is symbol_part))
                    {
                        continue;
                    }
                    symbol s = ((symbol_part)prod.rhs(i)).the_symbol();
                    if (!(s is non_terminal))
                    {
                        continue;
                    }
                    // skip this non-terminal unless it corresponds to
                    // an embedded action production.
                    if (((non_terminal)s).is_embedded_action == false)
                    {
                        continue;
                    }
                    // OK, it fits.  Make a conditional assignment to RESULT.
                    int index = prod.rhs_length() - i - 1;                     // last rhs is on top.
                    out_Renamed.WriteLine("              " + "// propagate RESULT from " + s.name_Renamed_Method());
                    out_Renamed.WriteLine("              " + "if ( " + "((CUP.runtime.Symbol) " + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + index + ")).Value != null )");
                    out_Renamed.WriteLine("                " + "RESULT = " + "(" + prod.lhs().the_symbol().stack_type() + ") " + "((CUP.runtime.Symbol) " + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + index + ")).Value;");
                }

                /* if there is an action string, emit it */
                if (prod.action() != null && prod.action().code_string() != null && !prod.action().Equals(""))
                {
                    out_Renamed.WriteLine(prod.action().code_string());
                }

                /* here we have the left and right values being propagated.
                 * must make this a command line option.
                 * frankf 6/18/96 */

                /* Create the code that assigns the left and right values of
                 * the new Symbol that the production is reducing to */
                if (emit.lr_values())
                {
                    int           loffset;
                    System.String leftstring, rightstring;
                    int           roffset = 0;
                    rightstring = "((CUP.runtime.Symbol)" + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + roffset + ")).right";
                    if (prod.rhs_length() == 0)
                    {
                        leftstring = rightstring;
                    }
                    else
                    {
                        loffset    = prod.rhs_length() - 1;
                        leftstring = "((CUP.runtime.Symbol)" + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + loffset + ")).left";
                    }
                    out_Renamed.WriteLine("              " + pre("result") + " = new CUP.runtime.Symbol(" + prod.lhs().the_symbol().index() + "/*" + prod.lhs().the_symbol().name_Renamed_Method() + "*/" + ", " + leftstring + ", " + rightstring + ", RESULT);");
                }
                else
                {
                    out_Renamed.WriteLine("              " + pre("result") + " = new CUP.runtime.Symbol(" + prod.lhs().the_symbol().index() + "/*" + prod.lhs().the_symbol().name_Renamed_Method() + "*/" + ", RESULT);");
                }

                /* end of their block */
                out_Renamed.WriteLine("            }");

                /* if this was the start production, do action for accept */
                if (prod == start_prod)
                {
                    out_Renamed.WriteLine("          /* ACCEPT */");
                    out_Renamed.WriteLine("          " + pre("parser") + ".done_parsing();");
                }

                /* code to return lhs symbol */
                out_Renamed.WriteLine("          return " + pre("result") + ";");
                out_Renamed.WriteLine();
            }

            /* end of switch */
            out_Renamed.WriteLine("          /* . . . . . .*/");
            out_Renamed.WriteLine("          default:");
            out_Renamed.WriteLine("            throw new Exception(");
            out_Renamed.WriteLine("               \"Invalid action number found in " + "internal parse table\");");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("        }");

            /* end of method */
            out_Renamed.WriteLine("    }");

            /* end of class */
            out_Renamed.WriteLine("}");
            out_Renamed.WriteLine();

            action_code_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #15
0
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Constructor for dot at start of right hand side. 
 /// </summary>
 /// <param name="prod">production this item uses.
 /// 
 /// </param>
 public lr_item_core(production prod)
     : this(prod, 0)
 {
 }
Example #16
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Emit code for the non-public class holding the actual action code. 
        /// </summary>
        /// <param name="out">       stream to produce output on.
        /// </param>
        /// <param name="start_prod">the start production of the grammar.
        /// 
        /// </param>
        protected internal static void emit_action_code(System.IO.StreamWriter out_Renamed, production start_prod)
        {
            production prod;

            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* class header */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("/** Cup generated class to encapsulate user supplied action code.*/");
            out_Renamed.WriteLine("public class " + pre("actions") + " {");

            /* user supplied code */
            if (action_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine(action_code);
            }

            /* field for parser object */
            out_Renamed.WriteLine("  private " + parser_class_name + " parser;");

            /* constructor */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Constructor */");
            out_Renamed.WriteLine("  public " + pre("actions") + "(" + parser_class_name + " parser) {");
            out_Renamed.WriteLine("    this.parser = parser;");
            out_Renamed.WriteLine("  }");

            /* action method head */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Method with the actual generated action code. */");
            out_Renamed.WriteLine("  public CUP.runtime.Symbol " + pre("do_action") + "(");
            out_Renamed.WriteLine("    int                        " + pre("act_num,"));
            out_Renamed.WriteLine("    CUP.runtime.lr_parser " + pre("parser,"));
            out_Renamed.WriteLine("    CUP.runtime.SymbolStack            " + pre("stack,"));
            out_Renamed.WriteLine("    int                        " + pre("top)"));
            out_Renamed.WriteLine("    {");

            /* declaration of result symbol */
            /* New declaration!! now return Symbol
            6/13/96 frankf */
            out_Renamed.WriteLine("      /* Symbol object for return from actions */");
            out_Renamed.WriteLine("      CUP.runtime.Symbol " + pre("result") + ";");
            out_Renamed.WriteLine();

            /* switch top */
            out_Renamed.WriteLine("      /* select the action based on the action number */");
            out_Renamed.WriteLine("      switch (" + pre("act_num") + ")");
            out_Renamed.WriteLine("        {");

            /* emit action code for each production as a separate case */
             for (System.Collections.IEnumerator p = production.all(); p.MoveNext(); )
            {
                prod = (production) p.Current;

                /* case label */
                out_Renamed.WriteLine("          /*. . . . . . . . . . . . . . . . . . . .*/");
                out_Renamed.WriteLine("          case " + prod.index() + ": // " + prod.to_simple_string());

                /* give them their own block to work in */
                out_Renamed.WriteLine("            {");

                /* create the result symbol */
                /*make the variable RESULT which will point to the new Symbol (see below)
                and be changed by action code
                6/13/96 frankf */
                 string strSymType = prod.lhs().the_symbol().stack_type().Trim();
                 string strPrimitives="int;float;double;short;char;byte;decimal;sbyte;bool;ushort;uint;long;ulong";
                 if(strPrimitives.IndexOf(strSymType) > -1)
                 {
                     string init = "";
                     switch (strSymType)
                     {
                         case "double":
                             init = " = 0.0";
                             break;
                         case "int":
                         case "uint":
                         case "short":
                         case "ushort":
                         case "byte":
                         case "sbyte":
                             init = " = 0";
                             break;
                         case "float":
                             init = " = 0.0f";
                             break;
                         case "decimal":
                             init = " = decimal.Zero";
                             break;
                         case "char":
                             init = " = '\\0'";
                             break;
                         case "long":
                         case "ulong":
                             init = " = 0L";
                             break;

                     }
                     if (strSymType == "double")
                     {
                         init = " = 0.0";
                     }

                     out_Renamed.WriteLine("              " + strSymType + " RESULT "  + init + ";");
                 }
                 else
                 {
                     out_Renamed.WriteLine("              " + strSymType + " RESULT = null;");
                 }

                /* Add code to propagate RESULT assignments that occur in
                * action code embedded in a production (ie, non-rightmost
                * action code). 24-Mar-1998 CSA
                */
                 for (int i = 0; i < prod.rhs_length(); i++)
                {
                    // only interested in non-terminal symbols.
                    if (!(prod.rhs(i) is symbol_part))
                        continue;
                    symbol s = ((symbol_part) prod.rhs(i)).the_symbol();
                    if (!(s is non_terminal))
                        continue;
                    // skip this non-terminal unless it corresponds to
                    // an embedded action production.
                    if (((non_terminal) s).is_embedded_action == false)
                        continue;
                    // OK, it fits.  Make a conditional assignment to RESULT.
                    int index = prod.rhs_length() - i - 1; // last rhs is on top.
                    out_Renamed.WriteLine("              " + "// propagate RESULT from " + s.name_Renamed_Method());
                    out_Renamed.WriteLine("              " + "if ( " + "((CUP.runtime.Symbol) " + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + index + ")).Value != null )");
                    out_Renamed.WriteLine("                " + "RESULT = " + "(" + prod.lhs().the_symbol().stack_type() + ") " + "((CUP.runtime.Symbol) " + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + index + ")).Value;");
                }

                /* if there is an action string, emit it */
                if (prod.action() != null && prod.action().code_string() != null && !prod.action().Equals(""))
                    out_Renamed.WriteLine(prod.action().code_string());

                /* here we have the left and right values being propagated.
                must make this a command line option.
                frankf 6/18/96 */

                /* Create the code that assigns the left and right values of
                the new Symbol that the production is reducing to */
                if (emit.lr_values())
                {
                    int loffset;
                    System.String leftstring, rightstring;
                    int roffset = 0;
                    rightstring = "((CUP.runtime.Symbol)" + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + roffset + ")).right";
                    if (prod.rhs_length() == 0)
                        leftstring = rightstring;
                    else
                    {
                        loffset = prod.rhs_length() - 1;
                        leftstring = "((CUP.runtime.Symbol)" + emit.pre("stack") + ".Peek(" + emit.pre("top") + "-" + loffset + ")).left";
                    }
                    out_Renamed.WriteLine("              " + pre("result") + " = new CUP.runtime.Symbol(" + prod.lhs().the_symbol().index() + "/*" + prod.lhs().the_symbol().name_Renamed_Method() + "*/" + ", " + leftstring + ", " + rightstring + ", RESULT);");
                }
                else
                {
                    out_Renamed.WriteLine("              " + pre("result") + " = new CUP.runtime.Symbol(" + prod.lhs().the_symbol().index() + "/*" + prod.lhs().the_symbol().name_Renamed_Method() + "*/" + ", RESULT);");
                }

                /* end of their block */
                out_Renamed.WriteLine("            }");

                /* if this was the start production, do action for accept */
                if (prod == start_prod)
                {
                    out_Renamed.WriteLine("          /* ACCEPT */");
                    out_Renamed.WriteLine("          " + pre("parser") + ".done_parsing();");
                }

                /* code to return lhs symbol */
                out_Renamed.WriteLine("          return " + pre("result") + ";");
                out_Renamed.WriteLine();
            }

            /* end of switch */
            out_Renamed.WriteLine("          /* . . . . . .*/");
            out_Renamed.WriteLine("          default:");
            out_Renamed.WriteLine("            throw new Exception(");
            out_Renamed.WriteLine("               \"Invalid action number found in " + "internal parse table\");");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("        }");

            /* end of method */
            out_Renamed.WriteLine("    }");

            /* end of class */
            out_Renamed.WriteLine("}");
            out_Renamed.WriteLine();

            action_code_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #17
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Constructor with default position and empty lookahead set.
        /// </summary>
        /// <param name="prod">the production for the item.
        ///
        /// </param>
        public lalr_item(production prod) : this(prod, 0, new terminal_set())
        {
        }
Example #18
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Constructor with default position (dot at start).
        /// </summary>
        /// <param name="prod">the production for the item.
        /// </param>
        /// <param name="look">the set of lookahead symbols.
        ///
        /// </param>
        public lalr_item(production prod, terminal_set look) : this(prod, 0, look)
        {
        }
Example #19
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /// <summary>Full constructor.
        /// </summary>
        /// <param name="prod">the production for the item.
        /// </param>
        /// <param name="pos"> the position of the "dot" within the production.
        /// </param>
        /// <param name="look">the set of lookahead symbols.
        ///
        /// </param>
        public lalr_item(production prod, int pos, terminal_set look) : base(prod, pos)
        {
            _lookahead        = look;
            _propagate_items  = new CUP.runtime.SymbolStack();
            needs_propagation = true;
        }
Example #20
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Build an LALR viable prefix recognition machine given a start
        /// production.  This method operates by first building a start state
        /// from the start production (based on a single item with the dot at
        /// the beginning and EOF as expected lookahead).  Then for each state
        /// it attempts to extend the machine by creating transitions out of
        /// the state to new or existing states.  When considering extension
        /// from a state we make a transition on each symbol that appears before
        /// the dot in some item.  For example, if we have the items: <pre>
        /// [A ::= a b * X c, {d,e}]
        /// [B ::= a b * X d, {a,b}]
        /// </pre>
        /// in some state, then we would be making a transition under X to a new
        /// state.  This new state would be formed by a "kernel" of items
        /// corresponding to moving the dot past the X.  In this case: <pre>
        /// [A ::= a b X * c, {d,e}]
        /// [B ::= a b X * Y, {a,b}]
        /// </pre>
        /// The full state would then be formed by "closing" this kernel set of
        /// items so that it included items that represented productions of things
        /// the parser was now looking for.  In this case we would items
        /// corresponding to productions of Y, since various forms of Y are expected
        /// next when in this state (see lalr_item_set.compute_closure() for details
        /// on closure). <p>
        /// *
        /// The process of building the viable prefix recognizer terminates when no
        /// new states can be added.  However, in order to build a smaller number of
        /// states (i.e., corresponding to LALR rather than canonical LR) the state
        /// building process does not maintain full loookaheads in all items.
        /// Consequently, after the machine is built, we go back and propagate
        /// lookaheads through the constructed machine using a call to
        /// propagate_all_lookaheads().  This makes use of propagation links
        /// constructed during the closure and transition process.
        /// *
        /// </summary>
        /// <param name="start_prod">the start production of the grammar
        /// </param>
        /// <seealso cref="   CUP.lalr_item_set#compute_closure
        /// "/>
        /// <seealso cref="   CUP.lalr_state#propagate_all_lookaheads
        ///
        /// "/>

        public static lalr_state build_machine(production start_prod)
        {
            lalr_state    start_state;
            lalr_item_set start_items;
            lalr_item_set new_items;
            lalr_item_set linked_items;
            lalr_item_set kernel;

            CUP.runtime.SymbolStack work_stack = new CUP.runtime.SymbolStack();
            lalr_state st, new_st;
            symbol_set outgoing;
            lalr_item  itm, new_itm, existing, fix_itm;
            symbol     sym, sym2;

            System.Collections.IEnumerator i, s, fix;

            /* sanity check */
            if (start_prod == null)
            {
                throw new internal_error("Attempt to build viable prefix recognizer using a null production");
            }

            /* build item with dot at front of start production and EOF lookahead */
            start_items = new lalr_item_set();

            itm = new lalr_item(start_prod);
            itm.lookahead().add(terminal.EOF);

            start_items.add(itm);

            /* create copy the item set to form the kernel */
            kernel = new lalr_item_set(start_items);

            /* create the closure from that item set */
            start_items.compute_closure();

            /* build a state out of that item set and put it in our work set */
            start_state = new lalr_state(start_items);
            System.Object temp_object;
            temp_object = start_state;
            System.Object generatedAux = temp_object;
            work_stack.Push(temp_object);

            /* enter the state using the kernel as the key */
            SupportClass.PutElement(_all_kernels, kernel, start_state);

            /* continue looking at new states until we have no more work to do */
            while (!(work_stack.Count == 0))
            {
                /* remove a state from the work set */
                st = (lalr_state)work_stack.Pop();

                /* gather up all the symbols that appear before dots */
                outgoing = new symbol_set();
                //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                for (i = st.items().all(); i.MoveNext();)
                {
                    //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                    itm = (lalr_item)i.Current;

                    /* add the symbol before the dot (if any) to our collection */
                    sym = itm.symbol_after_dot();
                    if (sym != null)
                    {
                        outgoing.add(sym);
                    }
                }

                /* now create a transition out for each individual symbol */
                //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                for (s = outgoing.all(); s.MoveNext();)
                {
                    //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                    sym = (symbol)s.Current;

                    /* will be keeping the set of items with propagate links */
                    linked_items = new lalr_item_set();

                    /* gather up shifted versions of all the items that have this
                     * symbol before the dot */
                    new_items = new lalr_item_set();
                    //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                    for (i = st.items().all(); i.MoveNext();)
                    {
                        //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                        itm = (lalr_item)i.Current;

                        /* if this is the symbol we are working on now, add to set */
                        sym2 = itm.symbol_after_dot();
                        if (sym.Equals(sym2))
                        {
                            /* add to the kernel of the new state */
                            new_items.add(itm.shift());

                            /* remember that itm has propagate link to it */
                            linked_items.add(itm);
                        }
                    }

                    /* use new items as state kernel */
                    kernel = new lalr_item_set(new_items);

                    /* have we seen this one already? */
                    new_st = (lalr_state)_all_kernels[kernel];

                    /* if we haven't, build a new state out of the item set */
                    if (new_st == null)
                    {
                        /* compute closure of the kernel for the full item set */
                        new_items.compute_closure();

                        /* build the new state */
                        new_st = new lalr_state(new_items);

                        /* add the new state to our work set */
                        System.Object temp_object2;
                        temp_object2 = new_st;
                        System.Object generatedAux2 = temp_object2;
                        work_stack.Push(temp_object2);

                        /* put it in our kernel table */
                        SupportClass.PutElement(_all_kernels, kernel, new_st);
                    }
                    else
                    {
                        /* walk through the items that have links to the new state */
                        //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                        for (fix = linked_items.all(); fix.MoveNext();)
                        {
                            //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                            fix_itm = (lalr_item)fix.Current;

                            /* look at each propagate link out of that item */
                            for (int l = 0; l < fix_itm.propagate_items().Count; l++)
                            {
                                /* pull out item linked to in the new state */
                                new_itm = (lalr_item)(fix_itm.propagate_items().Peek(fix_itm.propagate_items().Count - (l + 1)));

                                /* find corresponding item in the existing state */
                                existing = new_st.items().find(new_itm);

                                /* fix up the item so it points to the existing set */
                                if (existing != null)
                                {
                                    fix_itm.propagate_items()[l] = existing;
                                }
                            }
                        }
                    }

                    /* add a transition from current state to that state */
                    st.add_transition(sym, new_st);
                }
            }

            /* all done building states */

            /* propagate complete lookahead sets throughout the states */
            propagate_all_lookaheads();

            return(start_state);
        }
Example #21
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Emit the parser subclass with embedded tables.
        /// </summary>
        /// <param name="out">            stream to produce output on.
        /// </param>
        /// <param name="action_table">   internal representation of the action table.
        /// </param>
        /// <param name="reduce_table">   internal representation of the reduce-goto table.
        /// </param>
        /// <param name="start_st">       start state of the parse machine.
        /// </param>
        /// <param name="start_prod">     start production of the grammar.
        /// </param>
        /// <param name="compact_reduces">do we use most frequent reduce as default?
        /// </param>
        /// <param name="suppress_scanner">should scanner be suppressed for compatibility?
        ///
        /// </param>
        public static void  parser(System.IO.StreamWriter out_Renamed, parse_action_table action_table, parse_reduce_table reduce_table, int start_st, production start_prod, bool compact_reduces, bool suppress_scanner)
        {
            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* top of file */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("//----------------------------------------------------");
            out_Renamed.WriteLine("// The following code was generated by " + version.title_str);
            out_Renamed.WriteLine("// " + System.DateTime.Now);
            out_Renamed.WriteLine("//----------------------------------------------------");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("using System;");
            emit_package(out_Renamed);

            /* user supplied imports */
            for (int i = 0; i < import_list.Count; i++)
            {
                out_Renamed.WriteLine("using " + import_list.Peek(import_list.Count - (i + 1)) + ";");
            }

            /* class header */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("///<summary>" + version.title_str + " generated parser." + "</summary>");
            out_Renamed.WriteLine("///<version>" + System.DateTime.Now + "</version>");
            out_Renamed.WriteLine("///");
            out_Renamed.WriteLine("public class " + parser_class_name + " : CUP.runtime.lr_parser {");

            /* constructors [CSA/davidm, 24-jul-99] */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Default constructor. */");
            out_Renamed.WriteLine("  public " + parser_class_name + "() : base() {}");
            if (!suppress_scanner)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** Constructor which sets the default scanner. */");
                out_Renamed.WriteLine("  public " + parser_class_name + "(CUP.runtime.Scanner s) : base(s) {}");
            }

            /* emit the various tables */
            emit_production_table(out_Renamed);
            do_action_table(out_Renamed, action_table, compact_reduces);
            do_reduce_table(out_Renamed, reduce_table);

            /* instance of the action encapsulation class */
            out_Renamed.WriteLine("  /** Instance of action encapsulation class. */");
            out_Renamed.WriteLine("  protected " + pre("actions") + " action_obj;");
            out_Renamed.WriteLine();

            /* action object initializer */
            out_Renamed.WriteLine("  /** Action encapsulation object initializer. */");
            out_Renamed.WriteLine("  protected override void init_actions()");
            out_Renamed.WriteLine("    {");
            out_Renamed.WriteLine("      action_obj = new " + pre("actions") + "(this);");
            out_Renamed.WriteLine("    }");
            out_Renamed.WriteLine();

            /* access to action code */
            out_Renamed.WriteLine("  /** Invoke a user supplied parse action. */");
            out_Renamed.WriteLine("  public override CUP.runtime.Symbol do_action(");
            out_Renamed.WriteLine("    int                        act_num,");
            out_Renamed.WriteLine("    CUP.runtime.lr_parser parser,");
            out_Renamed.WriteLine("    CUP.runtime.SymbolStack   stack,");
            out_Renamed.WriteLine("    int                        top)");
            out_Renamed.WriteLine("  {");
            out_Renamed.WriteLine("    /* call code in generated class */");
            out_Renamed.WriteLine("    return action_obj." + pre("do_action(") + "act_num, parser, stack, top);");
            out_Renamed.WriteLine("  }");
            out_Renamed.WriteLine("");


            /* method to tell the parser about the start state */
            out_Renamed.WriteLine("  /** Indicates start state. */");
            out_Renamed.WriteLine("  public override int start_state() {return " + start_st + ";}");

            /* method to indicate start production */
            out_Renamed.WriteLine("  /** Indicates start production. */");
            out_Renamed.WriteLine("  public override int start_production() {return " + start_production.index() + ";}");
            out_Renamed.WriteLine();

            /* methods to indicate EOF and error symbol indexes */
            out_Renamed.WriteLine("  /** <code>EOF</code> Symbol index. */");
            out_Renamed.WriteLine("  public override int EOF_sym() {return " + terminal.EOF.index() + ";}");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** <code>error</code> Symbol index. */");
            out_Renamed.WriteLine("  public override int error_sym() {return " + terminal.error.index() + ";}");
            out_Renamed.WriteLine();

            /* user supplied code for user_init() */
            if (init_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** User initialization code. */");
                out_Renamed.WriteLine("  public override void user_init()");
                out_Renamed.WriteLine("    {");
                out_Renamed.WriteLine(init_code);
                out_Renamed.WriteLine("    }");
            }

            /* user supplied code for scan */
            if (scan_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** Scan to get the next Symbol. */");
                out_Renamed.WriteLine("  public override CUP.runtime.Symbol scan()");
                out_Renamed.WriteLine("    {");
                out_Renamed.WriteLine(scan_code);
                out_Renamed.WriteLine("    }");
            }

            /* user supplied code */
            if (parser_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine(parser_code);
            }

            /* end of class */
            out_Renamed.WriteLine("}");

            /* put out the action code class */
            emit_action_code(out_Renamed, start_prod);

            // End of namespace
            out_Renamed.WriteLine("}");

            parser_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #22
0
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Equality comparison. 
 /// </summary>
 public virtual bool equals(production other)
 {
     if (other == null)
         return false;
     return other._index == _index;
 }
Example #23
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Build an LALR viable prefix recognition machine given a start 
        /// production.  This method operates by first building a start state
        /// from the start production (based on a single item with the dot at
        /// the beginning and EOF as expected lookahead).  Then for each state
        /// it attempts to extend the machine by creating transitions out of
        /// the state to new or existing states.  When considering extension
        /// from a state we make a transition on each symbol that appears before
        /// the dot in some item.  For example, if we have the items: <pre>
        /// [A ::= a b * X c, {d,e}]
        /// [B ::= a b * X d, {a,b}]
        /// </pre>
        /// in some state, then we would be making a transition under X to a new
        /// state.  This new state would be formed by a "kernel" of items 
        /// corresponding to moving the dot past the X.  In this case: <pre>
        /// [A ::= a b X * c, {d,e}]
        /// [B ::= a b X * Y, {a,b}]
        /// </pre>
        /// The full state would then be formed by "closing" this kernel set of 
        /// items so that it included items that represented productions of things
        /// the parser was now looking for.  In this case we would items 
        /// corresponding to productions of Y, since various forms of Y are expected
        /// next when in this state (see lalr_item_set.compute_closure() for details 
        /// on closure). <p>
        /// *
        /// The process of building the viable prefix recognizer terminates when no
        /// new states can be added.  However, in order to build a smaller number of
        /// states (i.e., corresponding to LALR rather than canonical LR) the state 
        /// building process does not maintain full loookaheads in all items.  
        /// Consequently, after the machine is built, we go back and propagate 
        /// lookaheads through the constructed machine using a call to 
        /// propagate_all_lookaheads().  This makes use of propagation links 
        /// constructed during the closure and transition process.
        /// *
        /// </summary>
        /// <param name="start_prod">the start production of the grammar
        /// </param>
        /// <seealso cref="   CUP.lalr_item_set#compute_closure
        /// "/>
        /// <seealso cref="   CUP.lalr_state#propagate_all_lookaheads
        /// 
        /// "/>
        public static lalr_state build_machine(production start_prod)
        {
            lalr_state start_state;
            lalr_item_set start_items;
            lalr_item_set new_items;
            lalr_item_set linked_items;
            lalr_item_set kernel;
            CUP.runtime.SymbolStack work_stack = new CUP.runtime.SymbolStack();
            lalr_state st, new_st;
            symbol_set outgoing;
            lalr_item itm, new_itm, existing, fix_itm;
            symbol sym, sym2;
            System.Collections.IEnumerator i, s, fix;

            /* sanity check */
            if (start_prod == null)
                throw new internal_error("Attempt to build viable prefix recognizer using a null production");

            /* build item with dot at front of start production and EOF lookahead */
            start_items = new lalr_item_set();

            itm = new lalr_item(start_prod);
            itm.lookahead().add(terminal.EOF);

            start_items.add(itm);

            /* create copy the item set to form the kernel */
            kernel = new lalr_item_set(start_items);

            /* create the closure from that item set */
            start_items.compute_closure();

            /* build a state out of that item set and put it in our work set */
            start_state = new lalr_state(start_items);
            System.Object temp_object;
            temp_object = start_state;
            System.Object generatedAux = temp_object;
            work_stack.Push(temp_object);

            /* enter the state using the kernel as the key */
            SupportClass.PutElement(_all_kernels, kernel, start_state);

            /* continue looking at new states until we have no more work to do */
            while (!(work_stack.Count == 0))
            {
                /* remove a state from the work set */
                st = (lalr_state) work_stack.Pop();

                /* gather up all the symbols that appear before dots */
                outgoing = new symbol_set();
                //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                 for (i = st.items().all(); i.MoveNext(); )
                {
                    //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                    itm = (lalr_item) i.Current;

                    /* add the symbol before the dot (if any) to our collection */
                    sym = itm.symbol_after_dot();
                    if (sym != null)
                        outgoing.add(sym);
                }

                /* now create a transition out for each individual symbol */
                //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                 for (s = outgoing.all(); s.MoveNext(); )
                {
                    //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                    sym = (symbol) s.Current;

                    /* will be keeping the set of items with propagate links */
                    linked_items = new lalr_item_set();

                    /* gather up shifted versions of all the items that have this
                    symbol before the dot */
                    new_items = new lalr_item_set();
                    //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                     for (i = st.items().all(); i.MoveNext(); )
                    {
                        //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                        itm = (lalr_item) i.Current;

                        /* if this is the symbol we are working on now, add to set */
                        sym2 = itm.symbol_after_dot();
                        if (sym.Equals(sym2))
                        {
                            /* add to the kernel of the new state */
                            new_items.add(itm.shift());

                            /* remember that itm has propagate link to it */
                            linked_items.add(itm);
                        }
                    }

                    /* use new items as state kernel */
                    kernel = new lalr_item_set(new_items);

                    /* have we seen this one already? */
                    new_st = (lalr_state) _all_kernels[kernel];

                    /* if we haven't, build a new state out of the item set */
                    if (new_st == null)
                    {
                        /* compute closure of the kernel for the full item set */
                        new_items.compute_closure();

                        /* build the new state */
                        new_st = new lalr_state(new_items);

                        /* add the new state to our work set */
                        System.Object temp_object2;
                        temp_object2 = new_st;
                        System.Object generatedAux2 = temp_object2;
                        work_stack.Push(temp_object2);

                        /* put it in our kernel table */
                        SupportClass.PutElement(_all_kernels, kernel, new_st);
                    }
                    else
                    {
                        /* walk through the items that have links to the new state */
                        //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
                         for (fix = linked_items.all(); fix.MoveNext(); )
                        {
                            //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                            fix_itm = (lalr_item) fix.Current;

                            /* look at each propagate link out of that item */
                             for (int l = 0; l < fix_itm.propagate_items().Count; l++)
                            {
                                /* pull out item linked to in the new state */
                                new_itm = (lalr_item) (fix_itm.propagate_items().Peek(fix_itm.propagate_items().Count - (l + 1)));

                                /* find corresponding item in the existing state */
                                existing = new_st.items().find(new_itm);

                                /* fix up the item so it points to the existing set */
                                if (existing != null)
                                    fix_itm.propagate_items()[l] = existing;
                            }
                        }
                    }

                    /* add a transition from current state to that state */
                    st.add_transition(sym, new_st);
                }
            }

            /* all done building states */

            /* propagate complete lookahead sets throughout the states */
            propagate_all_lookaheads();

            return start_state;
        }
Example #24
0
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Constructor with default position (dot at start). 
 /// </summary>
 /// <param name="prod">the production for the item.
 /// </param>
 /// <param name="look">the set of lookahead symbols.
 /// 
 /// </param>
 public lalr_item(production prod, terminal_set look)
     : this(prod, 0, look)
 {
 }
Example #25
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Procedure that attempts to fix a shift/reduce error by using
        /// precedences.  --frankf 6/26/96
        /// 
        /// if a production (also called rule) or the lookahead terminal
        /// has a precedence, then the table can be fixed.  if the rule
        /// has greater precedence than the terminal, a reduce by that rule
        /// in inserted in the table.  If the terminal has a higher precedence, 
        /// it is shifted.  if they have equal precedence, then the associativity
        /// of the precedence is used to determine what to put in the table:
        /// if the precedence is left associative, the action is to reduce. 
        /// if the precedence is right associative, the action is to shift.
        /// if the precedence is non associative, then it is a syntax error.
        /// *
        /// </summary>
        /// <param name="p">          the production
        /// </param>
        /// <param name="term_index"> the index of the lokahead terminal
        /// </param>
        /// <param name="parse_action_row"> a row of the action table
        /// </param>
        /// <param name="act">        the rule in conflict with the table entry
        /// 
        /// </param>
        protected internal virtual bool fix_with_precedence(production p, int term_index, parse_action_row table_row, parse_action act)
        {
            terminal term = terminal.find(term_index);

            /* if the production has a precedence number, it can be fixed */
            if (p.precedence_num() > assoc.no_prec)
            {

                /* if production precedes terminal, put reduce in table */
                if (p.precedence_num() > term.precedence_num())
                {
                    table_row.under_term[term_index] = insert_reduce(table_row.under_term[term_index], act);
                    return true;
                }
                else if (p.precedence_num() < term.precedence_num())
                {
                    table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                    return true;
                }
                else
                {
                    /* they are == precedence */

                    /* equal precedences have equal sides, so only need to
                    look at one: if it is right, put shift in table */
                    if (term.precedence_side() == assoc.right)
                    {
                        table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                        return true;
                    }
                    else if (term.precedence_side() == assoc.left)
                    {
                        table_row.under_term[term_index] = insert_reduce(table_row.under_term[term_index], act);
                        return true;
                    }
                    else if (term.precedence_side() == assoc.nonassoc)
                    {
                        table_row.under_term[term_index] = new nonassoc_action();
                        return true;
                    }
                    else
                    {
                        /* something really went wrong */
                        throw new internal_error("Unable to resolve conflict correctly");
                    }
                }
            }
            else if (term.precedence_num() > assoc.no_prec)
            {
                table_row.under_term[term_index] = insert_shift(table_row.under_term[term_index], act);
                return true;
            }

            /* otherwise, neither the rule nor the terminal has a precedence,
            so it can't be fixed. */
            return false;
        }
Example #26
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Constructor for dot at start of right hand side.
        /// </summary>
        /// <param name="prod">production this item uses.
        ///
        /// </param>
        public lr_item_core(production prod) : this(prod, 0)
        {
        }
Example #27
0
 /// <summary>Constructor.
 /// </summary>
 /// <param name="base">      the production we are being factored out of.
 /// </param>
 /// <param name="lhs_sym">   the LHS symbol for this production.
 /// </param>
 /// <param name="rhs_parts"> array of production parts for the RHS.
 /// </param>
 /// <param name="rhs_len">   how much of the rhs_parts array is valid.
 /// </param>
 /// <param name="action_str">the trailing reduce action for this production.
 ///
 /// </param>
 public action_production(production base_Renamed, non_terminal lhs_sym, production_part[] rhs_parts, int rhs_len, string action_str) : base(lhs_sym, rhs_parts, rhs_len, action_str)
 {
     _base_production = base_Renamed;
 }
Example #28
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Emit the production table. 
        /// </summary>
        /// <param name="out">stream to produce output on.
        /// 
        /// </param>
        protected internal static void emit_production_table(System.IO.StreamWriter out_Renamed)
        {
            production[] all_prods;
            production prod;

            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* collect up the productions in order */
            all_prods = new production[production.number()];
             for (System.Collections.IEnumerator p = production.all(); p.MoveNext(); )
            {
                prod = (production) p.Current;
                all_prods[prod.index()] = prod;
            }

            // make short[,]
            short[][] prod_table = new short[production.number()][];
             for (int i = 0; i < production.number(); i++)
            {
                prod_table[i] = new short[2];
            }
             for (int i = 0; i < production.number(); i++)
            {
                prod = all_prods[i];
                // { lhs symbol , rhs size }
                prod_table[i][0] = (short) prod.lhs().the_symbol().index();
                prod_table[i][1] = (short) prod.rhs_length();
            }
            /* do the top of the table */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Production table. */");
            out_Renamed.Write("  private static string[] _strProductionTable = ");
            do_table_as_string(out_Renamed, prod_table);
            out_Renamed.WriteLine(";");
            out_Renamed.WriteLine("  protected static readonly short[][] _production_table  = CUP.runtime.lr_parser.unpackFromStrings(_strProductionTable);");
            // out_Renamed.Write("    unpackFromStrings(");
            // do_table_as_string(out_Renamed, prod_table);
            // out_Renamed.WriteLine(");");

            /* do the public accessor method */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Access to production table. */");
            out_Renamed.WriteLine("  public override short[][] production_table() " + "{return _production_table;}");

            production_table_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #29
0
        /// <summary>Method with the actual generated action code. 
        /// </summary>
        public Symbol CUP_parser_do_action(int CUP_parser_act_num, lr_parser CUP_parser_parser, CUP.runtime.SymbolStack CUP_parser_stack, int CUP_parser_top)
        {
            /* Symbol object for return from actions */
            Symbol CUP_parser_result;

            /* select the action based on the action number */
            switch (CUP_parser_act_num)
            {
                case 106:
                    // empty ::=
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(29, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 105:
                    // opt_semi ::= SEMI
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(7, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 104:
                    // opt_semi ::=
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(7, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 103:
                    // non_terminal ::= NONTERMINAL
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(8, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 102:
                    // non_terminal ::= NON TERMINAL
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(8, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 101:
                    // robust_id ::= error
                    {
                        System.String RESULT = null;

                        lexer.emit_error("Illegal use of reserved word");
                        RESULT = "ILLEGAL";

                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 100:
                    // robust_id ::= NONASSOC
                    {
                        System.String RESULT = null;
                        RESULT = "nonassoc";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 99:
                    // robust_id ::= RIGHT
                    {
                        System.String RESULT = null;
                        RESULT = "right";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 98:
                    // robust_id ::= LEFT
                    {
                        System.String RESULT = null;
                        RESULT = "left";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 97:
                    // robust_id ::= PRECEDENCE
                    {
                        System.String RESULT = null;
                        RESULT = "precedence";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 96:
                    // robust_id ::= START
                    {
                        System.String RESULT = null;
                        RESULT = "start";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 95:
                    // robust_id ::= WITH
                    {
                        System.String RESULT = null;
                        RESULT = "with";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 94:
                    // robust_id ::= SCAN
                    {
                        System.String RESULT = null;
                        RESULT = "scan";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 93:
                    // robust_id ::= INIT
                    {
                        System.String RESULT = null;
                        RESULT = "init";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 92:
                    // robust_id ::= NONTERMINAL
                    {
                        System.String RESULT = null;
                        RESULT = "nonterminal";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 91:
                    // robust_id ::= NON
                    {
                        System.String RESULT = null;
                        RESULT = "non";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 90:
                    // robust_id ::= TERMINAL
                    {
                        System.String RESULT = null;
                        RESULT = "terminal";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 89:
                    // robust_id ::= PARSER
                    {
                        System.String RESULT = null;
                        RESULT = "parser";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 88:
                    // robust_id ::= ACTION
                    {
                        System.String RESULT = null;
                        RESULT = "action";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 87:
                    // robust_id ::= CODE
                    {
                        System.String RESULT = null;
                        RESULT = "code";
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 86:
                    // robust_id ::= ID
                    {
                        System.String RESULT = null;
                        int the_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int the_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String the_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        RESULT = the_id;
                        CUP_parser_result = new Symbol(42, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 85:
                    // label_id ::= robust_id
                    {
                        System.String RESULT = null;
                        int the_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int the_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String the_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        RESULT = the_id;
                        CUP_parser_result = new Symbol(38, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 84:
                    // symbol_id ::= error
                    {
                        System.String RESULT = null;

                        lexer.emit_error("Illegal use of reserved word");
                        RESULT = "ILLEGAL";

                        CUP_parser_result = new Symbol(37, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 83:
                    // symbol_id ::= ID
                    {
                        System.String RESULT = null;
                        int the_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int the_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String the_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        RESULT = the_id;
                        CUP_parser_result = new Symbol(37, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 82:
                    // nt_id ::= error
                    {
                        System.String RESULT = null;

                        lexer.emit_error("Illegal use of reserved word");
                        RESULT = "ILLEGAL";

                        CUP_parser_result = new Symbol(36, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 81:
                    // nt_id ::= ID
                    {
                        System.String RESULT = null;
                        int the_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int the_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String the_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        RESULT = the_id;
                        CUP_parser_result = new Symbol(36, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 80:
                    // new_non_term_id ::= ID
                    {
                        System.Object RESULT = null;
                        int non_term_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int non_term_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String non_term_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* see if this non terminal has been declared before */
                        if (symbols[non_term_id] != null)
                        {
                            /* issue a message */
                            lexer.emit_error("CUP.runtime.Symbol \"" + non_term_id + "\" has already been declared");
                        }
                        else
                        {
                            if (multipart_name.Equals(""))
                            {
                                append_multipart("Object");
                            }
                            /* build the non terminal object */
                            non_terminal this_nt = new non_terminal(non_term_id, multipart_name);

                            /* put it in the non_terms table */
                            SupportClass.PutElement(non_terms, non_term_id, this_nt);

                            /* build a production_part and put it in the symbols table */
                            SupportClass.PutElement(symbols, non_term_id, new symbol_part(this_nt));
                        }

                        CUP_parser_result = new Symbol(26, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 79:
                    // new_term_id ::= ID
                    {
                        System.Object RESULT = null;
                        int term_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int term_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String term_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* see if this terminal has been declared before */
                        if (symbols[term_id] != null)
                        {
                            /* issue a message */
                            lexer.emit_error("CUP.runtime.Symbol \"" + term_id + "\" has already been declared");
                        }
                        else
                        {
                            /* if no type declared, declare one */
                            if (multipart_name.Equals(""))
                            {
                                append_multipart("Object");
                            }
                            /* build a production_part and put it in the table */
                            SupportClass.PutElement(symbols, term_id, new symbol_part(new terminal(term_id, multipart_name)));
                        }

                        CUP_parser_result = new Symbol(25, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 78:
                    // type_id ::= type_id LBRACK RBRACK
                    {
                        System.Object RESULT = null;
                        multipart_name = string.Concat(multipart_name, "[]");
                        CUP_parser_result = new Symbol(19, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 77:
                    // type_id ::= multipart_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(19, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 76:
                    // import_id ::= multipart_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(15, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 75:
                    // import_id ::= multipart_id DOT STAR
                    {
                        System.Object RESULT = null;
                        append_multipart("*");
                        CUP_parser_result = new Symbol(15, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 74:
                    // multipart_id ::= robust_id
                    {
                        System.Object RESULT = null;
                        int an_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int an_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String an_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        append_multipart(an_id);
                        CUP_parser_result = new Symbol(13, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 73:
                    // multipart_id ::= multipart_id DOT robust_id
                    {
                        System.Object RESULT = null;
                        int another_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int another_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String another_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        append_multipart(another_id);
                        CUP_parser_result = new Symbol(13, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 72:
                    // opt_label ::= empty
                    {
                        System.String RESULT = null;
                        RESULT = null;
                        CUP_parser_result = new Symbol(39, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 71:
                    // opt_label ::= COLON label_id
                    {
                        System.String RESULT = null;
                        int labidleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int labidright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String labid = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;
                        RESULT = labid;
                        CUP_parser_result = new Symbol(39, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 70:
                    // prod_part ::= CODE_STRING
                    {
                        System.Object RESULT = null;
                        int code_strleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int code_strright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String code_str = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* add a new production part */
                        add_rhs_part(new action_part(code_str));

                        CUP_parser_result = new Symbol(24, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 69:
                    // prod_part ::= symbol_id opt_label
                    {
                        System.Object RESULT = null;
                        int symidleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int symidright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.String symid = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;
                        int labidleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int labidright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String labid = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* try to look up the id */
                        production_part symb = (production_part) symbols[symid];

                        /* if that fails, symbol is undeclared */
                        if (symb == null)
                        {
                            if (lexer.error_count == 0)
                                lexer.emit_error("CUP.runtime.Symbol \"" + symid + "\" has not been declared");
                        }
                        else
                        {
                            /* add a labeled production part */
                            add_rhs_part(add_lab(symb, labid));
                        }

                        CUP_parser_result = new Symbol(24, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 68:
                    // prod_part_list ::= empty
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(23, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 67:
                    // prod_part_list ::= prod_part_list prod_part
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(23, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 66:
                    // rhs ::= prod_part_list
                    {
                        System.Object RESULT = null;

                        if (lhs_nt != null)
                        {
                            /* build the production */
                            production p = new production(lhs_nt, rhs_parts, rhs_pos);

                            /* if we have no start non-terminal declared and this is
                            the first production, make its lhs nt the start_nt
                            and build a special start production for it. */
                            if (start_nt == null)
                            {
                                start_nt = lhs_nt;

                                /* build a special start production */
                                new_rhs();
                                add_rhs_part(add_lab(new symbol_part(start_nt), "start_val"));
                                add_rhs_part(new symbol_part(terminal.EOF));
                                add_rhs_part(new action_part("RESULT = start_val;"));
                                emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos);

                                new_rhs();
                            }
                        }

                        /* reset the rhs accumulation in any case */
                        new_rhs();

                        CUP_parser_result = new Symbol(28, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 65:
                    // rhs ::= prod_part_list PERCENT_PREC term_id
                    {
                        System.Object RESULT = null;
                        int term_nameleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int term_nameright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String term_name = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        CUP.symbol sym = null;
                        if (lhs_nt != null)
                        {
                            /* Find the precedence symbol */
                            if (term_name == null)
                            {
                                System.Console.Error.WriteLine("No terminal for contextual precedence");
                                sym = null;
                            }
                            else
                            {
                                sym = ((symbol_part) symbols[term_name]).the_symbol();
                            }
                            /* build the production */
                            production p;
                            if ((sym != null) && (sym is terminal))
                            {
                                p = new production(lhs_nt, rhs_parts, rhs_pos, ((terminal) sym).precedence_num(), ((terminal) sym).precedence_side());
                                ((symbol_part) symbols[term_name]).the_symbol().note_use();
                            }
                            else
                            {
                                System.Console.Error.WriteLine("Invalid terminal " + term_name + " for contextual precedence assignment");
                                p = new production(lhs_nt, rhs_parts, rhs_pos);
                            }

                            /* if we have no start non-terminal declared and this is
                            the first production, make its lhs nt the start_nt
                            and build a special start production for it. */
                            if (start_nt == null)
                            {
                                start_nt = lhs_nt;

                                /* build a special start production */
                                new_rhs();
                                add_rhs_part(add_lab(new symbol_part(start_nt), "start_val"));
                                add_rhs_part(new symbol_part(terminal.EOF));
                                add_rhs_part(new action_part("RESULT = start_val;"));
                                if ((sym != null) && (sym is terminal))
                                {
                                    emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos, ((terminal) sym).precedence_num(), ((terminal) sym).precedence_side());
                                }
                                else
                                {
                                    emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos);
                                }
                                new_rhs();
                            }
                        }

                        /* reset the rhs accumulation in any case */
                        new_rhs();

                        CUP_parser_result = new Symbol(28, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 64:
                    // rhs_list ::= rhs
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(27, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 63:
                    // rhs_list ::= rhs_list BAR rhs
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(27, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 62:
                    // production ::= error NT_13 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_13
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(22, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 61:
                    // NT_13 ::=
                    {
                        System.Object RESULT = null;
                        lexer.emit_error("Syntax Error");
                        CUP_parser_result = new Symbol(56, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 60:
                    // production ::= nt_id NT_11 COLON_COLON_EQUALS NT_12 rhs_list SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_11
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).value_Renamed;
                        // propagate RESULT from NT_12
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;
                        int lhs_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 5)).left;
                        int lhs_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 5)).right;
                        System.String lhs_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 5)).value_Renamed;

                        CUP_parser_result = new Symbol(22, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 5)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 59:
                    // NT_12 ::=
                    {
                        System.Object RESULT = null;
                        int lhs_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                        int lhs_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                        System.String lhs_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;

                        CUP_parser_result = new Symbol(55, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 58:
                    // NT_11 ::=
                    {
                        System.Object RESULT = null;
                        int lhs_idleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int lhs_idright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String lhs_id = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* lookup the lhs nt */
                        lhs_nt = (non_terminal) non_terms[lhs_id];

                        /* if it wasn't declared, emit a message */
                        if (lhs_nt == null)
                        {
                            if (lexer.error_count == 0)
                                lexer.emit_error("LHS non terminal \"" + lhs_id + "\" has not been declared");
                        }

                        /* reset the rhs accumulation */
                        new_rhs();

                        CUP_parser_result = new Symbol(54, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 57:
                    // production_list ::= production
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(12, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 56:
                    // production_list ::= production_list production
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(12, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 55:
                    // start_spec ::= empty
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(11, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 54:
                    // start_spec ::= START WITH nt_id NT_10 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_10
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;
                        int start_nameleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left;
                        int start_nameright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).right;
                        System.String start_name = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;

                        CUP_parser_result = new Symbol(11, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 53:
                    // NT_10 ::=
                    {
                        System.Object RESULT = null;
                        int start_nameleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int start_nameright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String start_name = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* verify that the name has been declared as a non terminal */
                        non_terminal nt = (non_terminal) non_terms[start_name];
                        if (nt == null)
                        {
                            lexer.emit_error("Start non terminal \"" + start_name + "\" has not been declared");
                        }
                        else
                        {
                            /* remember the non-terminal for later */
                            start_nt = nt;

                            /* build a special start production */
                            new_rhs();
                            add_rhs_part(add_lab(new symbol_part(start_nt), "start_val"));
                            add_rhs_part(new symbol_part(terminal.EOF));
                            add_rhs_part(new action_part("RESULT = start_val;"));
                            emit.start_production = new production(non_terminal.START_nt, rhs_parts, rhs_pos);
                            new_rhs();
                        }

                        CUP_parser_result = new Symbol(53, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 52:
                    // term_id ::= symbol_id
                    {
                        System.String RESULT = null;
                        int symleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int symright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String sym = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        /* check that the symbol_id is a terminal */
                        if (symbols[sym] == null)
                        {
                            /* issue a message */
                            lexer.emit_error("Terminal \"" + sym + "\" has not been declared");
                        }
                        RESULT = sym;

                        CUP_parser_result = new Symbol(41, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 51:
                    // terminal_id ::= term_id
                    {
                        System.String RESULT = null;
                        int symleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left;
                        int symright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right;
                        System.String sym = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).value_Renamed;

                        add_precedence(sym);
                        RESULT = sym;

                        CUP_parser_result = new Symbol(40, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 50:
                    // terminal_list ::= terminal_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(32, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 49:
                    // terminal_list ::= terminal_list COMMA terminal_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(32, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 48:
                    // preced ::= PRECEDENCE NONASSOC NT_9 terminal_list SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_9
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;

                        CUP_parser_result = new Symbol(31, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 47:
                    // NT_9 ::=
                    {
                        System.Object RESULT = null;

                        update_precedence(assoc.nonassoc);

                        CUP_parser_result = new Symbol(52, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 46:
                    // preced ::= PRECEDENCE RIGHT NT_8 terminal_list SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_8
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;

                        CUP_parser_result = new Symbol(31, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 45:
                    // NT_8 ::=
                    {
                        System.Object RESULT = null;

                        update_precedence(assoc.right);

                        CUP_parser_result = new Symbol(51, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 44:
                    // preced ::= PRECEDENCE LEFT NT_7 terminal_list SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_7
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).value_Renamed;

                        CUP_parser_result = new Symbol(31, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 43:
                    // NT_7 ::=
                    {
                        System.Object RESULT = null;

                        update_precedence(assoc.left);

                        CUP_parser_result = new Symbol(50, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 42:
                    // precedence_l ::= preced
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(33, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 41:
                    // precedence_l ::= precedence_l preced
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(33, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 40:
                    // precedence_list ::= empty
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(30, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 39:
                    // precedence_list ::= precedence_l
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(30, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 38:
                    // non_term_name_list ::= new_non_term_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(21, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 37:
                    // non_term_name_list ::= non_term_name_list COMMA new_non_term_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(21, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 36:
                    // term_name_list ::= new_term_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(20, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 35:
                    // term_name_list ::= term_name_list COMMA new_term_id
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(20, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 34:
                    // declares_non_term ::= non_term_name_list NT_6 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_6
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(35, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 33:
                    // NT_6 ::=
                    {
                        System.Object RESULT = null;

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(49, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 32:
                    // declares_term ::= term_name_list NT_5 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_5
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(34, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 31:
                    // NT_5 ::=
                    {
                        System.Object RESULT = null;

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(48, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 30:
                    // symbol ::= non_terminal error NT_4 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_4
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 29:
                    // NT_4 ::=
                    {
                        System.Object RESULT = null;

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(47, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 28:
                    // symbol ::= TERMINAL error NT_3 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_3
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 27:
                    // NT_3 ::=
                    {
                        System.Object RESULT = null;

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(46, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 26:
                    // symbol ::= non_terminal declares_non_term
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 25:
                    // symbol ::= non_terminal type_id declares_non_term
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 24:
                    // symbol ::= TERMINAL declares_term
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 23:
                    // symbol ::= TERMINAL type_id declares_term
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(18, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 2)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 22:
                    // symbol_list ::= symbol
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(10, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 21:
                    // symbol_list ::= symbol_list symbol
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(10, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 20:
                    // scan_code ::= SCAN WITH CODE_STRING opt_semi
                    {
                        System.Object RESULT = null;
                        int user_codeleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int user_coderight = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.String user_code = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        if (emit.scan_code != null)
                            lexer.emit_error("Redundant scan code (skipping)");
                        else
                            emit.scan_code = user_code;

                        CUP_parser_result = new Symbol(17, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 19:
                    // init_code ::= INIT WITH CODE_STRING opt_semi
                    {
                        System.Object RESULT = null;
                        int user_codeleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int user_coderight = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.String user_code = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        if (emit.init_code != null)
                            lexer.emit_error("Redundant init code (skipping)");
                        else
                            emit.init_code = user_code;

                        CUP_parser_result = new Symbol(16, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 18:
                    // parser_code_part ::= PARSER CODE CODE_STRING opt_semi
                    {
                        System.Object RESULT = null;
                        int user_codeleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int user_coderight = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.String user_code = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        if (emit.parser_code != null)
                            lexer.emit_error("Redundant parser code (skipping)");
                        else
                            emit.parser_code = user_code;

                        CUP_parser_result = new Symbol(9, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 17:
                    // action_code_part ::= ACTION CODE CODE_STRING opt_semi
                    {
                        System.Object RESULT = null;
                        int user_codeleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int user_coderight = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.String user_code = (string) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        if (emit.action_code != null)
                            lexer.emit_error("Redundant action code (skipping)");
                        else
                            emit.action_code = user_code;

                        CUP_parser_result = new Symbol(4, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 16:
                    // code_parts ::= code_parts code_part
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(5, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 15:
                    // code_parts ::=
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(5, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 14:
                    // code_part ::= scan_code
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(6, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 13:
                    // code_part ::= init_code
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(6, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 12:
                    // code_part ::= parser_code_part
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(6, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 11:
                    // code_part ::= action_code_part
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(6, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 10:
                    // import_spec ::= IMPORT import_id NT_2 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_2
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(14, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 9:
                    // NT_2 ::=
                    {
                        System.Object RESULT = null;

                        /* save this import on the imports list */
                        emit.import_list.Push(multipart_name);

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(45, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 8:
                    // import_list ::= empty
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(3, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 7:
                    // import_list ::= import_list import_spec
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(3, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 6:
                    // package_spec ::= empty
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(2, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 5:
                    // package_spec ::= PACKAGE multipart_id NT_1 SEMI
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_1
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;

                        CUP_parser_result = new Symbol(2, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 3)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 4:
                    // NT_1 ::=
                    {
                        System.Object RESULT = null;

                        /* save the package name */
                        emit.namespace_name = multipart_name;

                        /* reset the accumulated multipart name */
                        multipart_name = new string("".ToCharArray());

                        CUP_parser_result = new Symbol(44, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 3:
                    // spec ::= error symbol_list precedence_list start_spec production_list
                    {
                        System.Object RESULT = null;

                        CUP_parser_result = new Symbol(1, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 4)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 2:
                    // spec ::= NT_0 package_spec import_list code_parts symbol_list precedence_list start_spec production_list
                    {
                        System.Object RESULT = null;
                        // propagate RESULT from NT_0
                        if (((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 7)).value_Renamed != null)
                            RESULT = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 7)).value_Renamed;

                        CUP_parser_result = new Symbol(1, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 7)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 1:
                    // NT_0 ::=
                    {
                        System.Object RESULT = null;

                        /* declare "error" as a terminal */
                        SupportClass.PutElement(symbols, "error", new symbol_part(terminal.error));

                        /* declare start non terminal */
                        SupportClass.PutElement(non_terms, "_START", non_terminal.START_nt);

                        CUP_parser_result = new Symbol(43, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    return CUP_parser_result;

                    /*. . . . . . . . . . . . . . . . . . . .*/

                case 0:
                    // _START ::= spec EOF
                    {
                        System.Object RESULT = null;
                        int start_valleft = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left;
                        int start_valright = ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).right;
                        System.Object start_val = (object) ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).value_Renamed;
                        RESULT = start_val;
                        CUP_parser_result = new Symbol(0, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 1)).left, ((Symbol) CUP_parser_stack.Peek(CUP_parser_top - 0)).right, RESULT);
                    }
                    /* ACCEPT */
                    CUP_parser_parser.done_parsing();
                    return CUP_parser_result;

                    /* . . . . . .*/

                default:
                    throw new System.Exception("Invalid action number found in internal parse table");

            }
        }
Example #30
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <summary>Emit the parser subclass with embedded tables. 
        /// </summary>
        /// <param name="out">            stream to produce output on.
        /// </param>
        /// <param name="action_table">   internal representation of the action table.
        /// </param>
        /// <param name="reduce_table">   internal representation of the reduce-goto table.
        /// </param>
        /// <param name="start_st">       start state of the parse machine.
        /// </param>
        /// <param name="start_prod">     start production of the grammar.
        /// </param>
        /// <param name="compact_reduces">do we use most frequent reduce as default?
        /// </param>
        /// <param name="suppress_scanner">should scanner be suppressed for compatibility?
        /// 
        /// </param>
        public static void parser(System.IO.StreamWriter out_Renamed, parse_action_table action_table, parse_reduce_table reduce_table, int start_st, production start_prod, bool compact_reduces, bool suppress_scanner)
        {
            long start_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            /* top of file */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("//----------------------------------------------------");
            out_Renamed.WriteLine("// The following code was generated by " + version.title_str);
            out_Renamed.WriteLine("// " + System.DateTime.Now);
            out_Renamed.WriteLine("//----------------------------------------------------");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("using System;");
            emit_package(out_Renamed);

            /* user supplied imports */
            for (int i = 0; i < import_list.Count; i++)
            {
                out_Renamed.WriteLine("using " + import_list.Peek(import_list.Count - (i + 1)) + ";");
            }

            /* class header */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("///<summary>" + version.title_str + " generated parser." + "</summary>");
            out_Renamed.WriteLine("///<version>" + System.DateTime.Now + "</version>");
            out_Renamed.WriteLine("///");
            out_Renamed.WriteLine("public class " + parser_class_name + " : CUP.runtime.lr_parser {");

            /* constructors [CSA/davidm, 24-jul-99] */
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** Default constructor. */");
            out_Renamed.WriteLine("  public " + parser_class_name + "() : base() {}");
            if (!suppress_scanner)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** Constructor which sets the default scanner. */");
                out_Renamed.WriteLine("  public " + parser_class_name + "(CUP.runtime.Scanner s) : base(s) {}");
            }

            /* emit the various tables */
            emit_production_table(out_Renamed);
            do_action_table(out_Renamed, action_table, compact_reduces);
            do_reduce_table(out_Renamed, reduce_table);

            /* instance of the action encapsulation class */
            out_Renamed.WriteLine("  /** Instance of action encapsulation class. */");
            out_Renamed.WriteLine("  protected " + pre("actions") + " action_obj;");
            out_Renamed.WriteLine();

            /* action object initializer */
            out_Renamed.WriteLine("  /** Action encapsulation object initializer. */");
            out_Renamed.WriteLine("  protected override void init_actions()");
            out_Renamed.WriteLine("    {");
            out_Renamed.WriteLine("      action_obj = new " + pre("actions") + "(this);");
            out_Renamed.WriteLine("    }");
            out_Renamed.WriteLine();

            /* access to action code */
            out_Renamed.WriteLine("  /** Invoke a user supplied parse action. */");
            out_Renamed.WriteLine("  public override CUP.runtime.Symbol do_action(");
            out_Renamed.WriteLine("    int                        act_num,");
            out_Renamed.WriteLine("    CUP.runtime.lr_parser parser,");
            out_Renamed.WriteLine("    CUP.runtime.SymbolStack   stack,");
            out_Renamed.WriteLine("    int                        top)");
            out_Renamed.WriteLine("  {");
            out_Renamed.WriteLine("    /* call code in generated class */");
            out_Renamed.WriteLine("    return action_obj." + pre("do_action(") + "act_num, parser, stack, top);");
            out_Renamed.WriteLine("  }");
            out_Renamed.WriteLine("");

            /* method to tell the parser about the start state */
            out_Renamed.WriteLine("  /** Indicates start state. */");
            out_Renamed.WriteLine("  public override int start_state() {return " + start_st + ";}");

            /* method to indicate start production */
            out_Renamed.WriteLine("  /** Indicates start production. */");
            out_Renamed.WriteLine("  public override int start_production() {return " + start_production.index() + ";}");
            out_Renamed.WriteLine();

            /* methods to indicate EOF and error symbol indexes */
            out_Renamed.WriteLine("  /** <code>EOF</code> Symbol index. */");
            out_Renamed.WriteLine("  public override int EOF_sym() {return " + terminal.EOF.index() + ";}");
            out_Renamed.WriteLine();
            out_Renamed.WriteLine("  /** <code>error</code> Symbol index. */");
            out_Renamed.WriteLine("  public override int error_sym() {return " + terminal.error.index() + ";}");
            out_Renamed.WriteLine();

            /* user supplied code for user_init() */
            if (init_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** User initialization code. */");
                out_Renamed.WriteLine("  public override void user_init()");
                out_Renamed.WriteLine("    {");
                out_Renamed.WriteLine(init_code);
                out_Renamed.WriteLine("    }");
            }

            /* user supplied code for scan */
            if (scan_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine("  /** Scan to get the next Symbol. */");
                out_Renamed.WriteLine("  public override CUP.runtime.Symbol scan()");
                out_Renamed.WriteLine("    {");
                out_Renamed.WriteLine(scan_code);
                out_Renamed.WriteLine("    }");
            }

            /* user supplied code */
            if (parser_code != null)
            {
                out_Renamed.WriteLine();
                out_Renamed.WriteLine(parser_code);
            }

            /* end of class */
            out_Renamed.WriteLine("}");

            /* put out the action code class */
            emit_action_code(out_Renamed, start_prod);

            // End of namespace
            out_Renamed.WriteLine("}");

            parser_time = (System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start_time;
        }
Example #31
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Fill in the parse table entries for this state.  There are two
        /// parse tables that encode the viable prefix recognition machine, an
        /// action table and a reduce-goto table.  The rows in each table
        /// correspond to states of the machine.  The columns of the action table
        /// are indexed by terminal symbols and correspond to either transitions
        /// out of the state (shift entries) or reductions from the state to some
        /// previous state saved on the stack (reduce entries).  All entries in the
        /// action table that are not shifts or reduces, represent errors.    The
        /// reduce-goto table is indexed by non terminals and represents transitions
        /// out of a state on that non-terminal.<p>
        /// Conflicts occur if more than one action needs to go in one entry of the
        /// action table (this cannot happen with the reduce-goto table).  Conflicts
        /// are resolved by always shifting for shift/reduce conflicts and choosing
        /// the lowest numbered production (hence the one that appeared first in
        /// the specification) in reduce/reduce conflicts.  All conflicts are
        /// reported and if more conflicts are detected than were declared by the
        /// user, code generation is aborted.
        /// *
        /// </summary>
        /// <param name="act_table">   the action table to put entries in.
        /// </param>
        /// <param name="reduce_table">the reduce-goto table to put entries in.
        ///
        /// </param>
        public virtual void  build_table_entries(parse_action_table act_table, parse_reduce_table reduce_table)
        {
            parse_action_row our_act_row;
            parse_reduce_row our_red_row;
            lalr_item        itm;
            parse_action     act, other_act;
            symbol           sym;
            terminal_set     conflict_set = new terminal_set();

            /* pull out our rows from the tables */
            our_act_row = act_table.under_state[index()];
            our_red_row = reduce_table.under_state[index()];

            /* consider each item in our state */
            //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"'
            for (System.Collections.IEnumerator i = items().all(); i.MoveNext();)
            {
                //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"'
                itm = (lalr_item)i.Current;


                /* if its completed (dot at end) then reduce under the lookahead */
                if (itm.dot_at_end())
                {
                    act = new reduce_action(itm.the_production());

                    /* consider each lookahead symbol */
                    for (int t = 0; t < terminal.number(); t++)
                    {
                        /* skip over the ones not in the lookahead */
                        if (!itm.lookahead().contains(t))
                        {
                            continue;
                        }

                        /* if we don't already have an action put this one in */
                        if (our_act_row.under_term[t].kind() == parse_action.ERROR)
                        {
                            our_act_row.under_term[t] = act;
                        }
                        else
                        {
                            /* we now have at least one conflict */
                            terminal term = terminal.find(t);
                            other_act = our_act_row.under_term[t];

                            /* if the other act was not a shift */
                            if ((other_act.kind() != parse_action.SHIFT) && (other_act.kind() != parse_action.NONASSOC))
                            {
                                /* if we have lower index hence priority, replace it*/
                                if (itm.the_production().index() < ((reduce_action)other_act).reduce_with().index())
                                {
                                    /* replace the action */
                                    our_act_row.under_term[t] = act;
                                }
                            }
                            else
                            {
                                /*  Check precedences,see if problem is correctable */
                                if (fix_with_precedence(itm.the_production(), t, our_act_row, act))
                                {
                                    term = null;
                                }
                            }
                            if (term != null)
                            {
                                conflict_set.add(term);
                            }
                        }
                    }
                }
            }

            /* consider each outgoing transition */
            for (lalr_transition trans = transitions(); trans != null; trans = trans.next())
            {
                /* if its on an terminal add a shift entry */
                sym = trans.on_symbol();
                if (!sym.is_non_term())
                {
                    act = new shift_action(trans.to_state());

                    /* if we don't already have an action put this one in */
                    if (our_act_row.under_term[sym.index()].kind() == parse_action.ERROR)
                    {
                        our_act_row.under_term[sym.index()] = act;
                    }
                    else
                    {
                        /* we now have at least one conflict */
                        production p = ((reduce_action)our_act_row.under_term[sym.index()]).reduce_with();

                        /* shift always wins */
                        if (!fix_with_precedence(p, sym.index(), our_act_row, act))
                        {
                            our_act_row.under_term[sym.index()] = act;
                            conflict_set.add(terminal.find(sym.index()));
                        }
                    }
                }
                else
                {
                    /* for non terminals add an entry to the reduce-goto table */
                    our_red_row.under_non_term[sym.index()] = trans.to_state();
                }
            }

            /* if we end up with conflict(s), report them */
            if (!conflict_set.empty())
            {
                report_conflicts(conflict_set);
            }
        }