예제 #1
0
        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);
            }
        }
예제 #2
0
 public int Eval(MyIDictionary <string, int> tbl)
 {
     if (!tbl.isDefined(id))
     {
         MyException ex = new MyException("Variable does not exist!");
         throw ex;
     }
     return(tbl.lookup(id));
 }
예제 #3
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stack    = state.getStk();
            MyIDictionary <string, int> symTable = state.getSymTable();
            int val = exp.Eval(symTable);

            if (symTable.isDefined(id))
            {
                symTable.update(id, val);
            }
            else
            {
                symTable.put(id, val);
            }
            return(null);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk     = state.getExeStack();
            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);

            FileTuple ft = fileTbl.getValue(value_exp);

            if (!symTbl.isDefined(ft.getFileName()))
            {
                //throw new MyStmtExecException("The key is not defined in the file table");
            }

            StreamReader streamReader = ft.getStreamReader();
            int          val          = -1;

            try
            {
                String line = streamReader.ReadLine();

                if (line == null)
                {
                    val = 0;
                }
                else
                {
                    try
                    {
                        val = int.Parse(line);
                    }
                    catch (Exception ex) { Console.WriteLine(ex.Message); }
                }


                symTbl.put(this.var_name, val);
            }
            catch (IOException ex) { throw new Exception(ex.Message); }
            return(state);
        }
        public PrgState execute(PrgState state)
        {
            MyIDictionary <string, int> symTbl = state.getSymTable();

            try {
                int val = exp.eval(symTbl);
                if (symTbl.isDefined(id))
                {
                    symTbl.update(id, val);
                }
                else
                {
                    symTbl.add(id, val);
                }
            }
            catch (MyException ex) {
                throw new MyException("" + ex);
            }

            return(state);
        }
예제 #7
0
        public PrgState execute(PrgState state)
        {
            MyIDictionary <string, int> symTbl = state.getSymTable();
            MyIFileDictionary <int, KeyValuePair <string, StreamReader> > fileTable = state.getFileTable();

            try
            {
                int val = exp_file_id.eval(symTbl);
                fileTable.lookup(val);
                StreamReader br   = fileTable.get(val).Value;
                String       line = br.ReadLine();

                int value, x;
                if (line == null)
                {
                    value = 0;
                }
                else
                {
                    value = int.Parse(line);
                }

                if (symTbl.isDefined(var_name))
                {
                    symTbl.update(var_name, value);
                }
                else
                {
                    symTbl.add(var_name, value);
                }
            }
            catch (MyException e)
            {
                throw new MyException("" + e);
            }
            return(state);
        }