Esempio n. 1
0
        public PrgState execute(PrgState state)
        {
            int fd = this.exp.evaluate(state.getSymTable());
            Tuple <String, TextReader> act = state.getFileTable().get(fd);

            if (act == null)
            {
                throw new Exception("FileNotOpened Exception at: " + this.ToString() + "\nThere is no opened file with fd = " + fd);
            }
            act.Item2.Close();
            state.getFileTable().remove(fd);
            return(state);
        }
        public PrgState execute(PrgState prgState)
        {
            var fileTable = prgState.getFileTable();

            foreach (Tuple <string, TextReader> act in fileTable.values())
            {
                if (act.Item1 == this.fileName)
                {
                    throw new Exception("already opened wtf?");
                }
            }
            TextReader t     = File.OpenText(this.fileName);
            int        actFd = ++OpenRFileStmt.fd; /// static variable

            prgState.getFileTable().put(actFd, new Tuple <String, TextReader>(this.fileName, t));
            prgState.getSymTable().put(this.varId, actFd);
            return(prgState);
        }
Esempio n. 3
0
        public PrgState execute(PrgState state)

        {
            int fd = this.exp.evaluate(state.getSymTable());
            Tuple <String, TextReader> br = state.getFileTable().get(fd);

            if (br == null)
            {
                throw new Exception("FileNotOpenedException at: " + this.ToString() + "\nNo such file descriptor: " + fd.ToString());
            }
            String line = br.Item2.ReadLine();
            int    val  = 0;

            if (line != null)
            {
                val = int.Parse(line);
            }
            state.getSymTable().put(this.var, val);
            return(state);
        }