Example #1
0
        public PrgState oneStep(PrgState state)
        {
            MyIStack <IStmt> stk     = state.getStk();
            IStmt            crtStmt = stk.pop();

            return(crtStmt.execute(state));
        }
Example #2
0
        /**
         * Adds a statemtn to the repository
         * @param stmt - type IStmt, statement to be added
         */
        public void Add(IStmt stmt)
        {
            ProgState prg = new ProgState(new ArrayList <int>(), new ArrayDict <string, int>(), new ArrayStack <IStmt>(), new ArrayDict <int, int>());

            prg.GetExe.Push(stmt);
            repo.AddState(prg);
        }
        public PrgState oneStep(PrgState state)
        {
            MyIStack <IStmt> stk = state.getExeStack();

            try
            {
                if (stk.empty())
                {
                    throw new Exception("Empty stack");
                }

                IStmt    crtStmt  = stk.pop();
                PrgState newState = crtStmt.execute(state);
                if (flag == 1)
                {
                    this.displayCrtPrgState(newState);
                }
                //repo.logPrgStateExec();
                return(newState);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            IStmt stmt = null;

            ctr = new Controller <IStmt>(stmt);
            ctr.Deserialize();
        }
Example #5
0
        static Controller.Controller CreateController(IStmt stmt, string log)
        {
            IRepository repo = new Repository.Repository(log);

            Controller.Controller ctrl = new Controller.Controller(repo);
            ctrl.SetMain(new ProgramState(stmt));
            return(ctrl);
        }
Example #6
0
 public PrgState(IStmt prg)
 {
     exeStack = new MyStack <IStmt>(new Stack <IStmt>());
     exeStack.push(prg);
     symTable  = new MyDictionary <string, int>(new Dictionary <string, int>());
     outList   = new MyList <int>(new List <int>());
     fileTable = new MyDictionary <int, Tuple <string, TextReader> >(new Dictionary <int, Tuple <string, TextReader> >());
 }
Example #7
0
 public CompStmt(
     IStmt _first,
     IStmt _second
     )
 {
     first  = _first;
     second = _second;
 }
Example #8
0
        public void executeOneStep()
        {
            ProgramState p    = repo.getCurrentPrgState();
            IStmt        stmt = p.Stack.pop();

            stmt.execute(p);
            Console.WriteLine(p);
        }
Example #9
0
 public ProgramState(ExeStack <IStmt> exeStack, Output <int> output, SymTable <string, int> symTable,
                     FileTable fileTable, IStmt program)
 {
     _exeStack  = exeStack;
     _output    = output;
     _symTable  = symTable;
     _fileTable = fileTable;
     _program   = program;
 }
Example #10
0
 public PrgState(IStmt prg)
 {
     this.exeStack        = new MyStack <IStmt>();
     this.symTable        = new MyDictionary <String, int>();
     this.outTbl          = new MyList <int>();
     this.originalProgram = prg.deepCopy();
     this.fileTable       = new FileTable <int, FileTuple>();
     this.exeStack.push(prg);
 }
Example #11
0
 public PrgState oneStep()
 {
     try {
         IStmt crtStmt = exeStack.Pop();
         return(crtStmt.execute(this));
     } catch (EmptyStackException) {
         throw new MyStmtExecException();
     }
 }
Example #12
0
 public SwitchStmt(Exp exp, Exp opCase1, IStmt case1, Exp opCase2, IStmt case2, IStmt defaultCase)
 {
     this.exp = exp;
     this.expCase1 = opCase1;
     this.case1 = case1;
     this.case2 = case2;
     this.expCase2 = opCase2;
     this.defaultCase = defaultCase;
 }
Example #13
0
 public PrgState()
 {
     id              = 0;
     exeStack        = null;
     symTable        = null;
     output          = null;
     originalProgram = null;
     heap            = null;
 }
Example #14
0
 public PrgState(IMyStack <IStmt> exe, IMyDictionary <String, int> d, IMyList <int> l, IMyFileTable <int, FileData> ft, IStmt orig)
 {
     exeStack    = exe;
     symTable    = d;
     messages    = l;
     fileTable   = ft;
     originalPrg = orig;
     exeStack.Push(orig);
 }
Example #15
0
 public ProgramState(IStmt statement)
 {
     _exeStack = new ExeStack <IStmt>();
     _exeStack.Push(statement);
     _symTable  = new SymTable <string, int>();
     _output    = new Output <int>();
     _fileTable = new FileTable();
     _program   = statement;
 }
        private void button1_Click(object sender, EventArgs e)
        {
            StmtMenu m = new StmtMenu();

            m.ShowDialog();
            prg = m.GetPrg();
            this.textBox1.Text = prg.ToString();
            ctr = new Controller <IStmt>(prg);
        }
Example #17
0
        public void UiInput()
        {
            StmtMenu();
            IStmt stmt = AddStmt(GetInputString());

            Console.WriteLine("You've added to program: ");
            Console.WriteLine(stmt.ToString());
            ctrl.Add(stmt);
        }
Example #18
0
 public SwitchStmt(Expr ex1, Expr ex2, VarExpr varn, IStmt st1, IStmt st2, IStmt st3)
 {
     var  = varn;
     exp1 = ex1;
     exp2 = ex2;
     stm1 = st1;
     stm2 = st2;
     stm3 = st3;
 }
Example #19
0
 public Stmt(StmtClass kind, IStmt parent)
 {
     Class  = kind;
     Parent = parent as Stmt;
     if (Parent != null)
     {
         Parent.Stmts.Add(this);
     }
 }
Example #20
0
 public PrgState(IStmt prg)
 {
     exeStack        = new MyStack <IStmt>();
     symTable        = new MyDictionary <string, int>();
     outList         = new MyList <int>();
     fileTable       = new MyFileTable <int, Tuple <string, StreamReader> >();
     originalProgram = prg;
     exeStack.push(prg);
 }
Example #21
0
 public PrgState(IStmt initialProgram)
 {
     this.exeStack       = new Stack <IStmt>();
     this.symTable       = new Dictionary <String, int>();
     this.stdout         = new List <int>();
     this.fileTable      = new Dictionary <int, MyFile>();
     this.initialProgram = initialProgram;
     this.exeStack.Push(initialProgram);
 }
 public SwitchStmt(Exp varExp, Exp exp1, IStmt statement1, Exp exp2, IStmt statement2, IStmt statement3)
 {
     mVarExp     = varExp;
     mExp1       = exp1;
     mExp2       = exp2;
     mStatement1 = statement1;
     mStatement2 = statement2;
     mStatement3 = statement3;
 }
Example #23
0
 public SwitchStmt(Exp op, Exp opCase1, IStmt case1, Exp opCase2, IStmt case2, IStmt defaultCase)
 {
     this.op          = op;
     this.opCase1     = opCase1;
     this.case1       = case1;
     this.case2       = case2;
     this.opCase2     = opCase2;
     this.defaultCase = defaultCase;
 }
Example #24
0
 public PrgState(IStack <IStmt> stk, IDict <String, int> symtbl, IList <int> output, IDictRandIntKey <MyTuple <String, TextReader> > fileTable, IStmt stmt)
 {
     this.exeStack             = stk;
     this.symTable             = symtbl;
     this.output               = output;
     this.fileTable            = fileTable;
     this.originalProgramState = stmt;
     this.exeStack.push(stmt);
 }
Example #25
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);
            }
        }
Example #26
0
        public ProgState OneStep()
        {
            if (exeStack.IsEmpty())
            {
                throw new MyStmtException("Exception in onestep progstate \n");
            }
            IStmt stm = exeStack.Pop();

            return(stm.execute(this));
        }
Example #27
0
 public PrgState(MyIStack <IStmt> stk, MyIDictionary <string, int> symtbl,
                 MyIList <int> ot, IFileTable <int, FileTuple> fileTable, IStmt prg)
 {
     this.exeStack        = stk;
     this.symTable        = symtbl;
     this.outTbl          = ot;
     this.originalProgram = prg.deepCopy();
     this.fileTable       = fileTable;
     this.exeStack.push(prg);
 }
Example #28
0
 //optional field, but good to have
 public PrgState(StackInterface<IStmt> stack, MapInterface<String, int> dictionary, HeapInterface<int> heap, ListInterface<int> list, IStmt prg)
 {
     id = generator++;
     exeStack = stack;
     symTable = dictionary;
     heapTable = heap;
     output = list;
     originalProgram = prg;
     exeStack.Push (originalProgram);
 }
Example #29
0
        private IfThenStmt ifThenStatement()
        {
            print("Expression:");
            Exp expression = inputExpression();

            print("Then Statement:");
            IStmt thenS = inputStatement();

            return(new IfThenStmt(expression, thenS));
        }
Example #30
0
        private WhileStmt whileStatement()
        {
            print("Expression:");
            Exp expression = inputExpression();

            print("Statement:");
            IStmt statement = inputStatement();

            return(new WhileStmt(expression, statement));
        }
Example #31
0
        private CompStmt compoundStatement()
        {
            print("Left side:");
            IStmt left = inputStatement();

            print("Right side:");
            IStmt right = inputStatement();

            return(new CompStmt(left, right));
        }
Example #32
0
        public void SetStmt(string name, IStmt stmt)
        {
            var prop = GetType().GetProperty(name, typeof(IStmt));

            if (prop == null)
            {
                return;
            }
            prop.SetValue(this, stmt);
        }
Example #33
0
 public IfThenStmt(Exp e, IStmt then)
 {
     exp = e;
     thenStmt = then;
 }
Example #34
0
 public IfStmt(Exp e, IStmt then, IStmt otherwise)
 {
     this.exp = e;
     this.thenStmt = then;
     this.elseStmt = otherwise;
 }
Example #35
0
 public WhileStmt(Exp e, IStmt stmt)
 {
     this.exp = e;
     this.stmt = stmt;
 }
Example #36
0
 public ForkStmt(IStmt forkStmt)
 {
     this.forkStmt = forkStmt;
 }
Example #37
0
 public CompStmt(IStmt left, IStmt right)
 {
     first = left;
     second = right;
 }
Example #38
0
 public CmpStmt(IStmt first, IStmt second)
 {
     this.first = first;
     this.second = second;
 }
Example #39
0
 public RepeatStmt(IStmt statement, Exp expr)
 {
     exp = expr;
     stmt = statement;
 }
Example #40
0
 public IfStmt(Exp e, IStmt t, IStmt el)
 {
     exp = e;
     thenS = t;
     elseS = el;
 }
Example #41
0
 public IfThenStmt(Exp e, IStmt t)
 {
     exp = e;
     thenS = t;
 }