コード例 #1
0
ファイル: RSequence.cs プロジェクト: ArsenShnurkov/csharpcc
		public override Nfa GenerateNfa(bool ignoreCase) {
			if (units.Count == 1)
				return units[0].GenerateNfa(ignoreCase);

			Nfa retVal = new Nfa();
			NfaState startState = retVal.Start;
			NfaState finalState = retVal.End;
			Nfa temp1;
			Nfa temp2 = null;

			RegularExpression curRE;

			curRE = units[0];
			temp1 = curRE.GenerateNfa(ignoreCase);
			startState.AddMove(temp1.Start);

			for (int i = 1; i < units.Count; i++) {
				curRE = units[i];

				temp2 = curRE.GenerateNfa(ignoreCase);
				temp1.End.AddMove(temp2.Start);
				temp1 = temp2;
			}

			temp2.End.AddMove(finalState);

			return retVal;

		}
コード例 #2
0
ファイル: ROneOrMore.cs プロジェクト: ArsenShnurkov/csharpcc
		public override Nfa GenerateNfa(bool ignoreCase) {
			Nfa retVal = new Nfa();
			NfaState startState = retVal.Start;
			NfaState finalState = retVal.End;

			Nfa temp = RegularExpression.GenerateNfa(ignoreCase);

			startState.AddMove(temp.Start);
			temp.End.AddMove(temp.Start);
			temp.End.AddMove(finalState);

			return retVal;
		}
コード例 #3
0
ファイル: RChoice.cs プロジェクト: ArsenShnurkov/csharpcc
        public override Nfa GenerateNfa(bool ignoreCase)
        {
            CompressCharLists();

            if (choices.Count == 1)
                return choices[0].GenerateNfa(ignoreCase);

            Nfa retVal = new Nfa();
            NfaState startState = retVal.Start;
            NfaState finalState = retVal.End;

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

                temp = curRE.GenerateNfa(ignoreCase);

                startState.AddMove(temp.Start);
                temp.End.AddMove(finalState);
            }

            return retVal;
        }
コード例 #4
0
        public override Nfa GenerateNfa(bool ignoreCase)
        {
            if (!transformed) {
                if (Options.getIgnoreCase() || ignoreCase) {

                    ToCaseNeutral();
                    SortDescriptors();
                }

                if (Negated)
                    RemoveNegation(); // This also sorts the list
                else
                    SortDescriptors();
            }

            if (descriptors.Count == 0 && !Negated) {
                CSharpCCErrors.SemanticError(this, "Empty character set is not allowed as it will not match any character.");
                return new Nfa();
            }

            transformed = true;
            Nfa retVal = new Nfa();
            NfaState startState = retVal.Start;
            NfaState finalState = retVal.End;
            int i;

            for (i = 0; i < descriptors.Count; i++) {
                if (descriptors[i] is SingleCharacter)
                    startState.AddChar(((SingleCharacter) descriptors[i]).Character);
                else // if (descriptors.get(i) instanceof CharacterRange)
                {
                    CharacterRange cr = (CharacterRange) descriptors[i];

                    if (cr.Left == cr.Right)
                        startState.AddChar(cr.Left);
                    else
                        startState.AddRange(cr.Left, cr.Right);
                }
            }

            startState.next = finalState;

            return retVal;
        }