public static void Main(string[] args) { IExeStack <IStatement> stack = new ExeStack <IStatement>(); Utils.IDictionary <string, int> dict = new MyDictionary <string, int>(); IMyList <int> output = new MyList <int>(); FileTable <int, FileData> fileTable = new FileTable <int, FileData>(); IStatement s1 = new OpenRFile("var_f", "C:\\Users\\Emy\\RiderProjects\\lab7\\text1.txt"); IStatement s2 = new ReadFile(new VarExp("var_f"), "var_c"); IStatement thenS1 = new ReadFile(new VarExp("var_f"), "var_c"); IStatement thenS2 = new PrintStmt(new VarExp("var_c")); IStatement thenS = new CompStmt(thenS1, thenS2); IStatement elseS = new PrintStmt(new ConstExp(0)); IStatement s3 = new IfStmt(new VarExp("var_c"), thenS, elseS); IStatement s4 = new CloseRFile(new VarExp("var_f")); IStatement s5 = new CompStmt(s1, s2); IStatement s6 = new CompStmt(s3, s4); IStatement s7 = new CompStmt(s5, s6); stack.push(s7); PrgState state = new PrgState(dict, stack, output, fileTable); Controller.Controller ctrl = new Controller.Controller(state); TextMenu menu = new TextMenu(); menu.addCommand(new ExitCommand("0", "exit")); menu.addCommand(new RunExample("1", "example_1", ctrl)); menu.show(); }
public override string ToString() { return("\tProgram State\nExecution Stack\n" + ExeStack.ToString() + "\n\nTable of Symbols: " + SymTable.ToString() + "\n\nOutput: " + Output.ToString() + "\n\nFile Table: " + FileTable.ToString() + "\n\n\n\n"); }
public ProgState execute(ProgState state) { ExeStack <Statement> stack = state.getExeStack; stack.push(stm2); stack.push(stm1); return(state); }
ProgramState IStmt.execute(ProgramState programState) { ExeStack <IStmt> exeStack = programState.getExeStack(); exeStack.Push(st2); exeStack.Push(st1); return(null); }
public ProgState(SymbolTable <string, int> symTable, ExeStack <Statement> exe, Output <int> outs, FileTable <int, FileData> fileT, Statement stm) { this.symTable = symTable; this.exe = exe; this.outs = outs; this.fileT = fileT; this.exe.push(stm); }
public override string ToString() { return ("ExeStack:\n" + ExeStack.ToString() + "SymLink:\n" + SymTable.ToString() + "FileTable:\n" + FileTable.ToString() + "Heap:\n" + Heap.ToString() + "Output:\n" + Output); }
public ProgramState(ExeStack <IStmt> exeStack, Output <int> output, SymTable <string, int> symTable, FileTable fileTable, IStmt program) { _exeStack = exeStack; _output = output; _symTable = symTable; _fileTable = fileTable; _program = program; }
public ProgramState(IStmt statement) { _exeStack = new ExeStack <IStmt>(); _exeStack.Push(statement); _symTable = new SymTable <string, int>(); _output = new Output <int>(); _fileTable = new FileTable(); _program = statement; }
private void ExecuteCommand(int command) { IExeStack <IStmt> exeStack = new ExeStack <IStmt>(); IModList <int> outList = new ModList <int>(); IModDictionary <string, int> dict = new ModDictionary <string, int>(); IStmt stmt = default(IStmt); IFileTable <int, FileData> fileTable = new FileTable <int, FileData>(); switch (command) { case 1: stmt = new CompStmt( new AssingStmt("v", new ConstExp(2)), new PrintStmt(new VarExp("v"))); break; case 2: break; case 3: break; case 4: stmt = new CompStmt( new OpenRFile("var_f", @"E:\GitRepoCollege\MAP\C# - Toy language\Lab10\Toy Language\Toy Language\test.in"), new CompStmt( new ReadRFile(new VarExp("var_f"), "var_c"), new CompStmt( new PrintStmt(new VarExp("var_c")), new CompStmt( new IfStmt( new VarExp("var_c"), new CompStmt( new ReadRFile(new VarExp("var_f"), "var_c"), new PrintStmt(new VarExp("var_c"))), new PrintStmt(new ConstExp(0))), new CloseRFile(new VarExp("var_f")))))); break; default: // throw some error throw new Exception("Invalid command"); } PrgState prgState = new PrgState(exeStack, dict, outList, fileTable, stmt); ctrl.AddPrgState(prgState); try { ctrl.AllStep(); } catch (Exception ex) { Console.WriteLine(ex); } }
public ProgramState OneStep(ProgramState prgState) { ExeStack <IStmt> exeStack = prgState.getExeStack(); if (exeStack.Count == 0) { throw new Exception("Empty execution stack!\n"); } return(exeStack.Pop().execute(prgState)); }
public void executeOneStep(Statement s) { IExeStack <Statement> exeStack = new ExeStack <Statement>(); ISymbolTable <string, int> symbolTable = new SymbolTable <string, int>(); IOutput <int> messages = new Output <int>(); IFileTable <int, FileData> fd = new FileTable <int, FileData>(); PrgState state = new PrgState(symbolTable, exeStack, messages, fd); IPrgRepository repo = new PrgRepository(state); Controller ctrl = new Controller(repo); ctrl.executeOneStep(); }
static void Main(string[] args) { IExeStack <Statement> exeStack = new ExeStack <Statement>(); Model.ADT.IDictionary <string, int> symbolTable = new DictionaryC <string, int>(); IOutput <int> messages = new Output <int>(); IFileTable <int, FileData> fd = new FileTable <int, FileData>(); Statement s = new CompoundStatement(new AssignStatement("v", new ConstantExpression(2)), new PrintStatement(new VariableExpression("v"))); exeStack.Push(s); PrgState state = new PrgState(symbolTable, exeStack, messages, fd); IMyRepository repo = new MyRepository(state); Controller.MyController ctrl = new Controller.MyController(repo); IExeStack <Statement> exeStack1 = new ExeStack <Statement>(); Model.ADT.IDictionary <string, int> symbolTable1 = new DictionaryC <string, int>(); IOutput <int> messages1 = new Output <int>(); IFileTable <int, FileData> fd1 = new FileTable <int, FileData>(); Statement s1 = new CompoundStatement( new CompoundStatement( new CompoundStatement( new OpenFileStatement("var_f", "C:\\FACULTATE\\MAP\\Lab7\\Lab7\\test.in"), new ReadFileStatement(new VariableExpression("var_f"), "var_c") ), new CompoundStatement( new PrintStatement(new VariableExpression("var_c")), new IfStatement( new VariableExpression("var_c"), new PrintStatement(new ConstantExpression(0)) , new CompoundStatement( new ReadFileStatement(new VariableExpression("var_f"), "var_c"), new PrintStatement(new VariableExpression("var_c")))))), new CloseFileStatement(new VariableExpression("var_f"))); exeStack1.Push(s1); PrgState state1 = new PrgState(symbolTable1, exeStack1, messages1, fd1); IMyRepository repo1 = new MyRepository(state1); Controller.MyController ctrl1 = new Controller.MyController(repo1); TextMenu menu = new TextMenu(); menu.addCommand(new ExitCommand("0", "exit")); //menu.addCommand(new RunExample("1", s.ToString(), ctrl)); menu.addCommand(new RunExample("1", s1.ToString(), ctrl1)); menu.show(); }
public ProgState oneStep(ProgState state) { ExeStack <Statement> stack = state.getExeStack; if (stack.isEmpty()) { throw (new InterpreterException("error: no current state")); } else { Statement crtStmt = stack.pop(); return(crtStmt.execute(state)); } }
ProgramState IStmt.execute(ProgramState programState) { ExeStack <IStmt> exeStack = programState.getExeStack(); if (exp.evaluate(programState.getSymTable()) != 0) { exeStack.Push(thenStmt); } else { exeStack.Push(elseStmt); } return(null); }
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); }
private static PrgState prg1() { //a=5; //if (a-5) then // print(1); //else // print(2); //print((5+7)a); Statement ex1 = new CompStmt( new AssignStmt("a", new ConstExpr(5)), new CompStmt( new IfStmt( new ArithmeticExpr( '-', new VarExpr("a"), new ConstExpr(5) ), new PrintStmt(new ConstExpr(1)), new PrintStmt(new ConstExpr(2)) ), new PrintStmt( new ArithmeticExpr( '*', new ArithmeticExpr( '+', new ConstExpr(5), new ConstExpr(7) ), new VarExpr("a") ) ) ) ); IExeStack <Statement> stack = new ExeStack <Statement>(); IDictionaryy <string, int> dict = new Dictionaryy <string, int>(); IListt <int> l = new outputList <int>(); FileTable <int, FileData> ft = new FileTable <int, FileData>(); stack.PushS(ex1); PrgState state = new PrgState(dict, stack, l, ex1, ft); return(state); }
static void Main(string[] args) { IStack <IStatement> stack = new ExeStack <IStatement>(); IDict <String, int> dictionary = new SymbTable <String, int>(); ILis <int> outL = new OutList <int>(); IDict <int, FileData> fileTab = new FileTable <int, FileData>(); IStatement stm1 = new AssignStatement("a", new ArithmeticExpression('+', new ConstExpression(5), new ConstExpression(4))); IStatement stm2 = new CompStatement(new AssignStatement("a", new ArithmeticExpression('+', new ConstExpression(5), new ConstExpression(4))), new AssignStatement("b", new ArithmeticExpression('-', new ConstExpression(14), new ConstExpression(4)))); IStatement asgnVar = new AssignStatement("x", new ArithmeticExpression('-', new ConstExpression(50), new ConstExpression(49))); IStatement ifstm = new IfStatement(new VarExpression("x"), new AssignStatement("x", new ConstExpression(13)), new AssignStatement("x", new ConstExpression(10))); IStatement stm3 = new CompStatement(asgnVar, new CompStatement(ifstm, new PrintStatement(new VarExpression("x")))); IStatement stm4 = new CompStatement(new OpenRFile("file", @"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\ex1.txt"), new CompStatement(new ReadFile(new VarExpression("file"), "x"), new CloseRFile(new VarExpression("file")))); IStatement stm5 = new CompStatement(new OpenRFile("file", @"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\ex1.txt"), new CompStatement(new ReadFile(new VarExpression("file"), "x"), new CompStatement(new ReadFile(new VarExpression("file"), "y"), new CloseRFile(new VarExpression("file"))))); stack.push(stm5); ProgramState ps = new ProgramState(stack, dictionary, outL, fileTab, stm5); IRepository repo = new Repository(@"c:\users\cristian\documents\visual studio 2015\Projects\Map\Map\OutLog.txt"); repo.Program = ps; Controller ctrl = new Controller(repo); TextMenu menu = new TextMenu(); menu.addCommand(new ExitCommand("0", "exit.")); menu.addCommand(new RunExample("1", "Run Program.", ctrl)); menu.show(); Console.ReadKey(); }