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

            ot.add(exp.eval(state.getSymTable()));
            return(state);
        }
예제 #2
0
파일: Print.cs 프로젝트: BendicRadu/MAP-CS
        public void execute(PrgState state)
        {
            ImyList <int>         output   = state.getOutput();
            ImyDict <String, int> symTable = state.getSymTable();

            output.add(e.eval(symTable));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #10
0
        public PrgState execute(PrgState state)
        {
            if (exp.eval(state.getSymTable()) != 0)
            {
                thenS.execute(state);
            }
            else
            {
                elseS.execute(state);
            }

            return(state);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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");
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #16
0
파일: Read.cs 프로젝트: BendicRadu/MAP-CS
        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);
            }
        }
예제 #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);
        }
예제 #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);
        }