/*public IEnumerable<string> ReportProductions() * { * if (productions == null) * return Enumerable.Empty<string>(); * else * return productions.Report(); * }*/ public string WriteReports(string prefix) { StringExtensions.ToTextFile(prefix + "dfa.out.txt", reportDfa()); // usually huge output! StringExtensions.ToTextFile(prefix + "first_sets.out.txt", reportFirstSets()); StringExtensions.ToTextFile(prefix + "cover_sets.out.txt", reportCoverSets()); StringExtensions.ToTextFile(prefix + "follow_sets.out.txt", reportFollowSets()); StringExtensions.ToTextFile(prefix + "horizon_sets.out.txt", reportHorizonSets()); StringExtensions.ToTextFile(prefix + "errors.out.txt", GrammarErrors.Select(it => it.ToString()) .Concat("") .Concat("") .Concat(BriefDfa())); StringExtensions.ToTextFile(prefix + "warnings.out.txt", GrammarWarnings); StringExtensions.ToTextFile(prefix + "information.out.txt", GrammarInformation); StringExtensions.ToTextFile(prefix + "action_table_info.out.csv", new string[] { this.actionTableSchemeInfo() }); StringExtensions.ToTextFile(prefix + "action_table.out.csv", new string[] { this.actionTableScheme() }); StringExtensions.ToTextFile(prefix + "edges_table.out.csv", new string[] { edgesTableScheme() }); StringExtensions.ToTextFile(prefix + "stats.out.txt", new string[] { "Action table fill ratio: " + actionTableFillRatio() }); return("Detailed reports written in \"" + prefix + "*\" files"); }
public IEnumerable <string> ReportGrammarProblems() { return(GrammarErrors.Select(it => it.ToString()).Concat(GrammarWarnings)); }
public IEnumerable <string> BriefDfa() { return(reportDfa(GrammarErrors.Select(it => it.NfaStateIndices).Flatten().Distinct())); }
public bool IsMatch(ref List <Token> tokens, Word parentWord = null) { #region Liść if (Words == null) { if (tokens.Any() == false) { if (canBeEmpty) { return(true); } return(false); } var token = tokens.First(); if (token != null && token.Name == "fr0m") { } // change to names digits and so on if (token.userMade == true && Name == "userMade") { Debug.WriteLine(token.Index + "\tin: <" + token.Name + ">\t expected: <" + Name + ">\t true"); tokens.RemoveAt(0); return(true); } if (token.Name == Name) { Debug.WriteLine(token.Index + "\tin: <" + token.Name + ">\t expected: <" + Name + ">\t true"); tokens.RemoveAt(0); return(true); } else { Debug.WriteLine(token.Index + "\tin: <" + token.Name + ">\t expected: <" + Name + ">\t false"); //if(Name != null) //GrammarErrors.Add(new GrammarError(token, Name +"2")); if (canBeEmpty) { return(true); } return(false); } } #endregion #region Rekurencja var alternatives = Words; foreach (var sequence in alternatives) { var sequenceMatch = false; var tokensCopy = new List <Token>(); tokensCopy.AddRange(tokens); #region Pętla if (loop) { var loops = 0; var continueLoop = true; int done = 0; var tokensInLoop = new List <Token>(); while (continueLoop) { tokensInLoop.Clear(); tokensInLoop.AddRange(tokensCopy); var loopSexentce = new List <Word>(sequence); for (int i = 0; i < loops; i++) { loopSexentce.AddRange(sequence); } done = 0; foreach (var word in loopSexentce) { if (word.IsMatch(ref tokensInLoop, this) == false) { if (loops >= 1) { sequenceMatch = true; continueLoop = false; continue; } else { if (loopWithoutAnyWords && loops == 0) { sequenceMatch = true; continueLoop = false; continue; } if (tokensInLoop.Any() && word.Name != null) { GrammarErrors.Add(new GrammarError(tokensInLoop.First(), word.Name + "1")); } sequenceMatch = false; continueLoop = false; break; } } done++; } loops++; } if (sequenceMatch) { if ((done % sequence.Count()) == 0) { if (tokensCopy.Count() >= sequence.Count()) { tokensCopy.RemoveRange(0, sequence.Count()); } tokensCopy = tokensInLoop; } else { var take = ((int)(((float)done) / ((float)sequence.Count()))) * sequence.Count(); tokensCopy.RemoveRange(0, take); } tokens = tokensCopy; //GrammarErrors.Clear(); return(true); } } #endregion else { foreach (var word in sequence) { if (word.IsMatch(ref tokensCopy, this) == false) { if (tokensCopy.Any() && word.Name != null) { GrammarErrors.Add(new GrammarError(tokensCopy.First(), word.Name)); } sequenceMatch = false; break; } else { GrammarErrors.Clear(); sequenceMatch = true; } } } if (sequenceMatch) { GrammarErrors.Clear(); tokens = tokensCopy; return(true); } } #endregion return(false); }