Пример #1
0
        public static IodineModule CompileModuleFromSource(ErrorLog errorLog, string source)
        {
            Tokenizer lexer = new Tokenizer (errorLog, source);
            TokenStream tokenStream = lexer.Scan ();
            if (errorLog.ErrorCount > 0)
                return null;
            Parser parser = new Parser (tokenStream);
            AstRoot root = parser.Parse ();
            if (errorLog.ErrorCount > 0)
                return null;
            SemanticAnalyser analyser = new SemanticAnalyser (errorLog);
            SymbolTable symbolTable = analyser.Analyse (root);
            if (errorLog.ErrorCount > 0)
                return null;
            IodineCompiler compiler = new IodineCompiler (errorLog, symbolTable, "");
            IodineModule module = new IodineModule ("");

            compiler.CompileAst (module, root);
            if (errorLog.ErrorCount > 0)
                return null;
            return module;
        }
Пример #2
0
 public static Parser CreateParser(IodineContext context, SourceUnit source)
 {
     Tokenizer tokenizer = new Tokenizer (context.ErrorLog, source.Text, source.Path ?? "");
     return new Parser (tokenizer.Scan ());
 }
Пример #3
0
 public static IodineModule CompileModule(ErrorLog errorLog, string file)
 {
     if (FindModule (file) != null) {
         Tokenizer lexer = new Tokenizer (errorLog, File.ReadAllText (FindModule (file)), file);
         TokenStream tokenStream = lexer.Scan ();
         if (errorLog.ErrorCount > 0)
             return null;
         Parser parser = new Parser (tokenStream);
         AstRoot root = parser.Parse ();
         if (errorLog.ErrorCount > 0)
             return null;
         SemanticAnalyser analyser = new SemanticAnalyser (errorLog);
         SymbolTable symbolTable = analyser.Analyse (root);
         if (errorLog.ErrorCount > 0)
             return null;
         IodineCompiler compiler = new IodineCompiler (errorLog, symbolTable, Path.GetFullPath (file));
         IodineModule module = new IodineModule (Path.GetFileNameWithoutExtension (file));
         compiler.CompileAst (module, root);
         if (errorLog.ErrorCount > 0)
             return null;
         return module;
     } else {
         errorLog.AddError (ErrorType.ParserError, new Location (0, 0, file),
             "Could not find module {0}", file);
         return null;
     }
 }