예제 #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 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);
        }
예제 #3
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);
        }
        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);
        }
예제 #5
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);
        }
        public PrgState execute(PrgState state)
        {
            MyIFileDictionary <int, KeyValuePair <string, StreamReader> > dict = state.getFileTable();

            try
            {
                for (int i = 0; i < dict.size(); i++)
                {
                    if (dict.lookup(i).Key == filename)
                    {
                        throw new MyException("Filename already exists!");
                    }
                }
                StreamReader br = null;
                FileStream   fr = null;
                try
                {
                    fr = new FileStream(filename, FileMode.Open);
                    br = new StreamReader(fr);
                    KeyValuePair <string, StreamReader> p = new KeyValuePair <string, StreamReader>(filename, br);
                    int uniqKey = this.key.getGeneratedKey();
                    dict.add(uniqKey, p);
                    //int lastKey = dict.getKey();
                    MyIDictionary <string, int> symTbl = state.getSymTable();
                    symTbl.add(var_file_id, uniqKey);
                }
                catch (IOException e)
                {
                    throw new IOException(e.ToString());
                }
            }
            catch (MyException ex)
            {
                throw new MyException("" + ex);
            }
            return(state);
        }