Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string codeExamples = File.ReadAllText("CodeExamples.txt");
            Lexer  lexer        = new Lexer(codeExamples);
            Parser parser       = new Parser(lexer);

            SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(parser);

            semanticAnalyzer.Analyze();
            Interpreter interpreter = new Interpreter(semanticAnalyzer);

            interpreter.Interpret();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compiles the source code of the given filepath.
        /// </summary>
        /// <param name="filePath">File path.</param>
        public SyntaxTree Compile(string filePath)
        {
            Init(filePath);                                             // initialize the compiler
            SyntaxTree syntaxTree = this.parser.Parse();                // parse the source code into an AST

            // if any errors were found during the parse, return null
            if (lexicalAndSyntacticalErrors())
            {
                return(null);
            }

            // perform semantic analysis
            semanticAnalyzer = new SemanticAnalyzer(syntaxTree, symbolTable);

            semanticAnalyzer.Analyze();

            // return the AST
            return(syntaxTree);
        }