コード例 #1
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/
        /// <summary>Simple constructor.  Note: this should not be used until the number of
        /// terminals in the grammar has been established.
        /// </summary>
        public parse_action_row()
        {
            /* make sure the size is set */
            if (_size <= 0)
                _size = terminal.number();

            /* allocate the array */
            under_term = new parse_action[size()];

            /* set each element to an error action */
             for (int i = 0; i < _size; i++)
                under_term[i] = new parse_action();
        }
コード例 #2
0
        /*-----------------------------------------------------------*/
        /*--- Constructor(s) ----------------------------------------*/
        /*-----------------------------------------------------------*/

        /// <summary>Simple constructor.  Note: this should not be used until the number of
        /// terminals in the grammar has been established.
        /// </summary>
        public parse_action_row()
        {
            /* make sure the size is set */
            if (_size <= 0)
            {
                _size = terminal.number();
            }

            /* allocate the array */
            under_term = new parse_action[size()];

            /* set each element to an error action */
            for (int i = 0; i < _size; i++)
            {
                under_term[i] = new parse_action();
            }
        }
コード例 #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/


        /*  given two actions, and an action type, return the
         * action of that action type.  give an error if they are of
         * the same action, because that should never have tried
         * to be fixed
         *
         */
        protected internal virtual parse_action insert_action(parse_action a1, parse_action a2, int act_type)
        {
            if ((a1.kind() == act_type) && (a2.kind() == act_type))
            {
                throw new internal_error("Conflict resolution of bogus actions");
            }
            else if (a1.kind() == act_type)
            {
                return(a1);
            }
            else if (a2.kind() == act_type)
            {
                return(a2);
            }
            else
            {
                throw new internal_error("Conflict resolution of bogus actions");
            }
        }
コード例 #4
0
ファイル: parse_action.cs プロジェクト: rmorgan0076/CUP
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Equality test.
        /// </summary>
        public virtual bool equals(parse_action other)
        {
            /* we match all error actions */
            return(other != null && other.kind() == ERROR);
        }
コード例 #5
0
ファイル: nonassoc_action.cs プロジェクト: rmorgan0076/CUP
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /// <summary>Equality test.
        /// </summary>
        public override bool equals(parse_action other)
        {
            return(other != null && other.kind() == NONASSOC);
        }
コード例 #6
0
ファイル: nonassoc_action.cs プロジェクト: BeyondOrdinary/CUP
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Equality test. 
 /// </summary>
 public override bool equals(parse_action other)
 {
     return other != null && other.kind() == NONASSOC;
 }
コード例 #7
0
ファイル: lalr_state.cs プロジェクト: BeyondOrdinary/CUP
 /* find the shift in the two actions */
 protected internal virtual parse_action insert_shift(parse_action a1, parse_action a2)
 {
     return insert_action(a1, a2, parse_action.SHIFT);
 }
コード例 #8
0
ファイル: lalr_state.cs プロジェクト: BeyondOrdinary/CUP
 /* find the reduce in the two actions */
 protected internal virtual parse_action insert_reduce(parse_action a1, parse_action a2)
 {
     return insert_action(a1, a2, parse_action.REDUCE);
 }
コード例 #9
0
ファイル: lalr_state.cs プロジェクト: BeyondOrdinary/CUP
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /*  given two actions, and an action type, return the
        action of that action type.  give an error if they are of
        the same action, because that should never have tried
        to be fixed

        */
        protected internal virtual parse_action insert_action(parse_action a1, parse_action a2, int act_type)
        {
            if ((a1.kind() == act_type) && (a2.kind() == act_type))
            {
                throw new internal_error("Conflict resolution of bogus actions");
            }
            else if (a1.kind() == act_type)
            {
                return a1;
            }
            else if (a2.kind() == act_type)
            {
                return a2;
            }
            else
            {
                throw new internal_error("Conflict resolution of bogus actions");
            }
        }
コード例 #10
0
ファイル: lalr_state.cs プロジェクト: BeyondOrdinary/CUP
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
        /// <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;
        }
コード例 #11
0
 /* find the reduce in the two actions */
 protected internal virtual parse_action insert_reduce(parse_action a1, parse_action a2)
 {
     return(insert_action(a1, a2, parse_action.REDUCE));
 }
コード例 #12
0
 /* find the shift in the two actions */
 protected internal virtual parse_action insert_shift(parse_action a1, parse_action a2)
 {
     return(insert_action(a1, a2, parse_action.SHIFT));
 }
コード例 #13
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);
        }
コード例 #14
0
ファイル: parse_action.cs プロジェクト: BeyondOrdinary/CUP
 /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 /// <summary>Equality test. 
 /// </summary>
 public virtual bool equals(parse_action other)
 {
     /* we match all error actions */
     return other != null && other.kind() == ERROR;
 }