Esempio n. 1
0
        public void Run(Syntatical syntatical, String out, Lexical lexer)
        {
            int          state        = 0;
            Token        currentToken = lexer.NextToken();
            NonTerminals nonterminals = new NonTerminals();
            var          action       = syntatical.actionTable[state][currentToken.Primary];

            // var sem = semantics.NewAnalyser(lexer, out);

            while (!Accept(action))
            {
                state = Shift(action);
                if (state != -1)
                {
                    syntatical.stateStack.Push(state);
                    currentToken = lexer.NextToken();
                    action       = syntatical.actionTable[state][currentToken.Primary];
                    continue;
                }

                int rule = Reduce(action);
                if (rule != -1)
                {
                    var amountToPop = nonterminals.RuleNumberOfTokens[rule - 1];
                    while (amountToPop > 0)
                    {
                        syntatical.stateStack.Pop();
                        amountToPop = amountToPop - 1;
                    }
                    var temporaryState = syntatical.stateStack.Peek();
                    var leftToken      = nonterminals.RuleLeftTokens[rule - 1];
                    var stateString    = syntatical.actionTable[temporaryState][leftToken];
                    state = int.Parse(stateString);
                    syntatical.stateStack.Push(state);
                    action = syntatical.actionTable[state][currentToken];
                    // sem.Parse(rule);
                    continue;
                }
            }
            // sem.Close();
        }