public void BasicErrorHandlerUsage()
        {
            ErrorHandler errorHandler = new ErrorHandler();
            errorHandler.errorOccured("Test error 1.", Error.ErrorType.UNDEFINED);
            errorHandler.errorOccured("Test error 2.", Error.ErrorType.SYNTAX, 10, 20);

            Assert.AreEqual(2, errorHandler.getErrors().Count);
        }
Esempio n. 2
0
        private void construct(TextReader stream, FunctionDefinition[] functionDefinitions, VariableDefinition[] variableDefinitions)
        {
            Debug.Assert(stream != null);
            Debug.Assert(functionDefinitions != null);

            m_compileTimeErrorHandler = new ErrorHandler();
            m_runtimeErrorHandler = new ErrorHandler();
            m_tokens = Tokenize(stream);
            m_ast = Parse(m_tokens);
            if(m_compileTimeErrorHandler.getErrors().Count > 0) { m_compileTimeErrorHandler.printErrorsToConsole(); return; }

            AddLocalVariables(m_ast, variableDefinitions);
            ExternalFunctionCreator externalFunctionCreator = AddExternalFunctions(functionDefinitions, m_ast);
            Scope globalScope = CreateScopeTree(m_ast);

            if(m_compileTimeErrorHandler.getErrors().Count > 0) { m_compileTimeErrorHandler.printErrorsToConsole(); return; }

            m_interpreter = new InterpreterTwo(m_ast, globalScope, m_runtimeErrorHandler, externalFunctionCreator);
            m_started = false;

            //PaintAST(m_ast);
        }
 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 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);
        }