public Lr0Item(int id, GrammarReduction reduction, int index) { if (reduction == null) throw new ArgumentNullException(nameof(reduction)); Id = id; Reduction = reduction; Index = index; }
protected Lr0Item CreateLr0Item(GrammarReduction reduction, int index) { return new Lr0Item(_lr0ItemCounter++, reduction, index); }
protected void AddReductions(GrammarDefinition root) { // Avoid infinite recursion. if (GrammarReductionsMapping.ContainsKey(root)) return; _allElements.Add(root); var reductions = GrammarReductionsMapping[root] = new List<GrammarReduction>(); // For each sequence in the grammar switch, create a new reduction with // its own LR(0) kernels. foreach (var sequence in root.Rule.Switch) { var reduction = new GrammarReduction(root, sequence); reductions.Add(reduction); AllReductions.Add(reduction); for (int index = 0; index < sequence.Count; index++) { var element = sequence[index]; reduction.Lr0Items.Add(CreateLr0Item(reduction, index)); // The sequence can hold grammar definitions as well. // Therefore we make a recursive loop to handle those. var definition = element as GrammarDefinition; if (definition != null) AddReductions(definition); else _allElements.Add(element); } reduction.Lr0Items.Add(CreateLr0Item(reduction, sequence.Count)); } }
public ReduceParserAction(GrammarReduction reduction) { Reduction = reduction; }