Beispiel #1
0
        private IStmt addNewStmt()
        {
            Console.WriteLine("Choose a type of statement:");
            Console.WriteLine("1. Compound statement");
            Console.WriteLine("2. Assignment statement");
            Console.WriteLine("3. If/then/else statement");
            Console.WriteLine("4. Print statement");
            Console.WriteLine("5. While statement");
            Console.WriteLine("6. Skip statement");
            Console.WriteLine("7. If/then statement");
            Console.WriteLine("8. Switch statement");
            Console.WriteLine("9. New statement");
            Console.WriteLine("10. Write to heap statement");


            int opt = Convert.ToInt32(Console.ReadLine());

            IStmt st;

            switch (opt)
            {
            case 1:
                Console.WriteLine("First statement:");
                IStmt st1 = addNewStmt();
                Console.WriteLine("Second statement:");
                IStmt st2 = addNewStmt();
                st = new CmpStmt(st1, st2);
                break;

            case 2:
                Console.WriteLine("Variable name:");
                String varName = Console.ReadLine();
                Console.WriteLine("Right side expression:");
                Exp exp = addNewExp();
                st = new AssignStmt(varName, exp);
                break;

            case 3:
                Console.WriteLine("Expression to evaluate:");
                Exp expr = addNewExp();
                Console.WriteLine("Then Statement:");
                IStmt then = addNewStmt();
                Console.WriteLine("Else Statement:");
                IStmt el = addNewStmt();
                st = new IfStmt(expr, then, el);
                break;

            case 4:
                Exp e = addNewExp();
                st = new PrintStmt(e);
                break;

            case 5:
                Console.WriteLine("Expression to evaluate:");
                Exp expression = addNewExp();
                Console.WriteLine("Statement:");
                IStmt statement = addNewStmt();
                st = new WhileStmt(expression, statement);
                break;

            case 6:
                st = new SkipStmt();
                break;

            case 7:
                Console.WriteLine("Expression to evaluate:");
                Exp exp1 = addNewExp();
                Console.WriteLine("Then Statement:");
                IStmt then1 = addNewStmt();
                st = new IfThenStmt(exp1, then1);
                break;

            case 8:
                Console.WriteLine("Switch operator:");
                String variableName = Console.ReadLine();
                expr = new VarExp(variableName);

                Console.WriteLine("Case 1 expression:");
                Exp expCase1 = addNewExp();
                Console.WriteLine("Case 1 Statement:");
                IStmt case1 = addNewStmt();

                Console.WriteLine("Case 2 expression:");
                Exp expCase2 = addNewExp();
                Console.WriteLine("Case 2 Statement:");
                IStmt case2 = addNewStmt();

                Console.WriteLine("Default case Statement:");
                IStmt caseDefault = addNewStmt();

                st = new SwitchStmt(expr, expCase1, case1, expCase2, case2, caseDefault);
                break;

            case 9:
                Console.WriteLine("Variable name:");
                String newVar = Console.ReadLine();
                Console.WriteLine("Assigned expression:");
                Exp exp9 = addNewExp();
                st = new NewStmt(newVar, exp9);
                break;

            case 10:
                Console.WriteLine("Variable name:");
                String heapVar = Console.ReadLine();
                Console.WriteLine("Assigned expression:");
                Exp exp10 = addNewExp();
                st = new WriteHeapStmt(heapVar, exp10);
                break;

            default:
                Console.WriteLine("Please try one of the options above.");
                st = addNewStmt();
                break;
            }

            return(st);
        }
Beispiel #2
0
        private IStmt addNewStmt()
        {
            Console.WriteLine("Choose a type of statement:");
            Console.WriteLine("1. Compound statement");
            Console.WriteLine("2. Assignment statement");
            Console.WriteLine("3. If/then/else statement");
            Console.WriteLine("4. Print statement");
            Console.WriteLine("5. While statement");
            Console.WriteLine("6. Skip statement");
            Console.WriteLine("7. If/then statement");
            Console.WriteLine("8. Switch statement");
            Console.WriteLine("9. New statement");
            Console.WriteLine("10. Write to heap statement");

            int opt = Convert.ToInt32(Console.ReadLine());

            IStmt st;
            switch (opt) {
            case 1:
                Console.WriteLine("First statement:");
                IStmt st1 = addNewStmt();
                Console.WriteLine("Second statement:");
                IStmt st2 = addNewStmt();
                st = new CmpStmt(st1, st2);
                break;
            case 2:
                Console.WriteLine("Variable name:");
                String varName = Console.ReadLine();
                Console.WriteLine("Right side expression:");
                Exp exp = addNewExp();
                st = new AssignStmt(varName, exp);
                break;
            case 3:
                Console.WriteLine("Expression to evaluate:");
                Exp expr = addNewExp();
                Console.WriteLine("Then Statement:");
                IStmt then = addNewStmt();
                Console.WriteLine("Else Statement:");
                IStmt el = addNewStmt();
                st = new IfStmt(expr, then, el);
                break;
            case 4:
                Exp e = addNewExp();
                st = new PrintStmt(e);
                break;
            case 5:
                Console.WriteLine("Expression to evaluate:");
                Exp expression = addNewExp();
                Console.WriteLine("Statement:");
                IStmt statement = addNewStmt();
                st = new WhileStmt(expression, statement);
                break;
            case 6:
                st = new SkipStmt();
                break;
            case 7:
                Console.WriteLine("Expression to evaluate:");
                Exp exp1 = addNewExp();
                Console.WriteLine("Then Statement:");
                IStmt then1 = addNewStmt();
                st = new IfThenStmt(exp1, then1);
                break;
            case 8:
                Console.WriteLine("Switch operator:");
                String variableName = Console.ReadLine();
                expr = new VarExp(variableName);

                Console.WriteLine("Case 1 expression:");
                Exp expCase1 = addNewExp();
                Console.WriteLine("Case 1 Statement:");
                IStmt case1 = addNewStmt();

                Console.WriteLine("Case 2 expression:");
                Exp expCase2 = addNewExp();
                Console.WriteLine("Case 2 Statement:");
                IStmt case2 = addNewStmt();

                Console.WriteLine("Default case Statement:");
                IStmt caseDefault = addNewStmt();

                st = new SwitchStmt(expr, expCase1, case1, expCase2, case2, caseDefault);
                break;
            case 9:
                Console.WriteLine("Variable name:");
                String newVar = Console.ReadLine();
                Console.WriteLine("Assigned expression:");
                Exp exp9 = addNewExp();
                st = new NewStmt(newVar, exp9);
                break;
            case 10:
                Console.WriteLine("Variable name:");
                String heapVar = Console.ReadLine();
                Console.WriteLine("Assigned expression:");
                Exp exp10 = addNewExp();
                st = new WriteHeapStmt(heapVar, exp10);
                break;
            default:
                Console.WriteLine ("Please try one of the options above.");
                st = addNewStmt ();
                break;

            }

            return st;
        }