Exemplo n.º 1
0
 public Lr0Item(int id, GrammarReduction reduction, int index)
 {
     if (reduction == null)
         throw new ArgumentNullException(nameof(reduction));
     Id = id;
     Reduction = reduction;
     Index = index;
 }
Exemplo n.º 2
0
 protected Lr0Item CreateLr0Item(GrammarReduction reduction, int index)
 {
     return new Lr0Item(_lr0ItemCounter++, reduction, index);
 }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
 public ReduceParserAction(GrammarReduction reduction)
 {
     Reduction = reduction;
 }