示例#1
0
        private void addProgram()
        {
            IStmt st1 = new AssignStmt("v", new ConstExp(10));
            IStmt st2 = new NewStmt("a", new ConstExp(22));
            IStmt st3 = new AssignStmt("v", new ConstExp(32));
            IStmt st4 = new PrintStmt(new VarExp("v"));
            IStmt st5 = new PrintStmt(new ReadHeapExp("a"));
            IStmt st8 = new ForkStmt(new CmpStmt(new WriteHeapStmt("a", new ConstExp(30)),
                                                 new CmpStmt(st3, new CmpStmt(st4, st5))));
            IStmt st6     = new PrintStmt(new VarExp("v"));
            IStmt st7     = new PrintStmt(new ReadHeapExp("a"));
            IStmt prgStmt = new CmpStmt(st1, new CmpStmt(st2,
                                                         new CmpStmt(st8, new CmpStmt(st6, st7))));
            //IStmt prgStmt = addNewStmt();
            IStack <IStmt>            exeStk = new ArrayStack <IStmt>();
            IDictionary <String, int> tbl    = new ArrayDictionary <String, int>();
            IList <int> outl = new ArrayList <int>();
            IHeap <int> h    = new MyHeap <int>();

            exeStk.Push(prgStmt);

            PrgState crtPrg = new PrgState(exeStk, tbl, outl, h);

            ctrl.addPrgState(crtPrg);
            ctrl.repoSer();

            try {
                mainMenu();
            } catch (ControllerException) {
                Console.WriteLine("Step evaluation error.");
            } catch (RepositoryException) {
                Console.WriteLine("Program state error.");
            } catch (ConsoleException) {
                Console.WriteLine("Wrong option. Try again.");
            }
        }
示例#2
0
        private void addProgram()
        {
            IStmt st1 = new AssignStmt("v", new ConstExp(10));
            IStmt st2 = new NewStmt("a", new ConstExp(22));
            IStmt st3 = new AssignStmt("v", new ConstExp(32));
            IStmt st4 = new PrintStmt(new VarExp("v"));
            IStmt st5 = new PrintStmt(new ReadHeapExp("a"));
            IStmt st8 = new ForkStmt(new CmpStmt(new WriteHeapStmt("a", new ConstExp(30)),
                new CmpStmt(st3, new CmpStmt(st4, st5))));
            IStmt st6 = new PrintStmt(new VarExp("v"));
            IStmt st7 = new PrintStmt(new ReadHeapExp("a"));
            IStmt prgStmt = new CmpStmt(st1, new CmpStmt(st2,
                new CmpStmt(st8, new CmpStmt(st6, st7))));
            //IStmt prgStmt = addNewStmt();
            IStack<IStmt> exeStk = new ArrayStack<IStmt>();
            IDictionary<String, int> tbl = new ArrayDictionary<String, int>();
            IList<int> outl = new ArrayList<int>();
            IHeap<int> h = new MyHeap<int>();
            exeStk.Push(prgStmt);

            PrgState crtPrg = new PrgState(exeStk, tbl, outl, h);
            ctrl.addPrgState(crtPrg);
            ctrl.repoSer ();

            try {
                mainMenu();
            } catch (ControllerException) {
                Console.WriteLine("Step evaluation error.");
            } catch (RepositoryException) {
                Console.WriteLine("Program state error.");
            } catch (ConsoleException) {
                Console.WriteLine("Wrong option. Try again.");
            }
        }