Esempio n. 1
0
        static void Main(string[] args)
        {
            TextMenu textMenu = new TextMenu();

            textMenu.AddCommand(new ExitCommand("0", "Exit"));

            // first example: v=2;Print(v)
            Command ex1 = GetRunCommand("1",
                                        "Basic statements example",
                                        new AssignmentStatement("v", new ConstantExpression(2)),
                                        new PrintStatement(new VariableExpression("v")));

            Command ex2 = GetRunCommand(
                "2",
                "Example of working with files",
                new OpenFileStatement("var_f", "input.txt"),
                new ReadFileStatement(new VariableExpression("var_f"), "var_c"),
                new PrintStatement(new VariableExpression("var_c")),
                new IfStatement(new VariableExpression("var_c"),
                                new CompoundStatement(new ReadFileStatement(new VariableExpression("var_f"), "var_c"),
                                                      new PrintStatement(new VariableExpression("var_c"))),
                                new PrintStatement(new ConstantExpression(0))),
                new CloseFileStatement(new VariableExpression("var_f"))
                );

            textMenu.AddCommand(ex1);
            textMenu.AddCommand(ex2);
            textMenu.Show();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            IStmt stmt1 = new CompStmt(new CompStmt(
                                           new OpenRFile("varf", "read.txt"),
                                           new ReadFile(new VarExp("varf"), "varc")
                                           ),
                                       new CompStmt(
                                           new PrintStmt(new VarExp("varc")),
                                           new CloseRFile("varf")
                                           )

                                       );
            IMyStack <IStmt>            exec    = new MyStack <IStmt>();
            IMyDictionary <String, int> symbolT = new MyDictionary <String, int>();
            IMyList <int> msg = new MyList <int>();
            IMyFileTable <int, FileData> filet = new MyFileTable <int, FileData>();
            PrgState prg1 = new PrgState(exec, symbolT, msg, filet, stmt1);

            IRepository repo1 = new Repository("log1.txt");
            Controller  ctr1  = new Controller(repo1);

            repo1.AddPrgState(prg1);
            TextMenu menu = new TextMenu();

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunExample("1", stmt1.ToString(), ctr1));
            menu.Show();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            TextMenu menu = new TextMenu();

            menu.AddCommand(new ExitCommand("0", "Exit"));
            menu.AddCommand(GetExample(Example1(), "1", "v = 2; Print(v)"));
            menu.AddCommand(GetExample(Example2(), "2", "a = 2 + 3 * 5; b = a - 4 / 2 + 7; Print(b)"));
            menu.AddCommand(GetExample(Example3(), "3", "a = 2 - 2; If a Then v = 2 Else v = 3; Print(v)"));
            menu.AddCommand(GetExample(Example4(), "4", "Files example 1"));
            menu.AddCommand(GetExample(Example5(), "5", "Double open example"));
            menu.AddCommand(GetExample(Example6(), "6", "Open inexistent file example"));

            menu.Show();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            IPrgStateRepo repository1 = new ProgStateRepo(prg1(), "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\prg1.txt");
            Controller    controller1 = new Controller(repository1);
            IPrgStateRepo repository2 = new ProgStateRepo(prg2(), "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\prg2.txt");
            Controller    controller2 = new Controller(repository2);
            IPrgStateRepo repository3 = new ProgStateRepo(prg3(), "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\prg3.txt");
            Controller    controller3 = new Controller(repository3);
            IPrgStateRepo repository4 = new ProgStateRepo(prg4(), "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\prg4.txt");
            Controller    controller4 = new Controller(repository4);
            TextMenu      menu        = new TextMenu();

            menu.AddCommand(new ExitCommand("0", ". Exit"));
            menu.AddCommand(new RunCommand("1", ". " + prg1().Stmt.ToString(), controller1));
            menu.AddCommand(new RunCommand("2", ". " + prg2().Stmt.ToString(), controller2));
            menu.AddCommand(new RunCommand("3", ". " + prg3().Stmt.ToString(), controller3));
            menu.AddCommand(new RunCommand("4", ". " + prg4().Stmt.ToString(), controller4));
            menu.Show();
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            IMyStack <IStatement>     stack1     = new MyStack <IStatement>();
            IMyDict <string, int>     dict1      = new MyDict <string, int>();
            IMyList <int>             output1    = new MyList <int>();
            FileTable <int, FileData> fileTable1 = new FileTable <int, FileData>();

            IStatement i1 = new OpenRFile("var_f", "../../../intrare.txt");
            IStatement i2 = new ReadFile(new VarExpression("var_f"), "var_c");
            IStatement i3 = new ReadFile(new VarExpression("var_f"), "var_c");
            IStatement i4 = new PrintStatement(new VarExpression("var_c"));
            IStatement i5 = new CompStatement(i3, i4);
            IStatement i6 = new PrintStatement(new ConstExpression(0));

            IStatement i7 = new IfStatement(new VarExpression("var_c"), i5, i6);
            IStatement i8 = new CloseRFile(new VarExpression("var_f"));

            IStatement i9  = new CompStatement(i1, i2);
            IStatement i10 = new CompStatement(i7, i8);
            IStatement i11 = new CompStatement(i9, i10);

            stack1.Push(i11);

            PrgState    state1 = new PrgState(dict1, stack1, output1, fileTable1);
            IRepository repo1  = new Repository.Repository();

            repo1.AddProg(state1);
            Controller.Controller ctrl1 = new Controller.Controller(repo1);

            /*Exemplu 111111111111111111111111111111111111111111111*/


            IMyStack <IStatement>     stack2     = new MyStack <IStatement>();
            IMyDict <string, int>     dict2      = new MyDict <string, int>();
            IMyList <int>             output2    = new MyList <int>();
            FileTable <int, FileData> fileTable2 = new FileTable <int, FileData>();

            IStatement j1 = new OpenRFile("a", "../../../intrare.txt");
            IStatement j2 = new CompStatement(new ReadFile(new VarExpression("a"), "p"), new PrintStatement(new VarExpression("p")));
            IStatement j3 = new IfStatement(new VarExpression("p"), new CompStatement(new ReadFile(new VarExpression("a"), "q"),
                                                                                      new PrintStatement(new VarExpression("q"))), new PrintStatement(new ConstExpression(0)));

            IStatement j4 = new CloseRFile(new VarExpression("a"));
            IStatement j5 = new CompStatement(j2, new CompStatement(j3, j4));
            IStatement j6 = new CompStatement(j1, j5);

            stack2.Push(j6);

            PrgState    state2 = new PrgState(dict2, stack2, output2, fileTable2);
            IRepository repo2  = new Repository.Repository();

            repo2.AddProg(state2);
            Controller.Controller ctrl2 = new Controller.Controller(repo2);
            /*Exemplu 222222222222222222222222222222222222222222222*/
            TextMenu menu = new TextMenu();

            menu.AddCommand(new ExitCommand("0", "exit \n"));
            menu.AddCommand(new RunCommand("1", "\t" + i11.ToString() + "\n", ctrl1));
            menu.AddCommand(new RunCommand("2", "\t" + j6.ToString() + "\n", ctrl2));
            menu.Show();
        }
        static void Main(string[] args)
        {
            IStatement ex1 = new CompoundStatement(
                new AssignmentStatement(
                    "v",
                    new Model.Expressions.ConstantExpression(2)
                    ),
                new PrintStatement(
                    new VariableExpression("v")
                    )
                );

            IRepository repo1 = new Repositoryx();
            Controllerx ctrl1 = new Controllerx(repo1);

            ctrl1.Load(new ProgramState(new ExecutionStack(ex1), new SymbolTable(), new Output(), new FileTable(), ex1));

            IStatement ex2 = new CompoundStatement(
                new AssignmentStatement(
                    "a",
                    new ArithmeticExpression(
                        new Model.Expressions.ConstantExpression(2),
                        "*",
                        new ArithmeticExpression(
                            new Model.Expressions.ConstantExpression(3),
                            "*",
                            new Model.Expressions.ConstantExpression(5)
                            )
                        )
                    ),
                new CompoundStatement(
                    new AssignmentStatement(
                        "b",
                        new ArithmeticExpression(
                            new VariableExpression("a"),
                            "+",
                            new Model.Expressions.ConstantExpression(1)
                            )
                        ),
                    new PrintStatement(
                        new VariableExpression("b")
                        )
                    )
                );

            IRepository repo2 = new Repositoryx();
            Controllerx ctrl2 = new Controllerx(repo2);

            ctrl2.Load(new ProgramState(new ExecutionStack(ex2), new SymbolTable(), new Output(), new FileTable(), ex2));

            IStatement ex3 = new CompoundStatement(
                new OpenRFile(
                    "var_f",
                    "test.in"
                    ),
                new CompoundStatement(
                    new ReadFile(
                        new VariableExpression("var_f"),
                        "var_c"
                        ),
                    new CompoundStatement(
                        new PrintStatement(
                            new VariableExpression("var_c")
                            ),
                        new CompoundStatement(
                            new IfStatement(
                                new VariableExpression("var_c"),
                                new CompoundStatement(
                                    new ReadFile(
                                        new VariableExpression("var_f"),
                                        "var_c"
                                        ),
                                    new PrintStatement(
                                        new VariableExpression("var_c")
                                        )
                                    ),
                                new PrintStatement(
                                    new Model.Expressions.ConstantExpression(0)
                                    )
                                ),
                            new CloseRFile(
                                new VariableExpression("var_f")
                                )
                            )
                        )
                    )
                );

            IRepository repo3 = new Repositoryx();
            Controllerx ctrl3 = new Controllerx(repo3);

            ctrl3.Load(new ProgramState(new ExecutionStack(ex3), new SymbolTable(), new Output(), new FileTable(), ex3));

            IStatement ex4 = new CompoundStatement(
                new OpenRFile(
                    "var_f",
                    "test.in"
                    ),
                new CompoundStatement(
                    new ReadFile(
                        new ArithmeticExpression(
                            new VariableExpression("var_f"),
                            "+",
                            new Model.Expressions.ConstantExpression(2)
                            ),
                        "var_c"
                        ),
                    new CompoundStatement(
                        new PrintStatement(
                            new VariableExpression("var_c")
                            ),
                        new CompoundStatement(
                            new IfStatement(
                                new VariableExpression("var_c"),
                                new CompoundStatement(
                                    new ReadFile(
                                        new VariableExpression("var_f"),
                                        "var_c"
                                        ),
                                    new PrintStatement(
                                        new VariableExpression("var_c")
                                        )
                                    ),
                                new PrintStatement(
                                    new Model.Expressions.ConstantExpression(0)
                                    )
                                ),
                            new CloseRFile(
                                new VariableExpression("var_f")
                                )
                            )
                        )
                    )
                );

            IRepository repo4 = new Repositoryx();
            Controllerx ctrl4 = new Controllerx(repo4);

            ctrl4.Load(new ProgramState(new ExecutionStack(ex4), new SymbolTable(), new Output(), new FileTable(), ex4));

            System.Console.Write("\nEnter the path to the log file: ");
            string filepath = System.Console.ReadLine();

            ctrl1.SetRepoFilepath(filepath);
            ctrl2.SetRepoFilepath(filepath);
            ctrl3.SetRepoFilepath(filepath);
            ctrl4.SetRepoFilepath(filepath);

            TextMenu menu = new TextMenu();

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunCommand("1", ex1.Tostring(), ctrl1));
            menu.AddCommand(new RunCommand("2", ex2.Tostring(), ctrl2));
            menu.AddCommand(new RunCommand("3", ex3.Tostring(), ctrl3));
            menu.AddCommand(new RunCommand("4", ex4.Tostring(), ctrl4));
            menu.Show();

            //C:\Users\Catalin\source\repos\MapA7\MapA7\log.txt
        }