Esempio n. 1
0
        private static PrgState prg2()
        {
            /*
             * a=2-2;
             * If a Then
             *  v=2
             * Else
             *  v=3;
             * Print(v)
             */
            Statement ex2 = new CompStmt(
                new AssignStmt("a",
                               new ArithmeticExpr('-',
                                                  new ConstExpr(2),
                                                  new ConstExpr(2))),
                new CompStmt(
                    new IfStmt(
                        new VarExpr("a"),
                        new AssignStmt("v",
                                       new ConstExpr(2)),
                        new AssignStmt("v",
                                       new ConstExpr(3))),
                    new PrintStmt(
                        new VarExpr("v"))));
            IExeStack <Statement>      stack = new ExeStack <Statement>();
            IDictionaryy <string, int> dict  = new Dictionaryy <string, int>();
            IListt <int> l = new outputList <int>();
            FileTable <int, FileData> ft = new FileTable <int, FileData>();

            stack.PushS(ex2);
            PrgState state = new PrgState(dict, stack, l, ex2, ft);

            return(state);
        }
Esempio n. 2
0
        private static PrgState prg4()
        {
            //open(a,"a.txt")
            //open(b,"b.txt")
            //open(c,"c.txt")
            //open(d,"d.txt")

            Statement ex4 = new CompStmt(
                new CompStmt(
                    new OpenFile("a", "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\a.txt"),
                    new OpenFile("b", "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\b.txt")
                    ),
                new CompStmt(
                    new OpenFile("c", "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\c.txt"),
                    new OpenFile("d", "E:\\Programe\\Visual Studio\\Programe\\MAP_Lab7\\d.txt")
                    )
                );
            IExeStack <Statement>      stack = new ExeStack <Statement>();
            IDictionaryy <string, int> dict  = new Dictionaryy <string, int>();
            IListt <int> l = new outputList <int>();
            FileTable <int, FileData> ft = new FileTable <int, FileData>();

            stack.PushS(ex4);
            PrgState state = new PrgState(dict, stack, l, ex4, ft);

            return(state);
        }
Esempio n. 3
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. 4
0
        private static PrgState prg3()
        {
            //a = 2 + 3 * 5
            //b = a + 1
            //Print(b)
            Statement ex3 = new CompStmt(
                new CompStmt(new AssignStmt("a",
                                            new ArithmeticExpr('+',
                                                               new ConstExpr(2),
                                                               new ArithmeticExpr('*',
                                                                                  new ConstExpr(3),
                                                                                  new ConstExpr(5)
                                                                                  ))),
                             new AssignStmt("b",
                                            new ArithmeticExpr('+',
                                                               new VarExpr("a"),
                                                               new ConstExpr(1)))),
                new PrintStmt(new VarExpr("b")));
            IExeStack <Statement>      stack = new ExeStack <Statement>();
            IDictionaryy <string, int> dict  = new Dictionaryy <string, int>();
            IListt <int> l = new outputList <int>();
            FileTable <int, FileData> ft = new FileTable <int, FileData>();

            stack.PushS(ex3);
            PrgState state = new PrgState(dict, stack, l, ex3, ft);

            return(state);
        }
        public static void Main(string[] args)
        {
            IExeStack <IStatement> stack = new ExeStack <IStatement>();

            Utils.IDictionary <string, int> dict = new MyDictionary <string, int>();
            IMyList <int>             output     = new MyList <int>();
            FileTable <int, FileData> fileTable  = new FileTable <int, FileData>();

            IStatement s1     = new OpenRFile("var_f", "C:\\Users\\Emy\\RiderProjects\\lab7\\text1.txt");
            IStatement s2     = new ReadFile(new VarExp("var_f"), "var_c");
            IStatement thenS1 = new ReadFile(new VarExp("var_f"), "var_c");
            IStatement thenS2 = new PrintStmt(new VarExp("var_c"));
            IStatement thenS  = new CompStmt(thenS1, thenS2);
            IStatement elseS  = new PrintStmt(new ConstExp(0));

            IStatement s3 = new IfStmt(new VarExp("var_c"), thenS, elseS);
            IStatement s4 = new CloseRFile(new VarExp("var_f"));

            IStatement s5 = new CompStmt(s1, s2);
            IStatement s6 = new CompStmt(s3, s4);
            IStatement s7 = new CompStmt(s5, s6);

            stack.push(s7);

            PrgState state = new PrgState(dict, stack, output, fileTable);

            Controller.Controller ctrl = new Controller.Controller(state);


            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExample("1", "example_1", ctrl));
            menu.show();
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //EX 1:
            //v=2;Print(v)
            IStmt ex1 = new CompStmt(new AssignStmt("v", new ConstExp(2)), new PrintStmt(new
                                                                                         VarExp("v")));

            Controller ctrl1 = createController(ex1);
            IStmt      ex2   = new CompStmt(new AssignStmt("a",
                                                           new ArithExp("+", new ConstExp(2),
                                                                        new ArithExp("*", new ConstExp(3), new ConstExp(5)))),
                                            new CompStmt(new AssignStmt("b", new ArithExp("+", new VarExp("a"), new
                                                                                          ConstExp(1))), new PrintStmt(new VarExp("b"))));
            Controller ctrl2 = createController(ex2);

            IStmt ex3 = new CompStmt(new AssignStmt("a", new ArithExp("-", new ConstExp(2), new
                                                                      ConstExp(2))),
                                     new CompStmt(new IfStmt(new VarExp("a"), new AssignStmt("v", new ConstExp(2)), new
                                                             AssignStmt("v", new ConstExp(3))), new PrintStmt(new VarExp("v"))));
            Controller ctrl3 = createController(ex3);

            /*openRFile(var_f,"test.in");
             * readFile(var_f,var_c);print(var_c);
             * (if var_c then readFile(var_f,var_c);print(var_c)
             * else print(0));
             * closeRFile(var_f)*/
            IStmt ex4 = new CompStmt(
                new OpenRFileStmt("var_f", "/Users/adrianflorea/Codes/MAP/A7/input.in"),
                new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                                                                             new PrintStmt(new ConstExp(0))), new CloseRFileStmt(new VarExp("var_f"))))));
            Controller ctrl4 = createController(ex4);

            /*
             * openRFile(var_f,"test.in");
             * readFile(var_f+2,var_c);print(var_c);
             * (if var_c then readFile(var_f,var_c);print(var_c)
             * else print(0));
             * closeRFile(var_f)*/
            IStmt ex5 = new CompStmt(
                new OpenRFileStmt("var_f", "/Users/adrianflorea/Codes/MAP/A7/input.in"),
                new CompStmt(new ReadFileStmt(new VarExp("var_f+2"), "var_c"), new CompStmt(
                                 new PrintStmt(new VarExp("var_c")), new CompStmt(new IfStmt(new VarExp("var_c"),
                                                                                             new CompStmt(new ReadFileStmt(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                                                                             new PrintStmt(new ConstExp(0))), new CloseRFileStmt(new VarExp("var_f"))))));
            Controller ctrl5 = createController(ex5);
            TextMenu   menu  = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExampleCommand("1", ex1.ToString(), ctrl1));
            menu.addCommand(new RunExampleCommand("2", ex2.ToString(), ctrl2));
            menu.addCommand(new RunExampleCommand("3", ex3.ToString(), ctrl3));
            menu.addCommand(new RunExampleCommand("4", ex4.ToString(), ctrl4));
            menu.addCommand(new RunExampleCommand("5", ex5.ToString(), ctrl5));
            menu.show();
        }
Esempio n. 7
0
        private void ExecuteCommand(int command)
        {
            IExeStack <IStmt>            exeStack = new ExeStack <IStmt>();
            IModList <int>               outList  = new ModList <int>();
            IModDictionary <string, int> dict     = new ModDictionary <string, int>();
            IStmt stmt = default(IStmt);
            IFileTable <int, FileData> fileTable = new FileTable <int, FileData>();

            switch (command)
            {
            case 1:
                stmt = new CompStmt(
                    new AssingStmt("v", new ConstExp(2)),
                    new PrintStmt(new VarExp("v")));
                break;

            case 2:
                break;

            case 3:
                break;

            case 4:
                stmt = new CompStmt(
                    new OpenRFile("var_f", @"E:\GitRepoCollege\MAP\C# - Toy language\Lab10\Toy Language\Toy Language\test.in"),
                    new CompStmt(
                        new ReadRFile(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 ReadRFile(new VarExp("var_f"), "var_c"),
                                        new PrintStmt(new VarExp("var_c"))),
                                    new PrintStmt(new ConstExp(0))),
                                new CloseRFile(new VarExp("var_f"))))));
                break;

            default:
                // throw some error
                throw new Exception("Invalid command");
            }

            PrgState prgState = new PrgState(exeStack, dict, outList, fileTable, stmt);

            ctrl.AddPrgState(prgState);
            try
            {
                ctrl.AllStep();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 8
0
        private static PrgState prg1()
        {
            //a=5;
            //if (a-5) then
            //    print(1);
            //else
            //    print(2);
            //print((5+7)a);

            Statement ex1 = new CompStmt(
                new AssignStmt("a", new ConstExpr(5)),
                new CompStmt(
                    new IfStmt(
                        new ArithmeticExpr(
                            '-',
                            new VarExpr("a"),
                            new ConstExpr(5)
                            ),
                        new PrintStmt(new ConstExpr(1)),
                        new PrintStmt(new ConstExpr(2))
                        ),
                    new PrintStmt(
                        new ArithmeticExpr(
                            '*',
                            new ArithmeticExpr(
                                '+',
                                new ConstExpr(5),
                                new ConstExpr(7)
                                ),
                            new VarExpr("a")
                            )
                        )
                    )
                );
            IExeStack <Statement>      stack = new ExeStack <Statement>();
            IDictionaryy <string, int> dict  = new Dictionaryy <string, int>();
            IListt <int> l = new outputList <int>();
            FileTable <int, FileData> ft = new FileTable <int, FileData>();

            stack.PushS(ex1);
            PrgState state = new PrgState(dict, stack, l, ex1, ft);

            return(state);
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            testing();
            IRepo       repo = new Repository();
            IController ctrl = new Controller(repo);
            //IStmt stmt = new CompStmt(new AssignStmt("v",new ConstExpr(10)), new CompStmt(
            //    new NewHeapStmt("v", new ConstExpr(20)), new CompStmt(new NewHeapStmt("a",
            //        new ConstExpr(20)), new CompStmt(new WriteHeapStmt("a",new ConstExpr(30)), new CompStmt(new PrintStmt(new VarExpr("a")),
            //            //new PrintStmt(new ReadHeapExpr("a")))))));
            //         IStmt stmt = new CompStmt(new AssignStmt("a", new ArithExpr(new ConstExpr(2), "*",
            //            new ConstExpr(3))), new PrintStmt(new ConstExpr(33)));
            //IStmt stmt = new CompStmt(new AssignStmt("a",new ConstExpr(1)), new CompStmt(new AssignStmt("v", new read()), new CompStmt(new SwitchStmt(new ConstExpr(1),
            //    new ConstExpr(0), new VarExpr("v"), new IfThenStmt(new LogicExpr(new VarExpr("v"),"&&", new VarExpr("a")),new AssignStmt("v",new ConstExpr(5)
            //    )), new AssignStmt("v", new LogicExpr(new VarExpr("v"),"||", new ConstExpr(1))), new AssignStmt("v", new ConstExpr(100))), new WhileStmt(new
            //    VarExpr("v"), new CompStmt(new AssignStmt("a",new ArithExpr(new VarExpr("a"),"+",new ConstExpr(1))), new AssignStmt("v", new ArithExpr(new
            //    VarExpr("v"),"-", new ConstExpr(1))))))));

            //        stmt = new AssignStmt("a", new ArithExpr(new ConstExpr(2), "/", new ConstExpr(0)));
            //       stmt = new AssignStmt("a", new ArithExpr(new ConstExpr(3), "i", new ConstExpr(2)));
            IStmt stmt = new CompStmt(new AssignStmt("v", new ConstExpr(10)), new CompStmt(new NewHeapStmt("a", new ConstExpr(22)),
                                                                                           new CompStmt(new ForkStmt(new CompStmt(new WriteHeapStmt("a", new ConstExpr(30)), new CompStmt(new AssignStmt(
                                                                                                                                                                                              "v", new ConstExpr(32)), new CompStmt(new PrintStmt(new VarExpr("v")), new PrintStmt(new ReadHeapExpr("a"))))))
                                                                                                        , new CompStmt(new PrintStmt(new VarExpr("v")), new PrintStmt(new ReadHeapExpr("a"))))));

            //ctrl.Add(stmt);
            //ctrl.SetFileName("WTFFF.txt");
            //ctrl.SetToFile();
            ctrl.Deserialize("D:/Projects/C#/console6/sert.txt");
            //ctrl.AllStep();
            //ctrl.SetFileName("D:/Projects/C#/console6/test.txt");
            //ctrl.SetToFile();
            //ctrl.AllStep(1);

            //Console.WriteLine("----------------");
            //ctrl.Serialize("D:/Projects/C#/console6/seri.txt");
            //ctrl.Deserialize("D:/Projects/C#/console6/seri.txt");
            //ProgState p2 = ctrl.GetProg();
            //Console.WriteLine(p2);
            //Console.WriteLine("----------------");
            View ui = new View(ctrl);

            ui.UiprintAll();
        }
Esempio n. 10
0
 public void FinalizeStatement()
 {
     Statement = new CompStmt(First.Statement, Second.Statement);
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            string logFile  = @"logFile.txt"; //Hardcoded logFile
            string testFile = @"test.txt";    //Hardcoded testFile

            //EXAMPLE 1
            IStmt ex1 = new CompStmt(new AssignStmt("v", new ConstExp(2)), new PrintStmt(new
                                                                                         VarExp("v")));
            PrgState    prg1  = new PrgState(ex1);
            IRepository repo1 = new Repository(logFile);
            Controller  ctrl1 = new Controller(repo1);

            ctrl1.addPrgCtrl(prg1);

            //EXAMPLE 2
            IStmt ex2 = new CompStmt(new AssignStmt("a", new ArithExp('+', new ConstExp(2), new
                                                                      ArithExp('/', new ConstExp(3), new ConstExp(0)))),
                                     new CompStmt(new AssignStmt("b", new ArithExp('+', new VarExp("a"), new
                                                                                   ConstExp(1))), new PrintStmt(new VarExp("b"))));
            PrgState    prg2  = new PrgState(ex2);
            IRepository repo2 = new Repository(logFile);
            Controller  ctrl2 = new Controller(repo2);

            ctrl2.addPrgCtrl(prg2);

            //EXAMPLE 3
            IStmt ex3 = new CompStmt(new AssignStmt("a", new ArithExp('-', new ConstExp(2), new
                                                                      ConstExp(2))),
                                     new CompStmt(new IfStmt(new VarExp("a"), new AssignStmt("v", new ConstExp(2)), new
                                                             AssignStmt("v", new ConstExp(3))), new PrintStmt(new VarExp("v"))));
            PrgState    prg3  = new PrgState(ex3);
            IRepository repo3 = new Repository(logFile);
            Controller  ctrl3 = new Controller(repo3);

            ctrl3.addPrgCtrl(prg3);
            //EXAMPLE 4
            IStmt ex4 = new CompStmt(new openRFile("var", testFile),
                                     new CompStmt(new readFile(new VarExp("var"), "c"),
                                                  new CompStmt(new PrintStmt(new VarExp("c")),
                                                               new CompStmt(new IfStmt(new VarExp("c"),
                                                                                       new CompStmt(new readFile(new VarExp("var"), "c"), new PrintStmt(new VarExp("c"))),
                                                                                       new PrintStmt(new ConstExp(0))), new closeRFile(new VarExp("var"))))));
            PrgState    prg4  = new PrgState(ex4);
            IRepository repo4 = new Repository(logFile);
            Controller  ctrl4 = new Controller(repo4);

            ctrl4.addPrgCtrl(prg4);

            //EXAMPLE 5
            IStmt ex5 = new CompStmt(new openRFile("var", testFile),
                                     new CompStmt(new readFile(new ArithExp('+', new VarExp("var"), new ConstExp(2)), "c"),
                                                  new CompStmt(new PrintStmt(new VarExp("c")),
                                                               new CompStmt(new IfStmt(new VarExp("c"),
                                                                                       new CompStmt(new readFile(new VarExp("var"), "c"), new PrintStmt(new VarExp("c"))),
                                                                                       new PrintStmt(new ConstExp(0))), new closeRFile(new VarExp("var"))))));
            PrgState    prg5  = new PrgState(ex5);
            IRepository repo5 = new Repository(logFile);
            Controller  ctrl5 = new Controller(repo5);

            ctrl5.addPrgCtrl(prg5);


            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "Exit"));
            menu.addCommand(new RunExample("1", ex1.ToString(), ctrl1));
            menu.addCommand(new RunExample("2", ex2.ToString(), ctrl2));
            menu.addCommand(new RunExample("3", ex3.ToString(), ctrl3));
            menu.addCommand(new RunExample("4", ex4.ToString(), ctrl4));
            menu.addCommand(new RunExample("5", ex5.ToString(), ctrl5));
            menu.show();


            Console.ReadKey();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            IStack <IStmt> ExeStack4 = new MyStack <IStmt>();

            Interpreter.Model.Utilities.IDictionary <string, int> SymTable4 = new MyDictionary <string, int>();
            IList <int> out4 = new MyList <int>();

            Model.Utilities.IDictionary <int, StreamReader> fileTable4 = new MyDictionary <int, StreamReader>();
            IStmt expr4 = new CompStmt(
                new OpenRFileStmt("var_f", "C:\\Users\\pechd\\source\\repos\\Interpreter\\Interpreter\\Example.txt"), new CompStmt(
                    new ReadFileStmt(new VarExpr("var_f"), "var_c"), new CompStmt(
                        new PrintStmt(new VarExpr("var_c")), new CompStmt(
                            new IfStmt(new VarExpr("var_c")
                                       , new CompStmt(new ReadFileStmt(new VarExpr("var_f"), "var_c"), new PrintStmt(new VarExpr("var_c"))), new PrintStmt(new ConstExpr(0))),
                            new CloseRFileStmt(new VarExpr("var_f"))))));

            ExeStack4.add(expr4);
            ProgramState  prgCurrent4 = new ProgramState(ExeStack4, SymTable4, out4, fileTable4);
            myRepositorix repo4       = new PrgRepo(prgCurrent4);

            Controller.MyController ctrl4 = new Controller.MyController(repo4);
            //IRepo repo4 = new Repository.Repository();
            //repo4.addPrg(prgCurrent4);
            //Controller.Controller ctrl4 = new Controller.Controller(repo4);

            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExample("1", expr4.ToString(), ctrl4));
            menu.show();

            //IExeStack<Statement> exeStack = new Stack<Statement>();
            //Model.ADT.IDictionary<string, int> symbolTable = new DictionaryC<string, int>();
            //IOutput<int> messages = new Output<int>();
            //IFileTable<int, FileData> fd = new FileTable<int, FileData>();

            //Statement s = new CompoundStatement(new AssignStatement("v", new ConstantExpression(2)), new PrintStatement(new VariableExpression("v")));
            //exeStack.Push(s);
            //PrgState state = new PrgState(symbolTable, exeStack, messages, fd);
            //IPrgRepository repo = new PrgRepository(state);
            //Controller.Controller ctrl = new Controller.Controller(repo);

            //IExeStack<Statement> exeStack1 = new Stack<Statement>();
            //Model.ADT.IDictionary<string, int> symbolTable1 = new DictionaryC<string, int>();
            //IOutput<int> messages1 = new Output<int>();
            //IFileTable<int, FileData> fd1 = new FileTable<int, FileData>();

            //Statement s1 = new CompoundStatement(
            //               new CompoundStatement(
            //                       new CompoundStatement(
            //                               new OpenFileStatement("var_f", "C:\\Users\\pechd\\source\\repos\\Lab7\\Lab7\\Example.txt"),

            //                               new ReadFileStatement(new VariableExpression("var_f"), "var_c")
            //                       ),
            //                       new CompoundStatement(
            //                               new PrintStatement(new VariableExpression("var_c")),
            //                               new IfStatement(
            //                                       new VariableExpression("var_c"),
            //                                       new PrintStatement(new ConstantExpression(0))
            //                                      , new CompoundStatement(
            //                                               new ReadFileStatement(new VariableExpression("var_f"), "var_c"),
            //                                               new PrintStatement(new VariableExpression("var_c")))))), new CloseFileStatement(new VariableExpression("var_f")));

            //exeStack1.Push(s1);
            //PrgState state1 = new PrgState(symbolTable1, exeStack1, messages1, fd1);
            //IPrgRepository repo1 = new PrgRepository(state1);
            //Controller.Controller ctrl1 = new Controller.Controller(repo1);

            //TextMenu menu = new TextMenu();
            //menu.addCommand(new ExitCommand("0", "exit"));
            //menu.addCommand(new RunExample("1", s.ToString(), ctrl));
            //menu.addCommand(new RunExample("2", s1.ToString(), ctrl1));
            //menu.show();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            IStmt       ex1   = new CompStmt(new AssignStmt("v", new ConstExp(2)), new PrintStmt(new VarExp("v")));;
            PrgState    prg1  = createPrg(ex1);
            IRepository rep1  = new Repository(prg1, "log1.txt");
            Controller  ctrl1 = new Controller(rep1);

            IStmt       ex2   = new CompStmt(new CompStmt(new AssignStmt("a", new ArithExp('+', new ConstExp(2), new ConstExp(1))), new AssignStmt("b", new ArithExp('/', new VarExp("a"), new ConstExp(0)))), new PrintStmt(new VarExp("b")));
            PrgState    prg2  = createPrg(ex2);
            IRepository rep2  = new Repository(prg2, "log2.txt");
            Controller  ctrl2 = new Controller(rep2);

            IStmt       ex3   = new CompStmt(new AssignStmt("a", new ArithExp('-', new ConstExp(2), new ConstExp(2))), new CompStmt(new IfStmt(new VarExp("a"), new AssignStmt("v", new ConstExp(2)), new AssignStmt("v", new ConstExp(3))), new PrintStmt(new VarExp("v"))));
            PrgState    prg3  = createPrg(ex3);
            IRepository rep3  = new Repository(prg3, "log3.txt");
            Controller  ctrl3 = new Controller(rep3);

            /*openRFile(var_f,"test.in");
             * readFile(var_f,var_c);print(var_c);
             * (if var_c then readFile(var_f,var_c);print(var_c)
             * else print(0));
             * closeRFile(var_f)*/
            IStmt ex4 = new CompStmt(new OpenFileStmt("var_f", "test.in"), new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                                                                                                                                                 new PrintStmt(new ConstExp(0))), new CloseFileStmt(new VarExp("var_f"))))));
            PrgState    prg4  = createPrg(ex4);
            IRepository rep4  = new Repository(prg4, "log4.txt");
            Controller  ctrl4 = new Controller(rep4);

            /*
             * compst:
             *  openRFile(var_f,"test.in");
             *  compst
             *      readFile(var_f,var_c);
             *      compst
             *          print(var_c);
             *          compstmt
             *              (if var_c then
             *                  compst
             *                      readFile(var_f,var_c);
             *                      print(var_c)
             *              else print(0));
             * closeRFile(var_f)
             * closeRFile(var_f)*/

            IStmt ex5 = new CompStmt(new OpenFileStmt("var_f", "test.in"), new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                                                                                                                                                 new PrintStmt(new ConstExp(0))), new CompStmt(new CloseFileStmt(new VarExp("var_f")), new CloseFileStmt(new VarExp("var_f")))))));
            PrgState    prg5  = createPrg(ex5);
            IRepository rep5  = new Repository(prg5, "log5.txt");
            Controller  ctrl5 = new Controller(rep5);

            /*
             * compst:
             *  compst
             *      openRFile(var_f,"test.in");
             *      openRFile(var_f,"test.in");
             *  compst
             *      readFile(var_f,var_c);
             *      compst
             *          print(var_c);
             *          compstmt
             *              (if var_c then
             *                  compst
             *                      readFile(var_f,var_c);
             *                      print(var_c)
             *              else print(0));
             *  closeRFile(var_f)*/

            IStmt ex6 = new CompStmt(new CompStmt(new OpenFileStmt("var_f", "test.in"), new OpenFileStmt("var_f", "test.in")), new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))),
                                                                                                                                                                                                                     new PrintStmt(new ConstExp(0))), new CompStmt(new CloseFileStmt(new VarExp("var_f")), new CloseFileStmt(new VarExp("var_f")))))));
            PrgState    prg6  = createPrg(ex6);
            IRepository rep6  = new Repository(prg6, "log6.txt");
            Controller  ctrl6 = new Controller(rep6);

            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExample("1", ex1.ToString(), ctrl1));
            menu.addCommand(new RunExample("2", ex2.ToString(), ctrl2));
            menu.addCommand(new RunExample("3", ex3.ToString(), ctrl3));
            menu.addCommand(new RunExample("4", ex4.ToString(), ctrl4));
            menu.addCommand(new RunExample("5", ex5.ToString(), ctrl5));
            menu.addCommand(new RunExample("6", ex6.ToString(), ctrl6));
            menu.show();
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            /*
             *   Lab2Ex1:
             *   v = 2;
             *   print (v)
             *
             * */
            IStmt lab2ex1 = new CompStmt(new AssignStmt("v", new ConstExp(2)), new PrintStmt(new
                                                                                             VarExp("v")));

            /*
             *   Lab2Ex2:
             *   a = 2 + 3 * 5;
             *   b = a + 1;
             *   print (b)
             *
             * */
            IStmt lab2ex2 = new CompStmt(new AssignStmt("a", new ArithExp(ArithExp.Operation.ADD, new ConstExp(2), new
                                                                          ArithExp(ArithExp.Operation.MULTIPLY, new ConstExp(3), new ConstExp(5)))),
                                         new CompStmt(new AssignStmt("b", new ArithExp(ArithExp.Operation.ADD, new VarExp("a"), new
                                                                                       ConstExp(1))), new PrintStmt(new VarExp("b"))));

            /*
             *   Lab2Ex3:
             *   a = 2 - 2;
             *   If a then v = 2 else v = 3;
             *   print (v)
             *
             * */
            IStmt lab2ex3 = new CompStmt(new AssignStmt("a", new ArithExp(ArithExp.Operation.SUBTRACT, new ConstExp(2), new
                                                                          ConstExp(2))),
                                         new CompStmt(new IfStmt(new VarExp("a"), new AssignStmt("v", new ConstExp(2)), new
                                                                 AssignStmt("v", new ConstExp(3))), new PrintStmt(new VarExp("v"))));


            /*
             *   Lab5Ex1
             *   openRFile (var_f, "test.in");
             *   readFile (var_f, var_c); print (var_c);
             *   If var_c then readFile (var_f, var_c); print (var_c) else print (0);
             *   closeRFile (var_f)
             *
             * */
            IStmt lab5ex1 = new CompStmt(
                new OpenRFileStmt("var_f", "test.in"),
                new CompStmt(
                    new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"),
                                    new PrintStmt(new VarExp("var_c"))
                                    ),
                                new PrintStmt(new ConstExp(0))
                                ),
                            new CloseRFileStmt(new VarExp("var_f"))
                            )
                        )
                    )
                );

            /*
             *   Lab5Ex2
             *   openRFile (var_f, "test.in");
             *   readFile (var_f + 2, var_c); print (var_c);
             *   If var_c then readFile (var_f, var_c); print (var_c) else print (0);
             *   closeRFile (var_f)
             * */
            IStmt lab5ex2 = new CompStmt(
                new OpenRFileStmt("var_f", "test.in"),
                new CompStmt(
                    new ReadFileStmt(new ArithExp(ArithExp.Operation.ADD, new VarExp("var_f"), new ConstExp(2)), "var_c"),
                    new CompStmt(
                        new PrintStmt(new VarExp("var_c")),
                        new CompStmt(
                            new IfStmt(
                                new VarExp("var_c"),
                                new CompStmt(
                                    new ReadFileStmt(new VarExp("var_f"), "var_c"),
                                    new PrintStmt(new VarExp("var_c"))
                                    ),
                                new PrintStmt(new ConstExp(0))
                                ),
                            new CloseRFileStmt(new VarExp("var_f"))
                            )
                        )
                    )
                );
            TextMenu menu = new TextMenu(new MyDictionary <string, Command>(new Dictionary <string, Command>()));

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExample("1", lab2ex1.ToString(), createController(lab2ex1, "log1.txt")));
            menu.addCommand(new RunExample("2", lab2ex2.ToString(), createController(lab2ex2, "log2.txt")));
            menu.addCommand(new RunExample("3", lab2ex3.ToString(), createController(lab2ex3, "log3.txt")));
            menu.addCommand(new RunExample("4", lab5ex1.ToString(), createController(lab5ex1, "log4.txt")));
            menu.addCommand(new RunExample("5", lab5ex2.ToString(), createController(lab5ex2, "log5.txt")));

            menu.show();
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            Statement statement = new CompStmt(
                new AssignStmt("v", new ConstExpr(2)),
                new PrintStmt(new VarExpr("v")));

            Statement st2 = new CompStmt(
                new AssignStmt(
                    "a",
                    new ArithExpr('+',
                                  new ConstExpr(2),
                                  new ArithExpr('*',
                                                new ConstExpr(3),
                                                new ConstExpr(5)
                                                )
                                  )),
                new CompStmt(
                    new AssignStmt(
                        "b",
                        new ArithExpr('+',
                                      new VarExpr("a"),
                                      new ConstExpr(1)
                                      )),
                    new PrintStmt(new VarExpr("b"))));

            Statement st3 = new CompStmt(
                new AssignStmt("v", new ArithExpr('/',
                                                  new VarExpr("2"),
                                                  new ConstExpr(0)
                                                  )),
                new PrintStmt(new VarExpr("v")));

            Statement st4 = new CompStmt(
                new OpenFileStmt("var_f", "test.in"),
                new CompStmt(
                    new ReadFileStmt(new VarExpr("var_f"), "var_c"),
                    new CompStmt(
                        new PrintStmt(new VarExpr("var_c")),
                        new CompStmt(
                            new IfStmt(
                                new VarExpr("var_c"),
                                new CompStmt(
                                    new ReadFileStmt(new VarExpr("var_f"), "var_c"),
                                    new PrintStmt(new VarExpr("var_c"))
                                    ),
                                new PrintStmt(new ConstExpr(0))
                                ),
                            new CloseFileStmt(new VarExpr("var_f")))
                        )
                    )
                );

            ProgState   prg8  = new ProgState(new SymbolTable <String, int>(), new ExeStack <Statement>(), new Output <int>(), new FileTable <int, FileData>(), statement);
            IRepository repo8 = new Repository(prg8, "file88.txt");
            Controller  ctr8  = new Controller(repo8);

            ProgState   prg2  = new ProgState(new SymbolTable <String, int>(), new ExeStack <Statement>(), new Output <int>(), new FileTable <int, FileData>(), st2);
            IRepository repo2 = new Repository(prg2, "file1.txt");
            Controller  ctr2  = new Controller(repo2);

            ProgState   prg3  = new ProgState(new SymbolTable <String, int>(), new ExeStack <Statement>(), new Output <int>(), new FileTable <int, FileData>(), st3);
            IRepository repo3 = new Repository(prg3, "file2.txt");
            Controller  ctr3  = new Controller(repo3);

            ProgState   prg4  = new ProgState(new SymbolTable <String, int>(), new ExeStack <Statement>(), new Output <int>(), new FileTable <int, FileData>(), st4);
            IRepository repo4 = new Repository(prg4, "file3.txt");
            Controller  ctr4  = new Controller(repo4);

            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new AllStepCommand("10", statement.toString(), ctr8));
            menu.addCommand(new AllStepCommand("2", st2.toString(), ctr2));
            menu.addCommand(new AllStepCommand("3", st3.toString(), ctr3));
            menu.addCommand(new AllStepCommand("4", st4.toString(), ctr4));
            menu.show();
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            // Example 1
            Statement stmt1 = new CompStmt(
                new OpenFileStmt("1stFile.txt", "1stFile"),
                new CompStmt(new PrintStmt(new ArithmeticExpr('-', new ConstExpr(10), new ConstExpr(5))),
                             new CompStmt(new AssignStmt(new ConstExpr(11), "b"),
                                          new CompStmt(new IfStmt(new ConstExpr(0),
                                                                  new PrintStmt(new ConstExpr(1)),
                                                                  new PrintStmt(new ConstExpr(2))),
                                                       new AssignStmt(new ConstExpr(10), "x")))));
            PrgState prg1 = new PrgState(stmt1,
                                         new ExeStack <Statement>(),
                                         new SymbolTable <string, int>(),
                                         new FileTable <int, FileStream>(),
                                         new Output <int>());
            IRepository repo1 = new Repository("logFile.txt", prg1);
            Controller  ctrl1 = new Controller(repo1);

            // Example 2
            Statement stmt2 = new AssignStmt(new ArithmeticExpr('/', new ConstExpr(3), new ConstExpr(0)), "var");
            PrgState  prg2  = new PrgState(stmt2,
                                           new ExeStack <Statement>(),
                                           new SymbolTable <string, int>(),
                                           new FileTable <int, FileStream>(),
                                           new Output <int>());
            IRepository repo2 = new Repository("logFile.txt", prg2);
            Controller  ctrl2 = new Controller(repo2);

            // Example 3
            Statement stmt3 = new CompStmt(
                new OpenFileStmt("2ndFile.txt", "2ndFile"),
                new CompStmt(new ReadFileStmt("2ndFile.txt", "h1"),
                             new CompStmt(new ReadFileStmt("2ndFile.txt", "h2"), new CloseFileStmt("2ndFile.txt"))));
            PrgState prg3 = new PrgState(stmt3,
                                         new ExeStack <Statement>(),
                                         new SymbolTable <string, int>(),
                                         new FileTable <int, FileStream>(),
                                         new Output <int>());
            IRepository repo3 = new Repository("logFile.txt", prg3);
            Controller  ctrl3 = new Controller(repo3);

            // Example 4
            Statement stmt4 = new CompStmt(
                new OpenFileStmt("2ndFile.txt", "2ndFile"),
                new CompStmt(new CompStmt(new ReadFileStmt("2ndFile.txt", "h1"),
                                          new CompStmt(new ReadFileStmt("2ndFile.txt", "h2"), new CloseFileStmt("2ndFile.txt"))),
                             new CompStmt(new OpenFileStmt("1stFile.txt", "1stFile"),
                                          new CompStmt(new ReadFileStmt("1stFile.txt", "h"), new CloseFileStmt("1stFile.txt")))));
            PrgState prg4 = new PrgState(stmt4,
                                         new ExeStack <Statement>(),
                                         new SymbolTable <string, int>(),
                                         new FileTable <int, FileStream>(),
                                         new Output <int>());
            IRepository repo4 = new Repository("logFile.txt", prg4);
            Controller  ctrl4 = new Controller(repo4);

            // MENU
            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "exit"));
            menu.addCommand(new RunExample("1", stmt1.ToString(), ctrl1));
            menu.addCommand(new RunExample("2", stmt2.ToString(), ctrl2));
            menu.addCommand(new RunExample("3", stmt3.ToString(), ctrl3));
            menu.addCommand(new RunExample("4", stmt4.ToString(), ctrl4));
            menu.show();
        }
        static void Main(string[] args)
        {
            IStmt ex1 = new CompStmt(new AssignStmt("a", new ArithExp(new ConstExp(1), new ConstExp(2), "+")),
                                     new IfStmt(new VarExp("a"), new PrintStmt(new VarExp("a")), new AssignStmt("b", new ConstExp(3))));
            PrgState prg1 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex1);
            IRepository repo1 = new Repository("D:\\VSProjects\\Interpreter\\log1.txt");

            repo1.AddProgram(prg1);
            Controller ctr1 = new Controller(repo1);

            IStmt    ex2  = new PrintStmt(new VarExp("a"));
            PrgState prg2 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex2);
            IRepository repo2 = new Repository("D:\\VSProjects\\Interpreter\\log2.txt");

            repo2.AddProgram(prg2);
            Controller ctr2 = new Controller(repo2);

            IStmt    ex3  = new PrintStmt(new ArithExp(new ConstExp(1), new ConstExp(0), "/"));
            PrgState prg3 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex3);
            IRepository repo3 = new Repository("D:\\VSProjects\\Interpreter\\log3.txt");

            repo3.AddProgram(prg3);
            Controller ctr3 = new Controller(repo3);

            IStmt ex4 = new CompStmt(new OpenRFileStmt("var_f", "D:\\VSProjects\\Interpreter\\file1.txt"),
                                     new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"),
                                                                                                                                                                                 new PrintStmt(new VarExp("var_c"))), new PrintStmt(new ConstExp(0))),
                                                                                                                                                         new CloseRFileStmt(new VarExp("var_f"))))));
            PrgState prg4 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex4);
            IRepository repo4 = new Repository("D:\\VSProjects\\Interpreter\\log4.txt");

            repo4.AddProgram(prg4);
            Controller ctr4 = new Controller(repo4);

            IStmt ex5 = new CompStmt(new OpenRFileStmt("var_f", "D:\\VSProjects\\Interpreter\\file2.txt"),
                                     new CompStmt(new ReadFileStmt(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 ReadFileStmt(new VarExp("var_f"), "var_c"),
                                                                                                                                                                                 new PrintStmt(new VarExp("var_c"))), new PrintStmt(new ConstExp(0))),
                                                                                                                                                         new CloseRFileStmt(new VarExp("var_f"))))));
            PrgState prg5 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex5);
            IRepository repo5 = new Repository("D:\\VSProjects\\Interpreter\\log5.txt");

            repo5.AddProgram(prg5);
            Controller ctr5 = new Controller(repo5);

            IStmt ex6 = new CompStmt(new OpenRFileStmt("var_f", "D:\\VSProjects\\Interpreter\\file1.txt"),
                                     new OpenRFileStmt("var_f", "D:\\VSProjects\\Interpreter\\file1.txt"));
            PrgState prg6 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex6);
            IRepository repo6 = new Repository("D:\\VSProjects\\Interpreter\\log6.txt");

            repo6.AddProgram(prg6);
            Controller ctr6 = new Controller(repo6);

            IStmt    ex7  = new OpenRFileStmt("var_f", "D:\\VSProjects\\Interpreter\\file0.txt");
            PrgState prg7 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex7);
            IRepository repo7 = new Repository("D:\\VSProjects\\Interpreter\\log7.txt");

            repo7.AddProgram(prg7);
            Controller ctr7 = new Controller(repo7);

            IStmt    ex8  = new ReadFileStmt(new ConstExp(1), "var_c");
            PrgState prg8 = new PrgState(new MyStack <IStmt>(), new MyDictionary <string, int>(), new MyList <int>(),
                                         new MyMap <ITuple <string, StreamReader> >(), ex8);
            IRepository repo8 = new Repository("D:\\VSProjects\\Interpreter\\log8.txt");

            repo8.AddProgram(prg8);
            Controller ctr8 = new Controller(repo8);



            TextMenu menu = new TextMenu();

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunExample("1", ex1.ToString(), ctr1));
            menu.AddCommand(new RunExample("2", ex2.ToString(), ctr2));
            menu.AddCommand(new RunExample("3", ex3.ToString(), ctr3));
            menu.AddCommand(new RunExample("4", ex4.ToString(), ctr4));
            menu.AddCommand(new RunExample("5", ex5.ToString(), ctr5));
            menu.AddCommand(new RunExample("6", ex6.ToString(), ctr6));
            menu.AddCommand(new RunExample("7", ex7.ToString(), ctr7));
            menu.AddCommand(new RunExample("8", ex8.ToString(), ctr8));
            menu.Show();
        }
Esempio n. 18
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();
        }