コード例 #1
0
ファイル: Program.cs プロジェクト: joshuaRMS/Formele-methode
        /// <summary>
        /// Creates multiple example regexp.
        /// </summary>
        public static void CreateExampleRegExp()
        {
            // regex : (aa)*(aa)+
            string        regex1      = "(aa)*(aa)+";
            RegExpression expression1 = new RegExpression(regex1);

            Console.WriteLine($"Language (aa)*(aa)+ \n" +
                              $"Language via toString method = {expression1.ToString()}\n");

            // regex : a* (aa+ | ba*b ) * (abba | baab | bbbb)+
            string        regex2      = "a* (aa+ | ba*b ) * (abba | baab | bbbb)+";
            RegExpression expression2 = new RegExpression(regex2);

            Console.WriteLine("Language a* (aa+ | ba*b ) * (abba | baab | bbbb)+ \n" +
                              $"Language via toString method = {expression2.ToString()}\n" +
                              $"Word asdasdsd \n\n");

            // regex : (a*b*)+ (bb*b | ab*baa)+
            string        regex3      = "(a*b*)+ (bb*b | ab*baa)+";
            RegExpression expression3 = new RegExpression(regex3);

            Console.WriteLine("Language (a*b*)+ (bb*b | ab*baa)+ \n" +
                              $"Language via toString method = {expression3.ToString()}\n" +
                              $"Word asdadsad \n\n");
        }
コード例 #2
0
        /// <summary>
        /// Easier visualisation of the regexpression as string
        /// </summary>
        public override string ToString()
        {
            string regexString = "";

            if (terminals != "")
            {
                regexString = terminals;
            }
            else
            {
                if (right != null)
                {
                    regexString += "(";
                }
                regexString += left.ToString();
                switch (o)
                {
                case Operator.PLUS:
                    regexString += '+';
                    break;

                case Operator.STAR:
                    regexString += '*';
                    break;

                case Operator.OR:
                    regexString += '|';
                    break;
                }
                if (right != null)
                {
                    regexString += right.ToString();
                    regexString += ')';
                }
            }
            return(regexString);
        }