示例#1
0
        private void CompressCharLists()
        {
            CompressChoices(); // Unroll nested choices
            RegularExpression curRE;
            RCharacterList curCharList = null;

            for (int i = 0; i < choices.Count; i++) {
                curRE = choices[i];

                while (curRE is RJustName)
                    curRE = ((RJustName) curRE).RegularExpression;

                if (curRE is RStringLiteral &&
                    ((RStringLiteral) curRE).Image.Length == 1)
                    choices[i] = curRE = new RCharacterList(((RStringLiteral) curRE).Image[0]);

                if (curRE is RCharacterList) {
                    if (((RCharacterList) curRE).Negated)
                        ((RCharacterList) curRE).RemoveNegation();

                    IList<object> tmp = ((RCharacterList) curRE).Descriptors;

                    if (curCharList == null)
                        choices[i] = curRE = curCharList = new RCharacterList();
                    else
                        choices.RemoveAt(i--);

                    for (int j = tmp.Count; j-- > 0;)
                        curCharList.Descriptors.Add(tmp[j]);
                }

            }
        }
示例#2
0
        private void CompressCharLists()
        {
            CompressChoices();             // Unroll nested choices
            RegularExpression curRE;
            RCharacterList    curCharList = null;

            for (int i = 0; i < choices.Count; i++)
            {
                curRE = choices[i];

                while (curRE is RJustName)
                {
                    curRE = ((RJustName)curRE).RegularExpression;
                }

                if (curRE is RStringLiteral &&
                    ((RStringLiteral)curRE).Image.Length == 1)
                {
                    choices[i] = curRE = new RCharacterList(((RStringLiteral)curRE).Image[0]);
                }

                if (curRE is RCharacterList)
                {
                    if (((RCharacterList)curRE).Negated)
                    {
                        ((RCharacterList)curRE).RemoveNegation();
                    }

                    IList <object> tmp = ((RCharacterList)curRE).Descriptors;

                    if (curCharList == null)
                    {
                        choices[i] = curRE = curCharList = new RCharacterList();
                    }
                    else
                    {
                        choices.RemoveAt(i--);
                    }

                    for (int j = tmp.Count; j-- > 0;)
                    {
                        curCharList.Descriptors.Add(tmp[j]);
                    }
                }
            }
        }
示例#3
0
        public override Nfa GenerateNfa(bool ignoreCase)
        {
            if (Image.Length == 1) {
                RCharacterList temp = new RCharacterList(Image[0]);
                return temp.GenerateNfa(ignoreCase);
            }

            NfaState startState = new NfaState();
            NfaState theStartState = startState;
            NfaState finalState = null;

            if (Image.Length == 0)
                return new Nfa(theStartState, theStartState);

            int i;

            for (i = 0; i < Image.Length; i++) {
                finalState = new NfaState();
                startState.charMoves = new char[1];
                startState.AddChar(Image[i]);

                if (Options.getIgnoreCase() || ignoreCase) {
                    startState.AddChar(Char.ToLower(Image[i]));
                    startState.AddChar(Char.ToUpper(Image[i]));
                }

                startState.next = finalState;
                startState = finalState;
            }

            return new Nfa(theStartState, finalState);
        }