private void AddRule(ProductionRule rule) { //ASSUMPTION: LHS of first rule in grammar file is root symbol if (_rules.Count == 0) { _rootSymbol = rule.LHS; _rhsIndex.Add(_rootSymbol.Text, new List <ProductionRule>()); } _rules.Add(rule); AddToLhsIndex(rule); AddToRhsIndex(rule); if (rule.RHS.Length == 1 && rule.RHS[0].Type == SymbolType.Terminal) { AddToTerminalIndex(rule); } if (rule.RHS[0].Type == SymbolType.Nonterminal) { AddToNonterminalIndex(rule); } }
private void AddToLhsIndex(ProductionRule rule) { if (!_lhsIndex.ContainsKey(rule.LHS.Text)) _lhsIndex.Add(rule.LHS.Text, new List<Symbol[]>()); _lhsIndex[rule.LHS.Text].Add(rule.RHS); }
private void AddToLhsIndex(ProductionRule rule) { if (!_lhsIndex.ContainsKey(rule.LHS.Text)) { _lhsIndex.Add(rule.LHS.Text, new List <Symbol[]>()); } _lhsIndex[rule.LHS.Text].Add(rule.RHS); }
private void AddToNonterminalIndex(ProductionRule rule) { if (!_nonterminalIndex.ContainsKey(rule.RHS[0].Text)) { _nonterminalIndex.Add(rule.RHS[0].Text, new List <ProductionRule>()); } _nonterminalIndex[rule.RHS[0].Text].Add(rule); }
private void AddToRhsIndex(ProductionRule rule) { if (!_rhsIndex.ContainsKey(rule.RHS[0].Text)) { _rhsIndex.Add(rule.RHS[0].Text, new List <ProductionRule>()); } _rhsIndex[rule.RHS[0].Text].Add(rule); }
private void ParseRule(string line) { ProductionRule rule = new ProductionRule(line); // Add the inverse rule for any binary rule if (rule.RHS.Length > 1) { ProductionRule ruleInverse = new ProductionRule(line); ruleInverse.FlipRHS(); rule.ScaleProbability(RULE_SCALE); ruleInverse.ScaleProbability(INVERSE_RULE_SCALE); AddRule(ruleInverse); } AddRule(rule); }
private void AddRule(ProductionRule rule) { //ASSUMPTION: LHS of first rule in grammar file is root symbol if (_rules.Count == 0) { _rootSymbol = rule.LHS; _rhsIndex.Add(_rootSymbol.Text, new List<ProductionRule>()); } _rules.Add(rule); AddToLhsIndex(rule); AddToRhsIndex(rule); if (rule.RHS.Length == 1 && rule.RHS[0].Type == SymbolType.Terminal) AddToTerminalIndex(rule); if (rule.RHS[0].Type == SymbolType.Nonterminal) AddToNonterminalIndex(rule); }
private void AddToNonterminalIndex(ProductionRule rule) { if (!_nonterminalIndex.ContainsKey(rule.RHS[0].Text)) _nonterminalIndex.Add(rule.RHS[0].Text, new List<ProductionRule>()); _nonterminalIndex[rule.RHS[0].Text].Add(rule); }
private void AddToRhsIndex(ProductionRule rule) { if (!_rhsIndex.ContainsKey(rule.RHS[0].Text)) _rhsIndex.Add(rule.RHS[0].Text, new List<ProductionRule>()); _rhsIndex[rule.RHS[0].Text].Add(rule); }