public void BasicEvaluation()
        {
            Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
            List<Token> tokens = tokenizer.process(File.OpenText("code9.txt"));

            Parser parser = new Parser(tokens, s_errorHandler);
            parser.process();

            AST root = parser.getAST();
            AST expressionTree = root.getChild(0).getChild(0);

            ExpressionEvaluator e1 = new ExpressionEvaluator(expressionTree);
            Assert.AreEqual(26, e1.getValue());
        }
Ejemplo n.º 2
0
 private AST Parse(List<Token> tokens)
 {
     Parser parser = new Parser(tokens, m_compileTimeErrorHandler);
     parser.process();
     AST ast = parser.getAST();
     return ast;
 }
        public void HandleNegativeNumbers()
        {
            Tokenizer tokenizer = new Tokenizer(s_errorHandler, true);
            List<Token> tokens = tokenizer.process(File.OpenText("code10.txt"));

            Parser parser = new Parser(tokens, s_errorHandler);
            parser.process();

            AST root = parser.getAST();
            AST expressionTree = root.getChild(0).getChild(0);

            ExpressionEvaluator e = new ExpressionEvaluator(expressionTree);
            Assert.AreEqual(-5, e.getValue());
        }
Ejemplo n.º 4
0
        public void TooManyTokensInStatements()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            Tokenizer tokenizer = new Tokenizer(errorHandler, true);
            List<Token> tokens = tokenizer.process(File.OpenText("code18.txt"));
            Parser parser = new Parser(tokens, errorHandler);
            parser.process();
            errorHandler.printErrorsToConsole();

            Assert.AreEqual(3, errorHandler.getErrors().Count);
        }