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

            State currentState;
            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;
                }
            }
            lalr.Action gotoAction = currentState.Actions.Get(action.Rule.Lhs);

            if (gotoAction is GotoAction)
            {
                DoGoto(token, (GotoAction)gotoAction);
            }
            else
            {
                throw new ParserException("Tabla de acciones inválida en el estado");
            }
        }
예제 #4
0
 public AcceptEventArgs(NonterminalToken token)
 {
     this.token = token;
 }