Ejemplo n.º 1
0
        static int Run(string source)
        {
            var errorState = new ErrorState();
            var lexer      = new Lexer(source, errorState);
            var tokens     = lexer.Tokenize();
            var parser     = new Parser(tokens, errorState);
            var statements = parser.Parse();

            if (errorState.HasErrors)
            {
                ErrorReporter.ReportSyntaxErrors(errorState);
                return(2);
            }

            var resolver = new Resolver(_interpreter, errorState);

            resolver.Resolve(statements);

            if (errorState.HasErrors)
            {
                ErrorReporter.ReportSyntaxErrors(errorState);
                return(2);
            }

            _interpreter.Interpret(statements);
            return(_interpreter.RuntimeExceptionThrown ? 3 : 1);
        }