示例#1
0
        public Interpreter(AbstractSyntaxTree ast)
        {
            this.ast = ast;
            rootEnv  = new InterpreterEnvironment();

            // Register built-in functions as symbols in the root environment
            DefineBuiltInFunctions();
        }
示例#2
0
        private static void ProcessFiles(string[] filePaths)
        {
            // Load all the source files
            List <string> sourceFiles = new List <string>();

            foreach (string filePath in filePaths)
            {
                // File exists
                // Read it
                if (File.Exists(filePath))
                {
                    sourceFiles.Add(File.ReadAllText(filePath));
                }
                // File does not exist
                // Print an error and stop execution
                else
                {
                    throw new FatalException($"Source file \"{filePath}\" does not exist");
                }
            }

            // Tokenize all the source code
            IEnumerable <Token> tokens = sourceFiles.SelectMany(x => Lexer.Tokenize(x));

            // No tokens
            // All source files are empty
            if (tokens.Count() == 0)
            {
                throw new FatalException("No source code provided (all source files are empty)");
            }

            // Parse the AST
            AbstractSyntaxTree ast = Parser.ParseAST(tokens);

            // Execute the program based on the parsed AST
            Interpreter inter = new Interpreter(ast);

            inter.Run();
        }