コード例 #1
0
        public void CompoundStatementProducesBlockWithStatements()
        {
            var c = new CompoundStatement(new NullExpression(), new NullExpression(), new ReturnStatement());

            Assert.AreEqual(3, c.Statements.Count);
            Assert.AreEqual("{null;null;return;}", c.ToString());
        }
コード例 #2
0
        public void CompoundStatementProducesEmptyBlock()
        {
            var c = new CompoundStatement();

            Assert.AreEqual(0, c.Statements.Count);
            Assert.AreEqual("{}", c.ToString());
        }
コード例 #3
0
        public void CompoundStatementProducesEmptyBlock()
        {
            var c = new CompoundStatement();

            Assert.AreEqual(0, c.Statements.Count);
            Assert.AreEqual("{}", c.ToString());
        }
コード例 #4
0
        public void CompoundStatementProducesBlockWithStatements()
        {
            var c = new CompoundStatement(new NullExpression(), new NullExpression(), new ReturnStatement());

            Assert.AreEqual(3, c.Statements.Count);
            Assert.AreEqual("{null;null;return;}", c.ToString());
        }
コード例 #5
0
        static void Main(string[] args)
        {
            // v = 2; print(v)
            IStatement ex1 = new CompoundStatement(new AssignmentStatement("v", new ConstantExpression(2)), new PrintStatement(new VariableExpression("v")));

            // open csharptestlogfile.txt, write the numbers on the first 2 lines and -1
            IStatement ex2 = new CompoundStatement(new OpenRFileStatement("var_f", "csharptestlogfile.txt"),
                                                   new CompoundStatement(new ReadRFileStatement(new VariableExpression("var_f"), "var_c"),
                                                                         new CompoundStatement(new PrintStatement(new VariableExpression("var_c")),
                                                                                               new CompoundStatement(new IfStatement(new VariableExpression("var_c"),
                                                                                                                                     new CompoundStatement(new ReadRFileStatement(new VariableExpression("var_f"), "var_c"), new PrintStatement(new VariableExpression("var_c"))),
                                                                                                                                     new PrintStatement(new ConstantExpression(0))), new PrintStatement(new ConstantExpression(-1))))));

            ProgramState          ps1   = new ProgramState(ex1);
            IRepository           repo1 = new Repository(ps1);
            InterpreterController ctrl1 = new InterpreterController(repo1);

            ProgramState          ps2   = new ProgramState(ex2);
            IRepository           repo2 = new Repository(ps2);
            InterpreterController ctrl2 = new InterpreterController(repo2);

            TextMenu menu = new TextMenu();

            menu.addCommand(new ExitCommand("0", "Exit"));
            menu.addCommand(new RunExample("1", ex1.ToString(), ctrl1));
            menu.addCommand(new RunExample("2", ex2.ToString(), ctrl2));

            menu.show();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            IStatement ex1 = new CompoundStatement(new AssignStatement("v", new ConstantExpression(2)),
                                                   new PrintStatement(new VariableExpression("v")));

            IStatement ex2 = new CompoundStatement(new AssignStatement("a", new ArithmeticExpression(new ConstantExpression(2), new
                                                                                                     ArithmeticExpression(new ConstantExpression(3), new ConstantExpression(5), Operation.MULTIPLY), Operation.ADD)),
                                                   new CompoundStatement(new AssignStatement("b", new ArithmeticExpression(new VariableExpression("a"), new
                                                                                                                           ConstantExpression(1), Operation.ADD)), new PrintStatement(new VariableExpression("b"))));

            IStatement ex3 = new CompoundStatement(new AssignStatement("a", new ArithmeticExpression(new ConstantExpression(2), new ConstantExpression(2), Operation.SUBTRACT)),
                                                   new CompoundStatement(new IfStatement(new VariableExpression("a"), new AssignStatement("v", new ConstantExpression(2)),
                                                                                         new AssignStatement("v", new ConstantExpression(3))), new PrintStatement(new VariableExpression("v"))));

            IStatement ex4 = new CompoundStatement(new OpenStatement("var_f", "test1.in"),
                                                   new CompoundStatement(new ReadStatement(new VariableExpression("var_f"), "var_c"),
                                                                         new CompoundStatement(new PrintStatement(new VariableExpression("var_c")),
                                                                                               new CompoundStatement(new IfStatement(new VariableExpression("var_c"),
                                                                                                                                     new CompoundStatement(new ReadStatement(new VariableExpression("var_f"), "var_c"),
                                                                                                                                                           new PrintStatement(new VariableExpression("var_c"))), new PrintStatement(new ConstantExpression(0))),
                                                                                                                     new CloseStatement(new VariableExpression("var_f"))))));

            TextMenu menu = new TextMenu(new MyDictionary <string, Command>(new Dictionary <string, Command>()));

            menu.AddCommand(new ExitCommand("0", "exit"));
            menu.AddCommand(new RunCommand("1", ex1.ToString(), CreateController(ex1, "log1.txt")));
            menu.AddCommand(new RunCommand("2", ex2.ToString(), CreateController(ex2, "log2.txt")));
            menu.AddCommand(new RunCommand("3", ex3.ToString(), CreateController(ex3, "log3.txt")));
            menu.AddCommand(new RunCommand("4", ex4.ToString(), CreateController(ex4, "log4.txt")));

            menu.show();
        }
コード例 #7
0
        public AstPrinterNode Visit(CompoundStatement node)
        {
            var printer = new AstPrinterNode(node.ToString());

            foreach (var stmt in node.Statements)
            {
                printer.AddChild(stmt.Accept(this));
            }

            return(printer);
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            TextMenu textMenu = new TextMenu();

            textMenu.AddCommand(new ExitCommand());

            Statement st1 = new CompoundStatement(
                new CompoundStatement(
                    new AssignStatement("a", new ArithmeticExpression('/', new ConstantExpression(2), new ConstantExpression(0))),
                    new AssignStatement("a", new ConstantExpression(5))),
                new PrintStatement(new VariableExpression("a")));

            ProgramState state1 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st1);

            RepositoryInterface repo1 = new Repository("..\\..\\LogFile1.log");

            repo1.Add(state1);

            Controller ctrl1 = new Controller(repo1);

            textMenu.AddCommand(new RunAllSteps(ctrl1, "1", st1.ToString()));

            Statement st2 = new CompoundStatement(
                new AssignStatement("a", new ConstantExpression(2)),
                new AssignStatement("a", new ConstantExpression(7)));
            ProgramState state2 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st2);

            RepositoryInterface repo2 = new Repository("..\\..\\LogFile2.log");

            repo2.Add(state2);
            Controller ctrl2 = new Controller(repo2);

            textMenu.AddCommand(new RunAllSteps(ctrl2, "2", st2.ToString()));

            Statement st3 = new CompoundStatement(
                new CompoundStatement(
                    new CompoundStatement(
                        new CompoundStatement(
                            new OpenReadFileStatement("example.ex", "f"),
                            new ReadFileStatement("f", "c")),
                        new PrintStatement(new VariableExpression("c"))),
                    new IfStatement(new VariableExpression("c"),
                                    new CompoundStatement(
                                        new ReadFileStatement("f", "c"),
                                        new PrintStatement(new VariableExpression("c"))),
                                    new PrintStatement(new ConstantExpression(0)))),
                new CloseReadFileStatement("f"));

            ProgramState state3 = new ProgramState(new ExecutionStack <Statement>(), new SymbolTable <string, int>(),
                                                   new OutputList <int>(), new FileTable <int, FileDescriptor>(), st3);

            RepositoryInterface repo3 = new Repository("..\\..\\LogFile3.log");

            repo3.Add(state3);
            Controller ctrl3 = new Controller(repo3);

            textMenu.AddCommand(new RunAllSteps(ctrl3, "3", st3.ToString()));

            textMenu.show();
        }