private CflParse Read(ref string input) { if (!string.IsNullOrEmpty(input)) { var match = null as Tuple <string, string[]>; var space = null as Match; var sofar = input; var lexicals = !(space = Grammar.WhiteSpace.Match(sofar)).Success ? (match = Grammar.Lexicon.Match(sofar)).Item2 : null; if (lexicals != null) { if (lexicals.Length > 0) { var productions = new CnfProductions(Grammar, lexicals); var value = match.Item1; input = input.Substring(value.Length); return(new CflParse(productions, value)); } else { input = null; return(Error(sofar)); } } else { input = input.Substring(space.Length); return(WhiteSpace(space.Value)); } } return(null); }
public CnfProductions Lookup(CnfProductions left, CnfProductions right) { var reductions = Binaries. Aggregate ( new CnfProductions(this), (found, production) => { if (left.Contains(production.Rhs1) && right.Contains(production.Rhs2)) { found.Add(production.Lhs); } return(found); } ); return((reductions != null) && (reductions.Count > 0) ? reductions : null); }
public CflParse(CnfProductions productions, CflParse left, CflParse right) : base(left, right) { Productions = productions; }
public CflParse(CnfProductions productions, string token) : this(productions, null, null) { Value = token; }
public CnfGrammar() { Productions = new Dictionary <string, CnfProduction>(); Error = new CnfProductions(this, "Error"); WhiteSpace = GetInsignificantWhiteSpace(); }