Esempio n. 1
0
        protected void Reduce(int rule_nr)
        {
            Rule rule = rules[rule_nr];

            //
            //  Default action "$$ = $1" for unit productions.
            //
            if (rule.rhs.Length == 1)
            {
                yyval = value_stack.Top(); // default action: $$ = $1;
            }
            else
            {
                yyval = new YYSTYPE();
            }
            //
            //  Default action "@$ = @1.Merge(@N)" for location info.
            //
            if (rule.rhs.Length == 1)
            {
                yyloc = location_stack.Top();
            }
            else if (rule.rhs.Length == 0)
            {
                // The location span for an empty production will start with the
                // beginning of the next lexeme, and end with the finish of the
                // previous lexeme.  This gives the correct behaviour when this
                // nonsense value is used in later Merge operations.
                yyloc = (scanner.yylloc != null ? scanner.yylloc.Merge(lastL) : default(YYLTYPE));
            }
            else
            {
                YYLTYPE at1 = location_stack.array[location_stack.top - rule.rhs.Length];
                YYLTYPE atN = location_stack.array[location_stack.top - 1];
                if (at1 != null && atN != null)
                {
                    yyloc = at1.Merge(atN);
                }
            }

            DoAction(rule_nr);

            for (int i = 0; i < rule.rhs.Length; i++)
            {
                state_stack.Pop();
                value_stack.Pop();
                location_stack.Pop();
            }

            current_state = state_stack.Top();

            int vlhs;

            if (current_state.Goto.TryGetValue(rule.lhs, out vlhs))
            {
                current_state = states[vlhs];
            }

            state_stack.Push(current_state);
            value_stack.Push(yyval);
            location_stack.Push(yyloc);
        }
Esempio n. 2
0
        protected void Reduce(int rule_nr)
        {
            if (Trace)
            {
                DisplayRule(rule_nr);
            }

            Rule rule = rules[rule_nr];

            //
            //  Default action "$$ = $1" for unit productions.
            //
            if (rule.rhs.Length == 1)
            {
                yyval = value_stack.Top(); // default action: $$ = $1;
            }
            else
            {
                yyval = new YYSTYPE();
            }
            //
            //  Default action "@$ = @1.Merge(@N)" for location info.
            //
            if (rule.rhs.Length == 1)
            {
                yyloc = location_stack.Top();
            }
            else if (rule.rhs.Length == 0)
            {
                yyloc = default(YYLTYPE);
            }
            else
            {
                YYLTYPE at1 = location_stack.array[location_stack.top - rule.rhs.Length];
                YYLTYPE atN = location_stack.array[location_stack.top - 1];
                if (at1 != null && atN != null)
                {
                    yyloc = at1.Merge(atN);
                }
            }

            DoAction(rule_nr);

            for (int i = 0; i < rule.rhs.Length; i++)
            {
                state_stack.Pop();
                value_stack.Pop();
                location_stack.Pop();
            }

            if (Trace)
            {
                DisplayStack();
            }

            current_state = state_stack.Top();

            if (current_state.Goto.ContainsKey(rule.lhs))
            {
                current_state = states[current_state.Goto[rule.lhs]];
            }

            state_stack.Push(current_state);
            value_stack.Push(yyval);
            location_stack.Push(yyloc);
        }