public ProgState execute(ProgState prog)
        {
            MyIDictionary <string, int> dict = prog.getDict();

            try
            {
                if (dict.isDefined(this.id) == 1)
                {
                    dict.update(id, exp.eval(dict));
                }
                else
                {
                    dict.add(id, exp.eval(dict));
                }
                return(prog);
            }
            catch (StmtExceptions e)
            {
                throw new ControllerException(e);
            }
            catch (DivizionByZeroException e)
            {
                throw new ControllerException(e);
            }
        }
        public ProgState execute(ProgState prog)
        {
            MyIDictionary <string, int> dict = prog.getDict();
            MyIFileTable <Tuple>        Tpl  = prog.getFile();

            try
            {
                if (Tpl.isEmpty() == 1)
                {
                    for (int i = 1; i <= Tpl.getKey(); i++)
                    {
                        Tuple tpl = Tpl.get(i);
                        if (tpl != null && tpl.getName() == filename)
                        {
                            throw new ControllerException("The file does not exist!! \n");
                        }
                    }
                }
                StreamReader st  = new StreamReader(filename);
                Tuple        tup = new Tuple(filename, st);
                Tpl.add(tup);
                dict.add(varName, Tpl.getKey());
                return(prog);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
            }
            catch (DictExceptions e)
            { throw new ControllerException(e.ToString()); }
            return(null);
        }
        public ProgState execute(ProgState prog)
        {
            MyIDictionary <string, int> dict = prog.getDict();
            MyIFileTable <Tuple>        Tpl  = prog.getFile();

            try
            {
                int   val = exp.eval(dict);
                Tuple tpl = Tpl.get(val);
                if (tpl != null)
                {
                    tpl.getST().Close();
                    Tpl.remove(val);
                }
                else
                {
                    throw new ControllerException("The file does not exist!! \n");
                }
            }
            catch (StmtExceptions e)
            { throw new ControllerException(e); }
            catch (IOException e)
            { Console.WriteLine(e.ToString()); }
            return(prog);
        }
        public ProgState execute(ProgState prog)
        {
            MyIStack <IStmt> stk = prog.getStk();

            stk.push(st2);
            stk.push(st1);
            return(prog);
        }
        public ProgState execute(ProgState prog)
        {
            MyIList <int> list = prog.getList();
            MyIDictionary <string, int> dict = prog.getDict();

            try {
                list.add(ex.eval(dict));
                return(prog);
            }
            catch (StmtExceptions e)
            {
                throw new ControllerException(e);
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            MyIDictionary <string, int> dict = new MyDictionary <string, int>();
            MyIList <int>        list        = new MyList <int>();
            MyIStack <IStmt>     stk         = new MyStack <IStmt>();
            MyIFileTable <Tuple> file        = new MyFileTable <Tuple>();
            IStmt st = new CompStmt(new AssignStmt("v", new ConstExp(2)), new CompStmt(
                                        new AssignStmt("v", new ConstExp(4)), new CompStmt(new AssignStmt("a", new ConstExp(40)), new PrintStmt(new VarExp("v")))));
            ProgState   prog = new ProgState(stk, dict, list, file, st);
            IRepository repo = null;

            try
            {
                repo = new Repository(prog, "D:\\Faculta\\OOP projects\\LabCsharp\\LabCsharp\\state1.txt");
            }
            catch (IOException e) { Console.WriteLine(e.ToString()); }
            Controller cont = new Controller(repo, 1);
            //cont.allSteps();

            MyIDictionary <string, int> dict2 = new MyDictionary <string, int>();
            MyIList <int>        list2        = new MyList <int>();
            MyIStack <IStmt>     stk2         = new MyStack <IStmt>();
            MyIFileTable <Tuple> file2        = new MyFileTable <Tuple>();
            IStmt st2 = new CompStmt(new OpenFile("f", "D:\\Faculta\\OOP projects\\LabCsharp\\LabCsharp\\Log1.txt"),
                                     new CompStmt(new ReadFile(new VarExp("f"), "g"),
                                                  new CompStmt(new PrintStmt(new VarExp("g")), new CloseFile(new VarExp("f")))));

            ProgState   state2 = new ProgState(stk2, dict2, list2, file2, st2);
            IRepository repo2  = null;

            try
            {
                repo2 = new Repository(state2, "D:\\Faculta\\OOP projects\\LabCsharp\\LabCsharp\\state2.txt");
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
            }
            Controller cont2 = new Controller(repo2, 1);

            TextMENU text = new TextMENU();

            text.add(new ExitCommand("0", "EXIT"));
            text.add(new RunCommand("1", st.ToString(), cont));
            text.add(new RunCommand("2", st2.ToString(), cont2));
            text.show();

            Console.ReadLine();
        }
Example #7
0
        public ProgState onestep(ProgState prog)
        {
            MyIStack <IStmt> stk = prog.getStk();

            try { stk.isEmpty(); }
            catch (StackExceptions) { throw new StmtExecException("The program is over!!! \n"); }

            IStmt st = stk.pop();

            if (flag == 1)
            {
                System.Console.WriteLine(st.ToString());
            }

            try { return(st.execute(prog)); }
            catch (ControllerException e) { throw new StmtExecException(e); }
        }
Example #8
0
        public void allSteps()
        {
            ProgState prg = repo.getProg();

            try
            {
                while (true)
                {
                    onestep(prg);
                    repo.PrintlogFile();
                }
            }
            catch (StmtExecException e)
            {
                Console.WriteLine(e.ToString());
            }
            finally { repo.CloseFile(); }
        }
        public ProgState execute(ProgState prog)
        {
            MyIStack <IStmt>            stk  = prog.getStk();
            MyIDictionary <string, int> dict = prog.getDict();

            try {
                if (ex.eval(dict) > 0)
                {
                    stk.push(thenS);
                }
                else
                {
                    stk.push(elseS);
                }
            } catch (StmtExceptions e) {
                throw new ControllerException(e);
            }
            return(prog);
        }
        public ProgState execute(ProgState prog)
        {
            MyIDictionary <string, int> dict = prog.getDict();
            MyIFileTable <Tuple>        tpl  = prog.getFile();

            try
            {
                int   val = exp.eval(dict);
                Tuple tup = tpl.get(val);

                if (tup != null)
                {
                    string st = tup.getST().ReadLine();
                    if (st != null)
                    {
                        if (dict.isDefined(name) == 0)
                        {
                            dict.add(name, int.Parse(st));
                        }
                        else
                        {
                            dict.update(name, int.Parse(st));
                        }
                    }
                }
                else
                {
                    throw new ControllerException("The file does not exist !!! \n");
                }
            }
            catch (StmtExceptions e)
            {
                throw new ControllerException(e);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
            }

            return(prog);
        }
 public Repository(ProgState prog, string filename)
 {
     progs    = new ProgState[1];
     progs[0] = prog;
     log      = new StreamWriter(filename);
 }