Exemplo n.º 1
0
        public PState execute(PState state)
        {
            IMap <int, FileTuple> files = state.getFiles();
            IMap <string, int>    table = state.getTable();
            int          counter        = state.getFilesCounter();
            StreamReader filedesc       = null;

            try {
                filedesc = new StreamReader("E:\\fac\\ToyCSharp\\ToyCSharp\\bin\\Debug\\" + filename);
            }
            catch (FileNotFoundException e) {
                System.Console.WriteLine(e.Message);

                throw new MyException("FILE_ERR: can't open file");
            }

            FileTuple f = new FileTuple(filename, filedesc);

            if (files.hasValue(f))
            {
                throw new MyException("FILE_ERR: file already opened");
            }

            files.add(counter, f);
            if (table.hasKey(var))
            {
                table.update(var, counter);
            }
            else
            {
                table.add(var, counter);
            }
            return(null);
        }
Exemplo n.º 2
0
        public bool equals(Object ob)
        {
            if (ob == null)
            {
                return(false);
            }
            if (ob.GetType() != this.GetType())
            {
                return(false);
            }
            FileTuple x = (FileTuple)ob;

            return(this.filename == x.filename);
        }
Exemplo n.º 3
0
        public PState execute(PState state)
        {
            IMap <int, FileTuple> files = state.getFiles();
            IMap <string, int>    table = state.getTable();
            int res = fid.eval(table);

            if (!files.hasKey(res))
            {
                throw new MyException("FILE_ERR: file not opened");
            }

            FileTuple f = files.lookup(res);

            f.filedesc.Close();

            files.remove(res);
            return(null);
        }
Exemplo n.º 4
0
        public PState execute(PState state)
        {
            IMap <int, FileTuple> files = state.getFiles();
            IMap <string, int>    table = state.getTable();
            int res = fid.eval(table);
            int value;

            if (!files.hasKey(res))
            {
                throw new MyException("FILE_ERR: file doesn't exist");
            }

            FileTuple    f      = files.lookup(res);
            StreamReader buffer = f.filedesc;

            string line = buffer.ReadLine();

            if (line == null)
            {
                value = 0;
            }
            else
            {
                value = Int32.Parse(line);
            }

            if (table.hasKey(var))
            {
                table.update(var, value);
            }
            else
            {
                table.add(var, value);
            }
            return(null);
        }