Example #1
0
 public ReduceEventArgs(Rule rule, NonterminalToken token, State newState)
 {
     this.rule     = rule;
     this.token    = token;
     this.newState = newState;
     this.contin   = true;
 }
 private void DoReleaseTokens(NonterminalToken token)
 {
     if ((StoreTokens == StoreTokensMode.Never) ||
         (StoreTokens == StoreTokensMode.NoUserObject &&
          token.UserObject != null))
     {
         token.ClearTokens();
     }
 }
        private void DoReduce(Token token, ReduceAction action)
        {
            int reduceLength = action.Rule.Rhs.Length;

            State currentState;
            // Do not reduce if the rule is single nonterminal and TrimReductions is on
            bool skipReduce = ((TrimReductions) &&
                               (reduceLength == 1) && (action.Rule.Rhs[0] is SymbolNonterminal));

            if (skipReduce)
            {
                stateStack.Pop();
                currentState = stateStack.Peek();
            }
            else
            {
                Token[] tokens = new Token[reduceLength];
                for (int i = 0; i < reduceLength; i++)
                {
                    stateStack.Pop();
                    tokens[reduceLength - i - 1] = tokenStack.Pop();
                }
                NonterminalToken nttoken = new NonterminalToken(action.Rule, tokens);
                tokenStack.Push(nttoken);
                currentState = stateStack.Peek();

                if (OnReduce != null)
                {
                    ReduceEventArgs args = new ReduceEventArgs(action.Rule,
                                                               nttoken,
                                                               currentState);
                    OnReduce(this, args);
                    DoReleaseTokens(args.Token);

                    continueParsing = args.Continue;
                }
            }
            Action gotoAction = currentState.Actions.Get(action.Rule.Lhs);

            if (gotoAction is GotoAction)
            {
                DoGoto(token, (GotoAction)gotoAction);
            }
            else
            {
                throw new ParserException("Invalid action table in state");
            }
        }
Example #4
0
 public AcceptEventArgs(NonterminalToken token)
 {
     this.token = token;
 }