Esempio n. 1
0
        public static string EXPRESSION(bool ForceToBeValid)
        {
            string Result = string.Empty;

            if (!ForceToBeValid)
            {
                return(EXPRESSION());
            }
            else
            {
                while (true)
                {
                    string Expr = EXPRESSION();

                    if (HighLevelScriptGen.EvaluateExpression(Expr, ref Result))
                    {
                        return(Expr);
                    }
                }
            }
        }
Esempio n. 2
0
        private static bool GenerateStatement
        (
            ACTION_TYPE Type,
            StreamWriter TestCaseWithErrorFile,
            StreamWriter TestCaseWithoutErrorFile,
            int Limit,
            UInt64 Counter
        )
        {
            string Result     = string.Empty;
            string Sentence   = string.Empty;
            string Script     = string.Empty;
            bool   EvalResult = false;

            StatementGenerator.ResetDepth();


            switch (Type)
            {
            case ACTION_TYPE.CREATE_EXPRESSIONS:

                Sentence = StatementGenerator.EXPRESSION();

                //
                // Avoid big statements!
                //
                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = "x = " + Sentence + "; test_statement(x);";
                EvalResult = HighLevelScriptGen.EvaluateExpression(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_CONDITIONAL_STATEMENTS:

                Sentence = StatementGenerator.IF_STATEMENT(false);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateConditionalStatement(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_CONDITIONAL_STATEMENTS_COMBINED_WITH_OTHER_STATEMENT:

                Sentence = StatementGenerator.IF_STATEMENT(true);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateConditionalStatement(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_FOR_LOOP:

                Sentence = StatementGenerator.FOR_STATEMENT(false);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_FOR_LOOP_COMBINED_WITH_OTHER_STATEMENT:

                Sentence = StatementGenerator.FOR_STATEMENT(true);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_WHILE_LOOP:

                Sentence = StatementGenerator.WHILE_STATEMENT(false);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_WHILE_LOOP_COMBINED_WITH_OTHER_STATEMENT:

                Sentence = StatementGenerator.WHILE_STATEMENT(true);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_DO_WHILE_LOOP:

                Sentence = StatementGenerator.DO_WHILE_STATEMENT(false);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            case ACTION_TYPE.CREATE_DO_WHILE_LOOP_COMBINED_WITH_OTHER_STATEMENT:

                Sentence = StatementGenerator.DO_WHILE_STATEMENT(true);

                if (!(Sentence.Length <= Limit))
                {
                    return(false);
                }

                Script     = Sentence;
                EvalResult = HighLevelScriptGen.EvaluateLoops(Sentence, ref Result);

                break;

            default:

                //
                // Invalid value
                //
                return(false);
            }


            Console.WriteLine(Counter + "\n\n" + Script + "\n\n" + Result + "\n");
            Console.WriteLine("------------------------------------------------------------");

            if (EvalResult)
            {
                TestCaseWithoutErrorFile.WriteLine(Counter.ToString());
                TestCaseWithoutErrorFile.WriteLine(Script);
                TestCaseWithoutErrorFile.WriteLine(Result);
                TestCaseWithoutErrorFile.WriteLine("$end$");

                return(true);
            }
            else
            {
                TestCaseWithErrorFile.WriteLine(Counter.ToString());
                TestCaseWithErrorFile.WriteLine(Script);
                TestCaseWithErrorFile.WriteLine(Result);
                TestCaseWithErrorFile.WriteLine("$end$");

                return(false);
            }
        }