public PrgState execute(PrgState state)
        {
            MyIList <int> ot = state.getOut();
            MyIDictionary <String, int> symTbl = state.getSymTable();

            ot.add(exp.eval(state.getSymTable()));
            return(state);
        }
Example #2
0
        public void execute(PrgState state)
        {
            ImyList <int>         output   = state.getOutput();
            ImyDict <String, int> symTable = state.getSymTable();

            output.add(e.eval(symTable));
        }
Example #3
0
        public void execute(PrgState state)
        {
            ImyDict <int, Tuple <string, StreamReader> > fileTable = state.getFileTable();
            ImyDict <string, int> symTable = state.getSymTable();

            try {
                if (fileTable.isInTuple(this.filename))
                {
                    throw new StmtException("File allready opened");
                }
            } catch (Exception e1) {
                throw new StmtException("Statement \"" + this.ToString() + "\" encountered a dictionary exception: " + e1.Message);
            }
            StreamReader buffReader;

            try {
                buffReader = new StreamReader(filename);
            } catch (FileNotFoundException) {
                throw new StmtException("File not found \"" + filename + "\"");
            }

            Tuple <string, StreamReader> entry = new Tuple <string, StreamReader>(filename, buffReader);
            int id = fileTable.generateId();

            fileTable.add(id, entry);
            symTable.add(var_file_id, id);
        }
Example #4
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt> stk = state.getExeStack();
            // stk.pop();

            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);


            FileTuple ft = fileTbl.getValue(value_exp);

            if (!fileTbl.isDefined(value_exp))
            {
                throw new Exception("The key is not defined in the file table");
            }

            StreamReader streamReader = fileTbl.getValue(value_exp).getStreamReader();

            try
            {
                streamReader.Close();
            }
            catch (IOException ex) { throw new Exception(ex.Message); }

            fileTbl.remove(value_exp);
            return(state);
        }
Example #5
0
        public PrgState execute(PrgState state)
        {
            MyIList <int> outList = state.getOutList();
            MyIDictionary <string, int> symTabel = state.getSymTable();

            outList.add(exp.Eval(symTabel));
            return(null);
        }
Example #6
0
        public PrgState execute(PrgState state)
        {
            int id = exp.Eval(state.getSymTable());
            Tuple <string, StreamReader> pair = state.getFileTable().get(id);

            if (pair == null)
            {
                throw new MyException("File not opened!");
            }

            string line = pair.Item2.ReadLine();

            if (line != null)
            {
                if (state.getSymTable().isDefined(var))
                {
                    state.getSymTable().update(var, Convert.ToInt32(line));
                }
                else
                {
                    state.getSymTable().put(var, Convert.ToInt32(line));
                }
            }
            else
            if (state.getSymTable().isDefined(var))
            {
                state.getSymTable().update(var, 0);
            }
            else
            {
                state.getSymTable().put(var, 0);
            }
            return(null);
        }
Example #7
0
        public PrgState execute(PrgState state)
        {
            if (!File.Exists(filename))
            {
                throw new MyException("File does not exist!");
            }

            state.getFileTable().put(unique_key, Tuple.Create(filename, new StreamReader(filename)));
            state.getSymTable().put(id, unique_key);
            unique_key += 1;
            return(null);
        }
Example #8
0
        public void execute(PrgState state)
        {
            ImyDict <string, int> symTable = state.getSymTable();

            int val;

            try {
                val = e.eval(symTable);
                symTable.add(id, val);
            } catch (ExpException e) {
                throw new StmtException("Statement \"" + this.ToString() + "\": " + e.Message);
            }
        }
Example #9
0
        public PrgState execute(PrgState state)
        {
            int id = exp.Eval(state.getSymTable());
            Tuple <string, System.IO.StreamReader> pair = state.getFileTable().get(id);

            if (pair == null)
            {
                throw new MyException("File not found!");
            }
            state.getFileTable().remove(id);
            pair.Item2.Close();
            return(null);
        }
Example #10
0
        public PrgState execute(PrgState state)
        {
            if (exp.eval(state.getSymTable()) != 0)
            {
                thenS.execute(state);
            }
            else
            {
                elseS.execute(state);
            }

            return(state);
        }
Example #11
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk      = state.getStk();
            MyIDictionary <string, int> symTable = state.getSymTable();

            if (exp.Eval(symTable) != 0)
            {
                stk.push(thenStatement);
            }
            else
            {
                stk.push(elseStatement);
            }
            return(null);
        }
Example #12
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stack    = state.getStk();
            MyIDictionary <string, int> symTable = state.getSymTable();
            int val = exp.Eval(symTable);

            if (symTable.isDefined(id))
            {
                symTable.update(id, val);
            }
            else
            {
                symTable.put(id, val);
            }
            return(null);
        }
Example #13
0
        public void execute(PrgState state)
        {
            ImyStack <Istmt>      stk      = state.getExeStack();
            ImyDict <string, int> symTable = state.getSymTable();

            try {
                if (e.eval(symTable) != 0)
                {
                    stk.push(thenS);
                }
                else
                {
                    stk.push(elseS);
                }
            } catch (ExpException) {
                throw new StmtException("Id in \"" + this.ToString() + "\" statement has no value asociated with it");
            }
        }
Example #14
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk     = state.getExeStack();
            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);

            FileTuple ft = fileTbl.getValue(value_exp);

            if (!symTbl.isDefined(ft.getFileName()))
            {
                //throw new MyStmtExecException("The key is not defined in the file table");
            }

            StreamReader streamReader = ft.getStreamReader();
            int          val          = -1;

            try
            {
                String line = streamReader.ReadLine();

                if (line == null)
                {
                    val = 0;
                }
                else
                {
                    try
                    {
                        val = int.Parse(line);
                    }
                    catch (Exception ex) { Console.WriteLine(ex.Message); }
                }


                symTbl.put(this.var_name, val);
            }
            catch (IOException ex) { throw new Exception(ex.Message); }
            return(state);
        }
Example #15
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk       = state.getExeStack();
            IFileTable <int, FileTuple> filetable = state.getFileTable();
            MyIDictionary <String, int> symTbl    = state.getSymTable();

            try
            {
                FileStream   reader         = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader bufferedStream = new StreamReader(reader);
                int          id             = IdGenerator.generateId();
                FileTuple    tuple          = new FileTuple(this.filename, bufferedStream);
                filetable.put(id, tuple);

                symTbl.put(this.var_file_id, id);
            }
            catch (Exception ex) { throw new Exception(ex.Message); }


            return(state);
        }
Example #16
0
        public void execute(PrgState state)
        {
            ImyDict <string, int> symTable = state.getSymTable();
            ImyDict <int, Tuple <string, StreamReader> > fileTable = state.getFileTable();

            int          v;
            StreamReader buffReader;

            try {
                v = exp_file_id.eval(symTable);
            } catch (ExpException e) {
                throw new StmtException("Expression \"" + exp_file_id + "\" in statement + \"" + this.ToString() + "\" is invalid: " + e.Message);
            }

            try {
                buffReader = fileTable.get(v).Item2;
            } catch (Exception) {
                throw new StmtException("File does not exist or hasn't been open \"" + exp_file_id.ToString() + "\"");
            }

            try {
                string readValue = buffReader.ReadLine();

                int value;

                if (readValue == null)
                {
                    value = 0;
                }
                else
                {
                    Int32.TryParse(readValue, out value);
                }

                symTable.add(var_name, value);
            } catch (IOException e2) {
                throw new StmtException("Statement \"" + this.ToString() + "\" encountered an exception: " + e2.Message);
            }
        }
Example #17
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk    = state.getExeStack();
            MyIDictionary <String, int> symTbl = state.getSymTable();

            try
            {
                int val = exp.eval(symTbl);

                //if (!symTbl.isDefined(this.id))
                //throw new MyStmtExecException("The variable is not assigned");
                //int address = symTbl.get(this.id);
                //heap.put(address, val);

                symTbl.put(this.id, val);                 //we assign the new values
            }
            catch (Exception ex)
            {
                Console.WriteLine("ASSIGN ERROR");
            }

            return(state);
        }
Example #18
0
        public PrgState execute(PrgState state)
        {
            ImyDict <String, int> symTable = state.getSymTable();
            ImyDict <int, Tuple <String, StreamReader> > fileTable = state.getFileTable();

            int          v;
            StreamReader buffReader;

            try {
                v = exp_file_id.eval(symTable);
            } catch (ExpException e) {
                throw new StmtException("Expression \"" + exp_file_id + "\" in statement + \"" + this.ToString() + "\" is invalid: " + e.Message);
            }

            try {
                buffReader = fileTable.get(v).Item2;
                buffReader.Close();
                fileTable.remove(v);
            } catch (Exception) {
                throw new StmtException("File does not exist or hasn't been open");
            }

            return(null);
        }