static void Main(string[] args) { var result = Parser.Default.ParseArguments <Options>(args); result.WithParsed(o => { try { var source = new Source(new StreamReader(o.SourceFilePath)); source.AddMessageListener(new SourceMessageListener()); var parser = FrontendFactory.CreateParser("pascal", "top-down", source); parser.AddMessageListener(new ParserMessageListener()); var backend = BackendFactory.CreateBackend(o.Operation); backend.AddMessageListener(new BackendMessageListener()); parser.Parse(); source.Close(); var iCode = parser.IntermediateCode; var symTab = parser.SymbolTable; backend.Process(iCode, symTab); } catch (Exception e) { Console.WriteLine(e); } }); }
public void CreateParser_PascalForTopDownParser() { var frontendFactory = new FrontendFactory(Mock.Of <IMessageHandler>(), Mock.Of <ITimeProvider>()); var parser = frontendFactory.CreateParser("pascal", "top-down", Mock.Of <ISource>()); parser.Should().BeOfType(typeof(PascalTopDownParser)); }
private Backend backend; // backend public Pascal(string operation, string filePath, string flags) { try { bool intermediate = flags.IndexOf('i') > -1; bool xref = flags.IndexOf('x') > -1; source = new Source(new StreamReader(filePath)); source.addMessageListener(new SourceMessageListener()); parser = FrontendFactory.createParser("Pascal", "top-down", source); parser.addMessageListener(new ParserMessageListener()); backend = BackendFactory.createBackend(operation); backend.addMessageListener(new BackendMessageListener()); parser.parse(); source.close(); iCode = parser.iCode; symbolTableStack = Parser.symbolTableStack; if (xref) { CrossReferencer crossReferencer = new CrossReferencer(); crossReferencer.Print(symbolTableStack); } if (intermediate) { ParseTreePrinter treePrinter = new ParseTreePrinter(Console.Out); treePrinter.Print(iCode); } backend.process(iCode, symbolTableStack); } catch (Exception e) { Console.WriteLine("***** Internal translator error. *****"); Console.WriteLine(e.StackTrace); } }
public void CreateParser_ThrowsExceptionForUnknownType() { var frontendFactory = new FrontendFactory(Mock.Of <IMessageHandler>(), Mock.Of <ITimeProvider>()); frontendFactory.CreateParser("pascal", "bottom-up", Mock.Of <ISource>()); }
public void CreateParser_ThrowsExceptionForUnknownLanguage() { var frontendFactory = new FrontendFactory(Mock.Of <IMessageHandler>(), Mock.Of <ITimeProvider>()); frontendFactory.CreateParser("ruby", "top-down", Mock.Of <ISource>()); }