Esempio n. 1
0
        public PrgState Execute(PrgState state)
        {
            MyIDictionary <String, int> symTable = state.GetSymTable();
            int file_id = this.exp_file_id.Eval(symTable);
            MyIPair <String, StreamReader> fileTable = state.GetFileTable().Lookup(file_id);

            if (fileTable == null)
            {
                throw new MyException("File not opened");
            }
            int    anotherVal;
            String line = fileTable.GetSecond().ReadLine();

            if (line == null)
            {
                anotherVal = 0;
            }
            else
            {
                anotherVal = System.Convert.ToInt32(line);
            }
            if (symTable.IsDefinedU(var_name))
            {
                symTable.Update(var_name, anotherVal);
            }
            else
            {
                symTable.Add(var_name, anotherVal);
            }
            return(state);
        }
Esempio n. 2
0
        public PrgState Execute(PrgState state)
        {
            MyIStack <IStmt>            stk    = state.GetExeStack();
            MyIDictionary <String, int> symTbl = state.GetSymTable();
            int val = exp.Eval(symTbl);

            if (symTbl.IsDefinedU(id))
            {
                symTbl.Update(id, val);
            }
            else
            {
                symTbl.Add(id, val);
            }
            return(state);
        }
Esempio n. 3
0
        public ProgramState Execute(ProgramState programState)
        {
            MyIDictionary <string, int> symbolTable = programState.SymbolTable;

            int value = expression.Evaluate(symbolTable);

            if (symbolTable.ContainsKey(id))
            {
                symbolTable.Update(id, value);
            }
            else
            {
                symbolTable.Add(id, value);
            }

            return(programState);
        }
Esempio n. 4
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIDictionary symTbl = state.GetSymTable();
            int           val;

            val = mExp.Eval(symTbl, state.GetHeap());

            if (symTbl.IsDefined(mId))
            {
                symTbl.Update(mId, val);
            }
            else
            {
                symTbl.Add(mId, val);
            }
            return(null);
        }
Esempio n. 5
0
        public PrgState <T> Execute <T>(PrgState <T> state)
        {
            MyIHeap       heap     = state.GetHeap();
            MyIDictionary symTable = state.GetSymTable();

            if (symTable.IsDefined(mVarName))
            {
                symTable.Update(mVarName, heap.Size() + 1);
                heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap));
            }
            else
            {
                symTable.Add(mVarName, heap.Size() + 1);
                heap.Put(heap.Size() + 1, mExp.Eval(symTable, heap));
            }

            return(null);
        }
Esempio n. 6
0
        public ProgramState Execute(ProgramState programState)
        {
            MyIDictionary <string, int> symbolTable = programState.SymbolTable;

            int fileDescriptor = expFileId.Evaluate(symbolTable);

            if (!programState.FileTable.TryGetValue(fileDescriptor, out Tuple <string, TextReader> value))
            {
                throw new StatementException("Invalid file id provided!");
            }

            TextReader reader = value.Item2;
            string     line;

            try
            {
                line = reader.ReadLine();
            }catch (Exception)
            {
                throw new StatementException("Error while reading from file!");
            }

            int intValue = 0;

            if (line != null && !int.TryParse(line, out intValue))
            {
                throw new StatementException("File contains non-numeric values!");
            }

            if (symbolTable.ContainsKey(varName))
            {
                symbolTable.Update(varName, intValue);
            }
            else
            {
                symbolTable.Add(varName, intValue);
            }

            return(programState);
        }