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());
        }
示例#2
0
 List<Token> Tokenize(TextReader stream)
 {
     Tokenizer tokenizer = new Tokenizer(m_compileTimeErrorHandler, true);
     return tokenizer.process(stream);
 }
 public void UnrecognizedChar()
 {
     TextReader reader = File.OpenText("code17.txt");
     ErrorHandler errorHandler = new ErrorHandler();
     Tokenizer tokenizer = new Tokenizer(errorHandler, true);
     tokenizer.process(File.OpenText("code17.txt"));
     List<Error> errors = errorHandler.getErrors();
     Assert.AreEqual(3, errors.Count);
 }
        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());
        }
        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);
        }