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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
                KeyValuePair <string, StreamReader> p = fileTable.lookup(val);
                StreamReader br = p.Value;
                br.Close();
                fileTable.remove(val); //not Sure
            }
            catch (MyException ex)
            {
                throw new MyException("" + ex);
            }

            return(state);
        }