Пример #1
0
        static void Run(string text, Environment environment, IErrorReporter errors)
        {
            var scanner = new Scanner(text, errors);
            var tokens  = scanner.ScanTokens();

            if (errors.Count == 0)
            {
                var parser  = new Parser(tokens, errors);
                var program = parser.Parse();
                if (errors.Count == 0)
                {
                    Console.WriteLine(ProgramPrinter.Print(program));

                    // TODO: Feels kinda weird to be creating the interpreter
                    // before the resolver. Maybe there's an intermediate data structure
                    // that could be passed from one to the other?
                    var interpreter = new Interpreter(environment, errors);
                    var resolver    = new Resolver(interpreter, errors);
                    resolver.Resolve(program);

                    if (errors.Count == 0)
                    {
                        interpreter.Interpret(program);
                    }
                }
            }
        }
Пример #2
0
        public static string Print(List <Stmt> program)
        {
            var printer = new ProgramPrinter();

            return(printer.PrintInner(program));
        }