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();
        }
        static void Main(string[] args)
        {
            IStatement ex1 = new CompoundStatement(new AssignStatement("v", new ConstantExpression(2)),
                                                   new PrintStatement(new VariableExpression("v")));

            IStatement ex2 = new CompoundStatement(new AssignStatement("a", new ArithmeticExpression(new ConstantExpression(2), new
                                                                                                     ArithmeticExpression(new ConstantExpression(3), new ConstantExpression(5), Operation.MULTIPLY), Operation.ADD)),
                                                   new CompoundStatement(new AssignStatement("b", new ArithmeticExpression(new VariableExpression("a"), new
                                                                                                                           ConstantExpression(1), Operation.ADD)), new PrintStatement(new VariableExpression("b"))));

            IStatement ex3 = new CompoundStatement(new AssignStatement("a", new ArithmeticExpression(new ConstantExpression(2), new ConstantExpression(2), Operation.SUBTRACT)),
                                                   new CompoundStatement(new IfStatement(new VariableExpression("a"), new AssignStatement("v", new ConstantExpression(2)),
                                                                                         new AssignStatement("v", new ConstantExpression(3))), new PrintStatement(new VariableExpression("v"))));

            IStatement ex4 = new CompoundStatement(new OpenStatement("var_f", "test1.in"),
                                                   new CompoundStatement(new ReadStatement(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 ReadStatement(new VariableExpression("var_f"), "var_c"),
                                                                                                                                                           new PrintStatement(new VariableExpression("var_c"))), new PrintStatement(new ConstantExpression(0))),
                                                                                                                     new CloseStatement(new VariableExpression("var_f"))))));

            TextMenu menu = new TextMenu(new MyDictionary <string, Command>(new Dictionary <string, Command>()));

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunCommand("1", ex1.ToString(), CreateController(ex1, "log1.txt")));
            menu.AddCommand(new RunCommand("2", ex2.ToString(), CreateController(ex2, "log2.txt")));
            menu.AddCommand(new RunCommand("3", ex3.ToString(), CreateController(ex3, "log3.txt")));
            menu.AddCommand(new RunCommand("4", ex4.ToString(), CreateController(ex4, "log4.txt")));

            menu.show();
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            var program = new ProgramState()
            {
                ExecutionStack = GetExampleProgram2()
            };
            IRepository repository = new Repository.Repository(
                "/home/bogdanboboc97/RiderProjects/ToyLanguage/ToyLanguage/logFile.txt",
                new List <ProgramState>(new[] { program }));
            var controller = new ToyLanguageController(repository);

            var menu = new TextMenu();

            menu.AddCommand(new ExitCommand(controller));
            menu.AddCommand(new RunProgramCommand(controller));

            menu.Run();
        }
Esempio n. 5
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. 6
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. 7
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)
        {
            TextMenu textMenu = new TextMenu();

            textMenu.AddCommand(new ExitCommand());

            Statement st1 = new CompoundStatement(
                new CompoundStatement(
                    new AssignStatement("a", new ArithmeticExpression('/', new ConstantExpression(2), new ConstantExpression(0))),
                    new AssignStatement("a", new ConstantExpression(5))),
                new PrintStatement(new VariableExpression("a")));

            ProgramState state1 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st1);

            RepositoryInterface repo1 = new Repository("..\\..\\LogFile1.log");

            repo1.Add(state1);

            Controller ctrl1 = new Controller(repo1);

            textMenu.AddCommand(new RunAllSteps(ctrl1, "1", st1.ToString()));

            Statement st2 = new CompoundStatement(
                new AssignStatement("a", new ConstantExpression(2)),
                new AssignStatement("a", new ConstantExpression(7)));
            ProgramState state2 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st2);

            RepositoryInterface repo2 = new Repository("..\\..\\LogFile2.log");

            repo2.Add(state2);
            Controller ctrl2 = new Controller(repo2);

            textMenu.AddCommand(new RunAllSteps(ctrl2, "2", st2.ToString()));

            Statement st3 = new CompoundStatement(
                new CompoundStatement(
                    new CompoundStatement(
                        new CompoundStatement(
                            new OpenReadFileStatement("example.ex", "f"),
                            new ReadFileStatement("f", "c")),
                        new PrintStatement(new VariableExpression("c"))),
                    new IfStatement(new VariableExpression("c"),
                                    new CompoundStatement(
                                        new ReadFileStatement("f", "c"),
                                        new PrintStatement(new VariableExpression("c"))),
                                    new PrintStatement(new ConstantExpression(0)))),
                new CloseReadFileStatement("f"));

            ProgramState state3 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st3);

            RepositoryInterface repo3 = new Repository("..\\..\\LogFile3.log");

            repo3.Add(state3);
            Controller ctrl3 = new Controller(repo3);

            textMenu.AddCommand(new RunAllSteps(ctrl3, "3", st3.ToString()));

            textMenu.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
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            IStmt ex1 = new CompStmt(
                new OpenRFile("var_f", "file1.txt"),
                new CompStmt(
                    new ReadFile(new VarExp("var_f"), "var_c"),
                    new CompStmt(
                        new PrintStmt(new VarExp("var_c")),
                        new CompStmt(
                            new IfStmt(new VarExp("var_c"), new CompStmt(new ReadFile(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                       new PrintStmt(new ConstExp(0))),
                            new CloseRFile(new VarExp("var_f")))
                        )));


            IStmt ex2 = new CompStmt(new OpenRFile("var_f", "file1.txt"),
                                     new CompStmt(new ReadFile(new VarExp("var_f"), "var_c"),
                                                  new IfStmt(new VarExp("var_f"), new CompStmt(new ReadFile(new VarExp("var_f"), "var_c"),
                                                                                               new PrintStmt(new VarExp("var_c"))),
                                                             new PrintStmt(new ConstExp(0)))));


            IStmt ex3 = new CompStmt(
                new AssignStmt("a",
                               new ArithExp('-',
                                            new ConstExp(2),
                                            new BooleanExp(
                                                new ConstExp(2),
                                                new ConstExp(3),
                                                "<"
                                                ))),
                new CompStmt(
                    new IfStmt(
                        new BooleanExp(
                            new VarExp("a"),
                            new ConstExp(1),
                            ">"
                            ),
                        new AssignStmt("v",
                                       new ConstExp(2)),
                        new AssignStmt("v",
                                       new ConstExp(3))),
                    new PrintStmt(new VarExp("v"))));



            TextMenu menu = new TextMenu(new Dictionary <string, Command>(new Dictionary <string, Command>()));

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunCommand("1", ex1.toString(),
                                           CreateController(ex1,
                                                            "D:\\Labs\\Sem III\\MAP\\Lab9\\Lab9\\Lab9\\log.txt")));
            menu.AddCommand(new RunCommand("2", ex2.toString(),
                                           CreateController(ex2,
                                                            "D:\\Labs\\Sem III\\MAP\\Lab9\\Lab9\\Lab9\\log.txt")));
            menu.AddCommand(new RunCommand("3", ex3.toString(),
                                           CreateController(ex3,
                                                            "D:\\Labs\\Sem III\\MAP\\Lab9\\Lab9\\Lab9\\log.txt")));
//			menu.AddCommand(new RunCommand("4", ex4.ToString(),
//				CreateController(ex4,
//					"D:\\Labs\\Sem III\\MAP\\Lab9\\Lab9\\Lab9\\log.txt")));

            menu.show();
        }