示例#1
0
        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 });
        }
示例#2
0
        private void Compile()
        {
            Builder builder = new Builder();

            try
            {
                var assembly = builder.Build(genLexer.Text, genParser.Text);

                var parserType = assembly.GetType($"Xxx.{_grammarName}Parser");
                _parser = Activator.CreateInstance(parserType);
                _parseMethod = parserType.GetMethod("Parse");

                var walkerType = assembly.GetType("Xxx.Walker");
                _walker = Activator.CreateInstance(walkerType);
                _nodesToStringMethod = walkerType.GetMethod("NodesToString");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }