Beispiel #1
0
        static void Main(string[] args)
        {
            // Watch for unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            LogManager.Enabled = true;
            LogManager.AttachLogTarget(new ConsoleTarget(Level.Trace));

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintBanner();
            Console.ResetColor();

            if (args.Length < 1 ||
                Path.GetExtension(args[0]) != FileManager.INPUT_FILE_EXTENSION)
            {
                PrintUsage();
                Environment.Exit(1);
            }

            using (FileManager fileManager = new FileManager(args[0]))
            {
                SymbolTable symbolTable = new SymbolTable();
                CodeGeneratorHelper cdh = new CodeGeneratorHelper();
                SyntaxTree syntaxTree;

                if (RunPhase_1(fileManager, symbolTable, out syntaxTree) &&
                    RunPhase_2(syntaxTree, symbolTable, cdh) &&
                    RunPhase_3(fileManager, syntaxTree, symbolTable, cdh))
                {
                    Logger.Info("Compilation successful.");
                }
                fileManager.FinalizeListing();
            }
        }
Beispiel #2
0
        static bool RunPhase_3(FileManager fileManager, SyntaxTree syntaxTree, SymbolTable symbolTable, CodeGeneratorHelper cdh)
        {
            fileManager.InitializeOutputFile();
            syntaxTree.GenerateCode(fileManager, symbolTable, cdh);
            fileManager.FinalizeOutputFile();

            return true;
        }
Beispiel #3
0
 static bool RunPhase_2(SyntaxTree syntaxTree, SymbolTable symbolTable, CodeGeneratorHelper storage)
 {
     if (syntaxTree.CheckForSemanticErrors(symbolTable) &&
         syntaxTree.AllocateMemoryForConstants(storage) &&
         syntaxTree.AllocateMemoryForVariables(storage))
     {
         return true;
     }
     return false;
 }