private void Build() { genGrammar.Text = ""; genLexer.Text = ""; genParser.Text = ""; Parser parser = new Parser(); Generator generator = new Generator(); Node<NodeType> node; try { node = parser.Parse(grammarText.Text); Grammar grammar = generator.BuildGrammar(node); _grammarName = grammar.Name; RefreshGrammar(grammar); genLexer.Text = generator.GenerateLexer(grammar); genParser.Text = generator.GenerateParser(grammar); Compile(); } catch (Exception exception) { _parser = null; _parseMethod = null; MessageBox.Show(exception.Message); } }
private string GenerateAndBuildParser(Grammar grammar, string text) { Generator generator = new Generator(); Builder builder = new Builder(); string lexerDef = generator.GenerateLexer(grammar); string parserDef = generator.GenerateParser(grammar); var assembly = builder.Build(lexerDef, parserDef); object parser = Activator.CreateInstance(assembly.GetType("Xxx.Parser")); object walker = Activator.CreateInstance(assembly.GetType("Xxx.Walker")); var node = parser.GetType().GetMethod("Parse").Invoke(parser, new object[] { text }); return (string)walker.GetType().GetMethod("NodesToString").Invoke(walker, new[] { node }); }