Esempio n. 1
0
        private static bool RunCode(SourceCodeFile file)
        {
            var tokens = Lexer.ScanTokens(file);

            if (Context.Instance.ErrorsReported > 0)
            {
                return(true);
            }

            var ast = Parser.Parse(tokens);

            if (Context.Instance.ErrorsReported > 0)
            {
                return(true);
            }

            // TODO: Scanning on demand.
            tokens.Clear();

            var byteCode = Compiler.Compile(ast);

            if (Context.Instance.ErrorsReported > 0)
            {
                return(true);
            }

#if DEBUG
            Disassembler.Disassemble(byteCode.ToArray());
            Console.WriteLine("----------------------------------------");
#endif

            VirtualMachine.Execute(byteCode);
            return(false);
        }
Esempio n. 2
0
        private static List <Statement> AnalyzeCode(SourceCodeFile file)
        {
            var tokens = Lexer.ScanTokens(file);

            if (Context.Instance.ErrorsReported > 0)
            {
                return(null);
            }

            var ast = Parser.Parse(tokens);

            return(Context.Instance.ErrorsReported == 0 ? ast : null);
        }