private static void DevelopAnnotations() { var sw = Stopwatch.StartNew(); var input = Sentence.FromLetters(Grammars.Properties.Resources.Arithmetic_annotated); var inputWithoutLayout = Ebnf.RemoveLayout(input, out _); var grammar = Ebnf.GrammarSyntax(); var parser = new EarleyParser2(grammar); var sppf = parser.ParseGetForest(inputWithoutLayout); if (sppf == null) { throw new Exception(); } var ms1 = sw.Elapsed.TotalMilliseconds; Console.WriteLine("Parse: {0:0.#}ms", ms1); DotRunner.Run(DotBuilder.GetRawDot(sppf), "annotations"); var traversal = new Traversal(sppf, grammar); var resCollection = traversal.Traverse(); if (resCollection.Count() > 1) { throw new Exception("ambiguous"); } var res = resCollection.Single(); Console.WriteLine(res); }
private static void EbnfPlay() { var input = Sentence.FromLetters(Grammars.Properties.Resources.Ebnf_bench); Sentence inputNoLayout = Ebnf.RemoveLayout(input, out var layoutSppf); //DotRunner.Run(DotBuilder.GetRawDot(layoutSppf), "arithmetic_ebnf_layout"); Console.WriteLine(inputNoLayout.AsTerminals()); var layoutGrammar = Ebnf.GrammarSyntax(); var earley = new EarleyParser2(layoutGrammar); var sppf = earley.ParseGetForest(inputNoLayout); if (sppf == null) { throw new Exception(); } //DotRunner.Run(DotBuilder.GetRawDot(sppf), "arithmetic_ebnf"); //var traversal = new Traversal(sppf, input, layoutGrammar); //var result = traversal.Traverse(); //if (result.Count() != 1) { // throw new Exception(); //} //var inputNoLayout = new Sentence((List<Terminal>)result.First().Payload); //return inputNoLayout; //Console.WriteLine(inputNoLayout); }
private static void EbnfParse(Sentence sentence) { var noLayoutSentence = Ebnf.RemoveLayout(sentence, out var layoutSppf); var g = Ebnf.GrammarSyntax(); //var earley = new EarleyParser(g); var earley2 = new EarleyParser2(g); //var sppf1 = earley.ParseGetForest(noLayoutSentence); //Assert.IsNotNull(sppf1); var sppf2 = earley2.ParseGetForest(noLayoutSentence); Assert.IsNotNull(sppf2); }
private static void EbnfBench() { var tup = EbnfBenchLayout(); var inputNoLayout = tup.Item1; var ms1 = tup.Item2; var sw = Stopwatch.StartNew(); var grammar = Ebnf.GrammarSyntax(); var earley = new EarleyParser2(grammar); var sppf = earley.ParseGetForest(inputNoLayout); var ms2 = sw.Elapsed.TotalMilliseconds; if (sppf == null) { throw new Exception(); } Console.WriteLine("Parse: {0:0.#}ms", ms2); Console.WriteLine("Total: {0:0.#}ms", ms1 + ms2); }