public PrgState execute(PrgState state)
        {
            MyIList <int> list = state.getOut();
            MyIDictionary <string, int> dict = state.getSymTable();

            try
            {
                list.add(exp.eval(dict));
            }
            catch (MyException ex)
            {
                throw new MyException("" + ex);
            }
            return(state);
        }
Esempio 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);
                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);
        }
        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);
        }
        public PrgState execute(PrgState state)
        {
            MyIDictionary <string, int> dict = state.getSymTable();
            MyIStack <IStmt>            stk  = state.getStk();

            try
            {
                if (exp.eval(dict) != 0)
                {
                    stk.push(thenS);
                }
                else
                {
                    stk.push(elseS);
                }
            }
            catch (MyException ex)
            {
                throw new MyException("" + ex);
            }
            return(state);
        }
Esempio n. 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);
        }