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);
        }
        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);
        }
Beispiel #3
0
 public ProgState(MyIStack <IStmt> stk, MyIDictionary <string, int> dict, MyIList <int> list, MyIFileTable <Tuple> fileT, IStmt prog)
 {
     this.stk   = stk;
     this.dict  = dict;
     this.list  = list;
     this.fileT = fileT;
     stk.push(prog);
 }
 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);
 }
        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);
        }
Beispiel #6
0
 public void setFile(MyIFileTable <Tuple> fileT)
 {
     this.fileT = fileT;
 }