Beispiel #1
0
        static void Main(string[] args)
        {
            IntStatement st1 = new CompStatement(new AssignStatement("a", new ArithExpresion(1, new ConstExpresion(2), new
                                                                                             ArithExpresion(3, new ConstExpresion(3), new ConstExpresion(5)))),
                                                 new CompStatement(new AssignStatement("b", new ArithExpresion(1, new VarExpresion("a"), new
                                                                                                               ConstExpresion(1))), new PrintStatement(new VarExpresion("b"))));

            IntStatement st2 = new CompStatement(new CompStatement(new openRFile("var_f", "test.in"), new CompStatement(new readFile("var_f", "var_c"),
                                                                                                                        new PrintStatement(new VarExpresion("var_c")))),
                                                 new CompStatement(new IfStatement(new VarExpresion("var_c"),
                                                                                   new CompStatement(new readFile("var_f", "var_c"),
                                                                                                     new PrintStatement(new VarExpresion("var_c"))),
                                                                                   new PrintStatement(new ConstExpresion(0))), new CompStatement(new closeRFile("var_f"), new closeRFile("var_f"))));


            IntStatement st3 = new CompStatement(new CompStatement(new openRFile("var_f", "test.in"), new CompStatement(new readFile("var_f", "var_c"),
                                                                                                                        new PrintStatement(new VarExpresion("var_c")))),
                                                 new closeRFile("var_f"));


            System.Console.WriteLine("Log file path:");
            String        filen_name = System.Console.ReadLine();
            IntRepository rep        = new Repository.Repository(filen_name);

            Controller.Controller cont = new Controller.Controller(rep);

            cont.addPrgState(createProgState(st1));
            cont.addPrgState(createProgState(st2));
            cont.addPrgState(createProgState(st3));
            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "Exit!"));
            menu.addCommand(new AllStepsCommand("1", "Run all steps an example!", cont));
            menu.show();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Statement s = new CompStatement(new VarDeclStatement("v", new IntType()),
                                            new CompStatement(new AssignStatement("v", new ValueExpression(new IntValue(2))),
                                                              new PrintStatement(new VariableExpression("v"))));
            List <ProgramState> l = new List <ProgramState>();

            l.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s));
            RepositoryInterface r = new Repository(l);
            ControllerInterface c = new Controller(r);

            Statement           s2 = ex1();
            List <ProgramState> l1 = new List <ProgramState>();

            l1.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s2));
            RepositoryInterface r1 = new Repository(l1);
            ControllerInterface c1 = new Controller(r1);


            Statement           s3 = ex2();
            List <ProgramState> l2 = new List <ProgramState>();

            l2.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s3));
            RepositoryInterface r2 = new Repository(l2);
            ControllerInterface c2 = new Controller(r2);

            Statement           s4 = ex4();
            List <ProgramState> l4 = new List <ProgramState>();

            l4.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s4));
            RepositoryInterface r4 = new Repository(l4);
            ControllerInterface c4 = new Controller(r4);

            Statement           s5 = ex5();
            List <ProgramState> l5 = new List <ProgramState>();

            l5.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s5));
            RepositoryInterface r5 = new Repository(l5);
            ControllerInterface c5 = new Controller(r5);

            Statement           s6 = ex6();
            List <ProgramState> l6 = new List <ProgramState>();

            l6.Add(new ProgramState(new Stack <Statement>(), new ConcurrentDictionary <string, Value>(), new List <Value>(), s6));
            RepositoryInterface r6 = new Repository(l6);
            ControllerInterface c6 = new Controller(r6);

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

            menu.addCommand(new ExitCommand("x", "Exit"));
            menu.addCommand(new RunCommand("1", s.ToString(), c));
            menu.addCommand(new RunCommand("2", s2.ToString(), c1));
            menu.addCommand(new RunCommand("3", s3.ToString(), c2));
            menu.addCommand(new RunCommand("4", s4.ToString(), c4));
            menu.addCommand(new RunCommand("5", s5.ToString(), c5));
            menu.addCommand(new RunCommand("6", s6.ToString(), c6));

            menu.runTextMenu();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            IStack <IStatement>   stack      = new ExeStack <IStatement>();
            IDict <String, int>   dictionary = new SymbTable <String, int>();
            ILis <int>            outL       = new OutList <int>();
            IDict <int, FileData> fileTab    = new FileTable <int, FileData>();


            IStatement stm1 = new AssignStatement("a", new ArithmeticExpression('+', new ConstExpression(5), new ConstExpression(4)));
            IStatement stm2 = new CompStatement(new AssignStatement("a", new ArithmeticExpression('+', new ConstExpression(5), new ConstExpression(4))), new AssignStatement("b", new ArithmeticExpression('-', new ConstExpression(14), new ConstExpression(4))));


            IStatement asgnVar = new AssignStatement("x", new ArithmeticExpression('-', new ConstExpression(50), new ConstExpression(49)));
            IStatement ifstm   = new IfStatement(new VarExpression("x"), new AssignStatement("x", new ConstExpression(13)), new AssignStatement("x", new ConstExpression(10)));
            IStatement stm3    = new CompStatement(asgnVar, new CompStatement(ifstm, new PrintStatement(new VarExpression("x"))));

            IStatement stm4 = new CompStatement(new OpenRFile("file", @"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\ex1.txt"), new CompStatement(new ReadFile(new VarExpression("file"), "x"), new CloseRFile(new VarExpression("file"))));
            IStatement stm5 = new CompStatement(new OpenRFile("file", @"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\ex1.txt"), new CompStatement(new ReadFile(new VarExpression("file"), "x"), new CompStatement(new ReadFile(new VarExpression("file"), "y"), new CloseRFile(new VarExpression("file")))));



            stack.push(stm5);

            ProgramState ps   = new ProgramState(stack, dictionary, outL, fileTab, stm5);
            IRepository  repo = new Repository(@"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\OutLog.txt");

            repo.Program = ps;

            Controller ctrl = new Controller(repo);

            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit."));
            menu.addCommand(new RunExample("1", "Run Program.", ctrl));

            menu.show();


            Console.ReadKey();
        }
Beispiel #4
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();
        }