コード例 #1
0
ファイル: StmOpenRFile.cs プロジェクト: mgvx/facultate
        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
ファイル: StmPrint.cs プロジェクト: mgvx/facultate
        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
ファイル: StmAssign.cs プロジェクト: mgvx/facultate
        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
ファイル: StmCloseRFile.cs プロジェクト: mgvx/facultate
        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
ファイル: StmReadRFile.cs プロジェクト: mgvx/facultate
        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);
        }