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(); } }
public Scanner(FileManager fileManager, SymbolTable symbolTable) { this._fileManager = fileManager; this._symbolTable = symbolTable; this._specialChars = this._symbolTable.GetSpecialCharList(); this._peekSymbol = AdvanceSymbol(); }
public GeneratedScannerWrapper(FileManager fileManager, SymbolTable symbolTable) { this._scanner = new NaseScanner(fileManager.Input); this._scanner.SymbolTable = symbolTable; this._symbolTable = symbolTable; this._peekSymbol = (Symbol)this._scanner.yylex(); if (this._peekSymbol == Symbol.INTEGER_LITERAL_SYMBOL || this._peekSymbol == Symbol.IDENTIFIER_SYMBOL) { UpdateSymbol(); } }
public Parser(SymbolTable symbolTable, IScanner scanner) { this._symbolTable = symbolTable; this._scanner = scanner; }
static bool RunPhase_1(FileManager fileManager, SymbolTable symbolTable, out SyntaxTree syntaxTree) { if (false) { IScanner scanner = new GeneratedScannerWrapper(fileManager, symbolTable); //IScanner scanner = new Scanner(fileManager, symbolTable); Parser parser = new Parser(symbolTable, scanner); bool result = parser.ParseProgramm(out syntaxTree); Logger.Debug(symbolTable.DumpSymbolTable()); Logger.Debug(syntaxTree.DumpTreeTable()); return result; } else { NaseScanner scanner = new NaseScanner(fileManager.Input); scanner.SymbolTable = symbolTable; NaseParser parser = new NaseParser(scanner, symbolTable); bool result = parser.Parse(); syntaxTree = parser.SyntaxTree; if (result) { Logger.Debug(symbolTable.DumpSymbolTable()); Logger.Debug(syntaxTree.DumpTreeTable()); } return result; } }
static bool RunPhase_3(FileManager fileManager, SyntaxTree syntaxTree, SymbolTable symbolTable, CodeGeneratorHelper cdh) { fileManager.InitializeOutputFile(); syntaxTree.GenerateCode(fileManager, symbolTable, cdh); fileManager.FinalizeOutputFile(); return true; }
static bool RunPhase_2(SyntaxTree syntaxTree, SymbolTable symbolTable, CodeGeneratorHelper storage) { if (syntaxTree.CheckForSemanticErrors(symbolTable) && syntaxTree.AllocateMemoryForConstants(storage) && syntaxTree.AllocateMemoryForVariables(storage)) { return true; } return false; }