Пример #1
0
        public List <State> advanceOneObject()
        {
            if (completedStack
                //				|| minimumTerminalsLeftToComplete() > terminalsLeft()
                )
            {
                return(new List <State>());
            }
            //if(completedStack) return new List<State> {this};

            SyntaticObject syntaticObject = stack.Pop();

            State     nextState     = new State(this);
            ParseNode nextAvailable = nextState.findNextAvailableNode();

            if (syntaticObject is Terminal)
            {
                Terminal terminal = syntaticObject as Terminal;
                if (terminal.token == currentChar + "")
                {
                    nextState.advanceOneChar();
                    new StringNode(nextAvailable as CategoryNode, terminal.token);
                    return(new List <State> {
                        nextState
                    });
                }
                return(new List <State>());
            }
            if (syntaticObject is Token)
            {
                Token terminal = syntaticObject as Token;

                if (terminal.token == currentToken)
                {
                    nextState.advanceOneToken();
                    new StringNode(nextAvailable as CategoryNode, terminal.token);
                    return(new List <State> {
                        nextState
                    });
                }
                return(new List <State>());
            }
            if (syntaticObject is Category)
            {
                Category     category = syntaticObject as Category;
                List <State> output   = new List <State>();

                if (!category.StrictTokenUsage)
                {
                    foreach (SyntaticObject[] syntaticObjects in category)
                    {
                        nextState = new State(this);
                        Stack <SyntaticObject> s = nextState.stack;
                        for (var i = syntaticObjects.Length - 1; i >= 0; i--)
                        {
                            s.Push(syntaticObjects[i]);
                        }

                        new CategoryNode(nextState.findNextAvailableNode(), category, syntaticObjects.Length);
                        nextState.index = index;
                        output.Add(nextState);
                    }
                }
                else
                {
                    PushDownAutomata internalDriver = new PushDownAutomata(new string[0], nextState.currentToken, category);
                    ParseTree        tokenParse     = internalDriver.parse();

                    if (tokenParse != null && tokenParse.success)
                    {
                        nextState.findNextAvailableNode().Add(tokenParse);
                        nextState.advanceOneToken();
                        output.Add(nextState);
                    }
                }

                return(output);
            }

            return(null);
        }