コード例 #1
0
ファイル: RCharacterList.cs プロジェクト: vsajip/csharpcc
        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);
        }