示例#1
0
        protected void Reduce(int ruleId)
        {
            LogBeforeReduction(ruleId);

            int rhsLength = _ruleRhsLengths[ruleId];

            //
            //  Default action "$$ = $1" for unit productions.
            //  Default action "@$ = @1.Merge(@N)" for location info.
            //
            if (rhsLength == 1)
            {
                yyval = _valueStack.Peek(1); // default action: $$ = $1;
                yyloc = _locationStack.Peek(1);
            }
            else
            {
                yyval = new TValue();
                if (rhsLength == 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 = MergeLocations(_lastTokenSpan, TokenSpan);
                }
                else
                {
                    TLocation at1 = GetLocation(rhsLength);
                    TLocation atN = GetLocation(1);
                    if (at1 != null && atN != null)
                    {
                        yyloc = MergeLocations(at1, atN);
                    }
                }
            }

            DoAction(ruleId);

            _stateStack.Pop(rhsLength);
            _valueStack.Pop(rhsLength);
            _locationStack.Pop(rhsLength);

            _currentState = _stateStack.Peek(1);

            int gotoState;

            if (_currentState.GotoStates.TryGetValue(_ruleLhsNonTerminals[ruleId], out gotoState))
            {
                LogBeforeGoto(gotoState, ruleId);
                _currentState = _states[gotoState];
            }

            _stateStack.Push(_currentState);
            _valueStack.Push(yyval);
            _locationStack.Push(yyloc);
        }
示例#2
0
        private void Reduce(int ruleId)
        {
            int ruleDef   = _rules[ruleId];
            int rhsLength = GetRuleRhsLength(ruleDef);

            LogBeforeReduction(ruleId, rhsLength);

            if (rhsLength == 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 = MergeLocations(_lastTokenSpan, GetTokenSpan());
            }
            else if (rhsLength == 1)
            {
                yyloc = _stack.PeekLocation(1);
            }
            else
            {
                TLocation at1 = GetLocation(rhsLength);
                TLocation atN = GetLocation(1);
                yyloc = MergeLocations(at1, atN);
            }

            DoAction(ruleId);

            _stack.Pop(rhsLength);

            var currentState = _stack.PeekState(1);

            int gotoState;

            if (currentState.GotoStates.TryGetValue(GetRuleLhsNonterminal(ruleDef), out gotoState))
            {
                LogBeforeGoto(gotoState, ruleId);
                currentState = _states[gotoState];
            }

            _stack.Push(currentState, yyval, yyloc);

            _currentState = currentState;
        }