Beispiel #1
0
        protected ATNConfigSet ComputeStartState(ICharStream input,
                                                 ATNState p)
        {
            PredictionContext initialContext = PredictionContext.EMPTY;
            ATNConfigSet      configs        = new OrderedATNConfigSet();

            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState       target = p.Transition(i).target;
                LexerATNConfig c      = new LexerATNConfig(target, i + 1, initialContext);
                Closure(input, c, configs, false, false, false);
            }
            return(configs);
        }
Beispiel #2
0
        /**
         * Compute a target state for an edge in the DFA, and attempt to add the
         * computed state and corresponding edge to the DFA.
         *
         * @param input The input stream
         * @param s The current DFA state
         * @param t The next input symbol
         *
         * @return The computed target DFA state for the given input symbol
         * {@code t}. If {@code t} does not lead to a valid DFA state, this method
         * returns {@link #ERROR}.
         */

        protected DFAState ComputeTargetState(ICharStream input, DFAState s, int t)
        {
            ATNConfigSet reach = new OrderedATNConfigSet();

            // if we don't find an existing DFA state
            // Fill reach starting from closure, following t transitions
            GetReachableConfigSet(input, s.configSet, reach, t);

            if (reach.Empty)
            {             // we got nowhere on t from s
                if (!reach.hasSemanticContext)
                {
                    // we got nowhere on t, don't throw out this knowledge; it'd
                    // cause a failover from DFA later.
                    AddDFAEdge(s, t, ERROR);
                }

                // stop when we can't match any more char
                return(ERROR);
            }

            // Add an edge from s to target DFA found/created for reach
            return(AddDFAEdge(s, t, reach));
        }