Beispiel #1
0
        /* @Override */
        public PrgState execute(PrgState state)
        {
            Stack <IStmt> stack = state.getExeStack();

            stack.Push(this.snd);
            stack.Push(this.fst);

            return(state);
        }
Beispiel #2
0
        public PrgState oneStep(PrgState state)
        {
            Stack <IStmt> exeStack = state.getExeStack();

            // if(exeStack.isEmpty())
            // return null;
            // throws MyStmtExecException;
            IStmt currentStmt = exeStack.Pop();

            return(currentStmt.execute(state));
        }
Beispiel #3
0
        public void logPrgStateExec()
        {
            /*
             * try {
             *  // TODO: first file open overwrites file.
             *  PrintWriter logFile = new PrintWriter(new BufferedWriter(new FileWriter(this.logFilePath, true)));
             *
             *  logFile.println(this.getCurrentState().toString());
             *  logFile.close();
             * } catch(Exception e) {
             *      System.err.println(e);
             *      throw e;
             * }*/

            PrgState state = getCurrentState();

            using (StreamWriter logFile = new StreamWriter(logFilePath, true)) {
                try {
                    logFile.WriteLine("Execution Stack\n");
                    foreach (IStmt statement in state.getExeStack())
                    {
                        logFile.WriteLine("  " + statement + "\n");
                    }
                    logFile.WriteLine("\n");

                    logFile.WriteLine("Symbol Table\n");
                    foreach (KeyValuePair <string, int> entry in state.getSymTable())
                    {
                        logFile.WriteLine("  " + entry.Key + " --> " + entry.Value + "\n");
                    }
                    logFile.WriteLine("\n");

                    logFile.WriteLine("File Table\n");
                    foreach (KeyValuePair <int, MyFile> entry in state.getFileTable())
                    {
                        logFile.WriteLine("  " + entry.Key + " --> " + entry.Value + "\n");
                    }
                    logFile.WriteLine("\n");

                    logFile.WriteLine("Output\n");
                    foreach (int output in state.getStdout())
                    {
                        logFile.Write("  %d\n", output);
                    }
                    logFile.WriteLine("-------------------\n");
                }
                catch (Exception) {
                    Console.WriteLine("error: could not write to the given file");
                }
            }
        }
Beispiel #4
0
        /* @Override */
        public PrgState execute(PrgState state)
        {
            Stack <IStmt>            exeStack = state.getExeStack();
            Dictionary <String, int> symTable = state.getSymTable();

            if (this.exp.eval(symTable) != 0)
            {
                exeStack.Push(thenStmt);
            }
            else
            {
                exeStack.Push(elseStmt);
            }

            return(state);
        }
Beispiel #5
0
        public void allStep()
        {
            PrgState state = r.getCurrentState();

            // initial state
            Console.WriteLine(state.toString());
            try {
                this.r.logPrgStateExec();
            } catch (Exception e) {
                Console.Write(e.ToString());
            }

            while (state.getExeStack().Count != 0)
            {
                oneStep(state);
                Console.WriteLine(state.toString());
                try {
                    this.r.logPrgStateExec();
                } catch (Exception e) {
                    Console.Write(e.ToString());
                }
            }
        }