private HashSet <ISymbol> CreateRightRecursiveSymbols( IDottedRuleRegistry dottedRuleRegistry, Dictionary <ISymbol, UniqueList <ISymbol> > symbolPaths) { var hashSet = new HashSet <ISymbol>(); for (var p = 0; p < _productions.Count; p++) { var production = _productions[p]; var position = production.RightHandSide.Count; var completed = dottedRuleRegistry.Get(production, position); var symbolPath = symbolPaths[production.LeftHandSide]; for (var s = position; s > 0; s--) { var preDotSymbol = production.RightHandSide[s - 1]; if (preDotSymbol.SymbolType != SymbolType.NonTerminal) { break; } var preDotNonTerminal = preDotSymbol as INonTerminal; if (symbolPath.Contains(preDotNonTerminal)) { hashSet.Add(production.LeftHandSide); break; } if (!IsTransativeNullable(preDotNonTerminal)) { break; } } } return(hashSet); }
public Grammar( INonTerminal start, IReadOnlyList <IProduction> productions, IReadOnlyList <ILexerRule> ignoreRules, IReadOnlyList <ILexerRule> triviaRules) { _productions = new IndexedList <IProduction>(); _ignores = new IndexedList <ILexerRule>(); _trivia = new IndexedList <ILexerRule>(); _transativeNullableSymbols = new UniqueList <INonTerminal>(); _symbolsReverseLookup = new Dictionary <INonTerminal, UniqueList <IProduction> >(); _lexerRules = new IndexedList <ILexerRule>(); _leftHandSideToProductions = new Dictionary <INonTerminal, List <IProduction> >(); _dottedRuleRegistry = new DottedRuleRegistry(); _symbolPaths = new Dictionary <ISymbol, UniqueList <ISymbol> >(); Start = start; AddProductions(productions ?? EmptyProductionArray); AddIgnoreRules(ignoreRules ?? EmptyLexerRuleArray); AddTriviaRules(triviaRules ?? EmptyLexerRuleArray); _rightRecursiveSymbols = CreateRightRecursiveSymbols(_dottedRuleRegistry, _symbolPaths); FindNullableSymbols(_symbolsReverseLookup, _transativeNullableSymbols); }
public ParseEngine(IGrammar grammar, ParseEngineOptions options) { _dottedRuleRegistry = new GrammarSeededDottedRuleRegistry(grammar); StateFactory = new StateFactory(_dottedRuleRegistry); Options = options; _nodeSet = new ForestNodeSet(); Grammar = grammar; Initialize(); }
public StateFactory(IDottedRuleRegistry dottedRuleRegistry) { DottedRuleRegistry = dottedRuleRegistry; }