示例#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);
        }
示例#2
0
        public PState execute(PState state)
        {
            IMap <string, int> table = state.getTable();
            IList <int>        list  = state.getOut();

            list.add(exp.eval(table));
            return(state);
        }
示例#3
0
文件: StmComp.cs 项目: mgvx/facultate
        public PState execute(PState state)
        {
            IStack <IStatement> stack = state.getStack();

            stack.push(second);
            stack.push(first);
            return(state);
        }
示例#4
0
        public PState execute(PState state)
        {
            IStack <IStatement> stack = state.getStack();
            IMap <string, int>  table = state.getTable();
            int val = exp.eval(table);

            if (val != 0)
            {
                stack.push(s1);
            }
            else
            {
                stack.push(s2);
            }
            return(state);
        }
示例#5
0
        public PState execute(PState state)
        {
            IStack <IStatement> stack = state.getStack();
            IMap <string, int>  table = state.getTable();
            int val = exp.eval(table);

            if (table.hasKey(id))
            {
                table.update(id, val);
            }
            else
            {
                table.add(id, val);
            }
            return(state);
        }
示例#6
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);
        }
示例#7
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);
        }