Пример #1
0
        public ProgState execute(ProgState prog)
        {
            MyIDictionary <string, int> dict = prog.getDict();
            MyIFileTable <Tuple>        Tpl  = prog.getFile();

            try
            {
                int   val = exp.eval(dict);
                Tuple tpl = Tpl.get(val);
                if (tpl != null)
                {
                    tpl.getST().Close();
                    Tpl.remove(val);
                }
                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);
        }
Пример #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);
        }