Ejemplo n.º 1
0
        static Symbol MatchedDFA(string s, Symbol sym)
        {
            int  i, len = s.Length;
            bool weakMatch = false;
            // s has no quotes
            State state = firstState;

            for (i = 0; i < len; i++) // try to match s against existing DFA
            {
                Action a = state.TheAction(s[i]);
                if (a == null)
                {
                    break;
                }
                if (a.typ == Node.clas)
                {
                    weakMatch = true;
                }
                state = a.target.state;
            }
            // don't execute the following block if s was totally consumed and the DFA is in a final state
            if (weakMatch && (i != len || state.endOf == null))
            {
                state    = firstState;
                i        = 0;
                dirtyDFA = true;
            }
            for (; i < len; i++) // make new DFA for s[i..len-1]
            {
                State to = NewState();
                NewTransition(state, to, Node.chr, s[i], Node.normalTrans);
                state = to;
            }
            Symbol matchedSym = state.endOf;

            if (state.endOf == null)
            {
                state.endOf = sym;
            }
            return(matchedSym);
        }