Ejemplo n.º 1
0
        public ProgState execute(ProgState programState)
        {
            try
            {
                int descriptor = fileDescriptor.evaluate(programState.getSymbolTable);
                FileTable <int, FileData> fileTable = programState.getFileTable;
                StreamReader bufferedReader         = fileTable.getValue(descriptor).Buffer;

                string    line = bufferedReader.ReadLine();
                ConstExpr value;

                if (line == null)
                {
                    value = new ConstExpr(0);
                }
                else
                {
                    value = new ConstExpr(int.Parse(line));
                }

                Statement assignment = new AssignStmt(variable, value);

                return(assignment.execute(programState));
            }
            catch (IOException)
            {
                throw (new InterpreterException("error: file could not be read"));
            }
        }
Ejemplo n.º 2
0
        public ProgState execute(ProgState state)
        {
            SymbolTable <string, int> table = state.getSymbolTable;
            Output <int> outs = state.getOutput;

            outs.add(exp.evaluate(table));
            return(state);
        }
Ejemplo n.º 3
0
        public ProgState execute(ProgState state)
        {
            ExeStack <Statement> stack = state.getExeStack;

            stack.push(stm2);
            stack.push(stm1);
            return(state);
        }
Ejemplo n.º 4
0
        public ProgState execute(ProgState state)
        {
            SymbolTable <string, int> table = state.getSymbolTable;
            int val = exp.evaluate(table);

            table.add(name, val);
            return(state);
        }
Ejemplo n.º 5
0
        public ProgState execute(ProgState state)
        {
            ExeStack <Statement>      stack = state.getExeStack;
            SymbolTable <string, int> table = state.getSymbolTable;
            int val = exp.evaluate(table);

            if (val != 0)
            {
                stack.push(stm1);
            }
            else
            {
                stack.push(stm2);
            }
            return(state);
        }
Ejemplo n.º 6
0
        public ProgState execute(ProgState programState)
        {
            try
            {
                int descriptor = fileDescriptor.evaluate(programState.getSymbolTable);
                FileTable <int, FileData> fileTable = programState.getFileTable;
                StreamReader bufferedReader         = fileTable.getValue(descriptor).Buffer;

                bufferedReader.Close();
                fileTable.remove(descriptor);

                return(programState);
            }
            catch (IOException)
            {
                throw (new InterpreterException("error: file could not be closed"));
            }
        }
Ejemplo n.º 7
0
        public ProgState execute(ProgState state)
        {
            FileTable <int, FileData> fileT = state.getFileTable;

            if (isOpen(fileName, fileT))
            {
                throw new InterpreterException("error: file could not be open");
            }
            try
            {
                StreamReader bufferedReader    = new StreamReader(fileName);
                FileData     fd                = new FileData(fileName, bufferedReader);
                int          id                = Generator.generator();
                SymbolTable <string, int> symT = state.getSymbolTable;
                fileT.add(id, fd);
                symT.add(fileId, id);
            }
            catch (IOException e)
            {
                throw new InterpreterException("error: file could not be open");
            }
            return(state);
        }