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);
 }
예제 #3
0
 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());
        }
예제 #5
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);
        }