예제 #1
0
 public PrgState <T> Execute <T>(PrgState <T> state)
 {
     return(null);
 }
예제 #2
0
 public PrgState Execute(PrgState state)
 {
     state.Stack.Push(second);
     state.Stack.Push(first);
     return(state);
 }
예제 #3
0
파일: Program.cs 프로젝트: pamhrituc/MAP
        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();
        }
예제 #4
0
        public void logPrgStateExec()
        {
            PrgState p = programStates[0];

            System.IO.File.AppendAllText(logFilePath, p.ToString());
        }
예제 #5
0
 public void logPrgStateExec(PrgState state)
 {
     File.WriteAllText(this.log, state.ToString());
     Console.WriteLine(state.ToString());
 }
 public Controller(PrgState state)
 {
     this.state = state;
 }
예제 #7
0
 public void addPrg(PrgState prgState)
 {
     programStates.Add(prgState);
 }
예제 #8
0
 public void AddPrgState(PrgState st)
 {
     myList.Add(st);
 }
예제 #9
0
 public PrgState Execute(PrgState state)
 {
     return(null);
 }
예제 #10
0
 public PrgRepository(PrgState p)
 {
     this.p = p;
 }
예제 #11
0
 public ProgStateRepo(PrgState state, string fn)
 {
     fileName = fn;
     myList.Add(state);
 }
예제 #12
0
        private void button6_Click(object sender, EventArgs e)
        {
            PrgState prog = repo.GetCrtPrg();

            repo.ProgStateFile(prog);
        }
예제 #13
0
 private void button5_Click(object sender, EventArgs e)
 {
     PrgState prog = repo.DeserializeProgState();
 }
예제 #14
0
        private void button4_Click(object sender, EventArgs e)
        {
            PrgState prog = repo.GetCrtPrg();

            repo.SerializeProgState(prog);
        }
예제 #15
0
 public Repository(string filename, PrgState ps)
 {
     this.repo     = new List <PrgState>();
     this.filename = filename;
     this.repo.Add(ps);
 }
예제 #16
0
 public PrgState Execute(PrgState state)
 {
     state.Output.Add(exp.Eval(state.SymTable));
     return state;
 }
예제 #17
0
 public void addPrgState(PrgState ps)
 {
     this.repo.Add(ps);
 }
예제 #18
0
 public void addPrgCtrl(PrgState prgState)
 {
     repo.addPrg(prgState);
 }