public LR0Item(int id, Production production, int position, GrammarHintList hints)
 {
     ID         = id;
     Production = production;
     Position   = position;
     Hints      = hints;
     _hashCode  = ID.ToString().GetHashCode();
 }
Exemplo n.º 2
0
 public LR0Item(int id, Production production, int position, GrammarHintList hints)
 {
     ID         = id;
     Production = production;
     Position   = position;
     Current    = (Position < Production.RValues.Count) ? Production.RValues[Position] : null;
     if (hints != null)
     {
         Hints.AddRange(hints);
     }
     _hashCode = ID.ToString().GetHashCode();
 }//method
Exemplo n.º 3
0
        private Production CreateProduction(NonTerminal lvalue, BnfTermList operands)
        {
            Production      prod  = new Production(lvalue);
            GrammarHintList hints = null;

            //create RValues list skipping Empty terminal and collecting grammar hints
            foreach (BnfTerm operand in operands)
            {
                if (operand == Grammar.CurrentGrammar.Empty)
                {
                    continue;
                }
                //Collect hints as we go - they will be added to the next non-hint element
                GrammarHint hint = operand as GrammarHint;
                if (hint != null)
                {
                    if (hints == null)
                    {
                        hints = new GrammarHintList();
                    }
                    hints.Add(hint);
                    continue;
                }
                //Check if it is a Terminal or Error element
                Terminal t = operand as Terminal;
                if (t != null)
                {
                    prod.Flags |= ProductionFlags.HasTerminals;
                    if (t.Category == TokenCategory.Error)
                    {
                        prod.Flags |= ProductionFlags.IsError;
                    }
                }
                //Add the operand info and LR0 Item
                LR0Item item = new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints);
                prod.LR0Items.Add(item);
                prod.RValues.Add(operand);
                hints = null;
            }//foreach operand
            //set the flags
            if (prod.RValues.Count == 0)
            {
                prod.Flags |= ProductionFlags.IsEmpty;
            }
            //Add final LRItem
            prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints));
            return(prod);
        }
        public GrammarHintList GetHints(HintType hintType)
        {
            var result = new GrammarHintList();

            foreach (var item in this)
            {
                if (item.Core.HasHints())
                {
                    foreach (var hint in item.Core.Hints)
                    {
                        if (hint.HintType == hintType)
                        {
                            result.Add(hint);
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        private Production CreateProduction(NonTerminal lvalue, BnfTermList operands)
        {
            Production      prod  = new Production(lvalue);
            GrammarHintList hints = null;

            //create RValues list skipping Empty terminal and collecting grammar hints
            foreach (BnfTerm operand in operands)
            {
                if (operand == _grammar.Empty)
                {
                    continue;
                }
                //Collect hints as we go - they will be added to the next non-hint element
                GrammarHint hint = operand as GrammarHint;
                if (hint != null)
                {
                    if (hints == null)
                    {
                        hints = new GrammarHintList();
                    }
                    hints.Add(hint);
                    continue;
                }
                //Add the operand and create LR0 Item
                prod.RValues.Add(operand);
                prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count - 1, hints));
                hints = null;
            }//foreach operand
            //set the flags
            if (prod.RValues.Count == 0)
            {
                prod.Flags |= ProductionFlags.IsEmpty;
            }
            //Add final LRItem
            ComputeProductionFlags(prod);
            prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints));
            return(prod);
        }
Exemplo n.º 6
0
 private Production CreateProduction(NonTerminal lvalue, BnfTermList operands)
 {
     Production prod = new Production(lvalue);
       GrammarHintList hints = null;
       //create RValues list skipping Empty terminal and collecting grammar hints
       foreach (BnfTerm operand in operands) {
     if (operand ==  _grammar.Empty)
       continue;
     //Collect hints as we go - they will be added to the next non-hint element
     GrammarHint hint = operand as GrammarHint;
     if (hint != null) {
       if (hints == null) hints = new GrammarHintList();
       hints.Add(hint);
       continue;
     }
     //Add the operand and create LR0 Item
     prod.RValues.Add(operand);
     prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count - 1, hints));
     hints = null;
       }//foreach operand
       //set the flags
       if (prod.RValues.Count == 0)
     prod.Flags |= ProductionFlags.IsEmpty;
       //Add final LRItem
       ComputeProductionFlags(prod);
       prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints));
       return prod;
 }
Exemplo n.º 7
0
 private Production CreateProduction(NonTerminal lvalue, BnfTermList operands)
 {
     Production prod = new Production(lvalue);
       GrammarHintList hints = null;
       //create RValues list skipping Empty terminal and collecting grammar hints
       foreach (BnfTerm operand in operands) {
     if (operand == Grammar.CurrentGrammar.Empty)
       continue;
     //Collect hints as we go - they will be added to the next non-hint element
     GrammarHint hint = operand as GrammarHint;
     if (hint != null) {
       if (hints == null) hints = new GrammarHintList();
       hints.Add(hint);
       continue;
     }
     //Check if it is a Terminal or Error element
     Terminal t = operand as Terminal;
     if (t != null) {
       prod.Flags |= ProductionFlags.HasTerminals;
       if (t.Category == TokenCategory.Error) prod.Flags |= ProductionFlags.IsError;
     }
     //Add the operand info and LR0 Item
     LR0Item item = new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints);
     prod.LR0Items.Add(item);
     prod.RValues.Add(operand);
     hints = null;
       }//foreach operand
       //set the flags
       if (prod.RValues.Count == 0)
     prod.Flags |= ProductionFlags.IsEmpty;
       //Add final LRItem
       prod.LR0Items.Add(new LR0Item(_lastItemId++, prod, prod.RValues.Count, hints));
       return prod;
 }