/// <summary> /// Constructs a <see cref="SimisJinxFormat"/> from a <see cref="BnfFile"/>. /// </summary> /// <param name="bnf">The <see cref="BnfFile"/> to read Simis Jinx format data from.</param> internal SimisJinxFormat(BnfFile bnf) { Name = bnf.BnfFileName; Extension = bnf.BnfFileExtension; Format = bnf.BnfFileType + bnf.BnfFileTypeVersion; Roots = bnf.BnfFileRoots; Bnf = bnf.Bnf; }
public BnfFile(string fileName) { FileName = fileName; BnfFileRoots = new List <string>(); BnfFileName = ""; BnfFileExtension = ""; BnfFileType = ""; BnfFileTypeVersion = -1; Bnf = new Bnf(FileName); }
private static void BnfParse(Sentence sentence) { var g = Bnf.Grammar(); //var h = g.ToCNF(); // too much memory var earley = new EarleyParser(g); // var cyk = new CykParser(h); var earley2 = new EarleyParser2(g); // var p1 = cyk.ParseGetProbability(sentence); var p2 = earley.ParseGetProbability(sentence); var p3 = earley2.ParseGetProbability(sentence); // Helpers.AssertNear(p1, p2); Helpers.AssertNear(p2, p3); Assert.IsTrue(p2 > 0.0); }
private static void BnfPlay() { var bnf = Bnf.Grammar(); var earley = new EarleyParser2(bnf); var sentence1 = Sentence.FromLetters(Grammars.Properties.Resources.Arithmetic); // var sentence1 = Sentence.FromLetters(Grammars.Properties.Resources.Bnf); // var sentence2 = Sentence.FromLetters("<S> ::= <S> '+' <S>\r\n<S> ::= '1'\r\n"); // if (!sentence1.Equals(sentence2)) { } // int index = sentence1.Zip(sentence2, (c1, c2) => c1 == c2).TakeWhile(b => b).Count() + 1; var sppf = earley.ParseGetForest(sentence1); if (sppf == null) { throw new Exception(); } DotRunner.Run(DotBuilder.GetRawDot(sppf), "bnfPlay"); }