public ParseState this[ParseState current, BnfTerm symbol] { get { Dictionary<BnfTerm, ParseState> transition; if (!transitionRules.TryGetValue(current, out transition)) { if (!allStates.Contains(current)) throw new ParseException("No such state"); else return null; } ParseState next; if (!transition.TryGetValue(symbol, out next)) { HashSet<Terminal> expected = new HashSet<Terminal>(); foreach (var item in current) { if (item.Position < item.Production.Body.Length) expected.UnionWith(grammar.GetFirstSet(item.Production.Body[item.Position])); } throw new ParseException("Invalid symbol " + symbol.ToString() + " expected one of [" + String.Join(", ", expected.Select(a => a.Name)) + "]"); } return next; } }
public static ParseState Goto(this IEnumerable<Item> state, BnfTerm symbol, Grammar grammar) { HashSet<Item> items = new HashSet<Item>(); foreach (var item in state) { if (item.Production.Body.Length == item.Position) continue; BnfTerm term = item.Production.Body[item.Position]; if (term.Equals(symbol)) items.Add(new Item(item.Production, item.Position + 1)); } return items.Closure(grammar); }
public static ParseState Goto(this IEnumerable <Item> state, BnfTerm symbol, Grammar grammar) { HashSet <Item> items = new HashSet <Item>(); foreach (var item in state) { if (item.Production.Body.Length == item.Position) { continue; } BnfTerm term = item.Production.Body[item.Position]; if (term.Equals(symbol)) { items.Add(new Item(item.Production, item.Position + 1)); } } return(items.Closure(grammar)); }
public static ConcatenationRule Plus(BnfTerm left, BnfTerm right) { return(new ConcatenationRule(left, right)); }
public ParseStateTransition(ParseState start, BnfTerm trigger, ParseState end) { Start = start; Trigger = trigger; End = end; }
public static ConcatenationRule Plus(BnfTerm left, BnfTerm right) { return new ConcatenationRule(left, right); }