}//method

        #endregion

        #region Creating Productions
        private void CreateProductions()
        {
            Data.Productions.Clear();
            //each LR0Item gets its unique ID, last assigned (max) Id is kept in static field
            LR0Item._maxID = 0;
            foreach (NonTerminal nt in Data.NonTerminals)
            {
                nt.Productions.Clear();
                //Get data (sequences) from both Rule and ErrorRule
                BnfExpressionData allData = new BnfExpressionData();
                allData.AddRange(nt.Rule.Data);
                if (nt.ErrorRule != null)
                {
                    allData.AddRange(nt.ErrorRule.Data);
                }
                //actually create productions for each sequence
                foreach (BnfTermList prodOperands in allData)
                {
                    bool       isInitial = (nt == Data.AugmentedRoot);
                    Production prod      = new Production(isInitial, nt, prodOperands);
                    nt.Productions.Add(prod);
                    Data.Productions.Add(prod);
                }//foreach prodOperands
            }
        }
Beispiel #2
0
 public BnfExpression()
     : base(null)
 {
     Data = new BnfExpressionData {
         new BnfTermList()
     };
 }
 private void CreateProductions()
 {
     Data.Productions.Clear();
     //each LR0Item gets its unique ID, last assigned (max) Id is kept in static field
     LR0Item._maxID = 0;
     foreach (NonTerminal nt in Data.NonTerminals)
     {
         NtData ntInfo = NtData.GetOrCreate(nt);
         ntInfo.Productions.Clear();
         //Get data (sequences) from both Rule and ErrorRule
         BnfExpressionData allData = new BnfExpressionData();
         allData.AddRange(nt.Rule.Data);
         if (nt.ErrorRule != null)
         {
             allData.AddRange(nt.ErrorRule.Data);
         }
         //actually create productions for each sequence
         foreach (BnfTermList prodOperands in allData)
         {
             Production prod = CreateProduction(nt, prodOperands);
             //Add the production to non-terminal's list and to global list
             ntInfo.Productions.Add(prod);
             Data.Productions.Add(prod);
         }//foreach prodOperands
     }
 }
        }//method

        private void CreateProductions()
        {
            _lastItemId = 0;
            //CheckWrapTailHints() method may add non-terminals on the fly, so we have to use for loop here (not foreach)
            for (int i = 0; i < _grammarData.NonTerminals.Count; i++)
            {
                var nt = _grammarData.NonTerminals[i];
                nt.Productions.Clear();
                //Get data (sequences) from both Rule and ErrorRule
                BnfExpressionData allData = new BnfExpressionData();
                allData.AddRange(nt.Rule.Data);
                if (nt.ErrorRule != null)
                {
                    allData.AddRange(nt.ErrorRule.Data);
                }
                //actually create productions for each sequence
                foreach (BnfTermList prodOperands in allData)
                {
                    Production prod = CreateProduction(nt, prodOperands);
                    nt.Productions.Add(prod);
                } //foreach prodOperands
                // insert pending custom hints in all productions
                nt.InsertCustomHints();
            }
        }
Beispiel #5
0
 public GrammarExpression(GrammarTerm element)
     : base(null)
 {
     Data = new BnfExpressionData();
     Data.Add(new BnfTermList()
     {
         element
     });
 }
Beispiel #6
0
        private void CreateProductions()
        {
            _data.Productions.Clear();

            LR0Item.instance_counter = 0;
            foreach (NonTerminal nt in _data.NonTerminals)
            {
                nt.Productions.Clear();
                BnfExpressionData allData = new BnfExpressionData();
                allData.AddRange(nt.Rule.Data);

                foreach (BnfTermList prodOperands in allData)
                {
                    bool       isInitial = (nt == _data.AugmentedRoot);
                    Production prod      = new Production(isInitial, nt, prodOperands);
                    nt.Productions.Add(prod);
                    _data.Productions.Add(prod);
                }
            }
        }
        private void ValidateAll()
        {
            //Check rule on all non-terminals
            StringSet ntList = new StringSet();

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt == Data.AugmentedRoot)
                {
                    continue;                   //augm root does not count
                }
                BnfExpressionData data = nt.Rule.Data;
                if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal)
                {
                    ntList.Add(nt.Name);
                }
            }//foreach
            if (ntList.Count > 0)
            {
                string slist = TextUtils.Cleanup(ntList.ToString(", "));
                AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" +
                         "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", slist);
            }
            //Check constructors of all nodes referenced in Non-terminals that don't use NodeCreator delegate
            var ctorArgTypes = new Type[] { typeof(NodeArgs) };

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt.NodeCreator == null && nt.NodeType != null)
                {
                    object ci = nt.NodeType.GetConstructor(ctorArgTypes);
                    if (ci == null)
                    {
                        AddError(
                            @"AST Node class {0} referenced by non-terminal {1} does not have a constructor for automatic node creation. 
Provide a constructor with a single NodeArgs parameter, or use NodeCreator delegate property in NonTerminal.",
                            nt.NodeType, nt.Name);
                    }
                } //if
            }     //foreach ntInfo
        }         //method
Beispiel #8
0
        private void ValidateAll()
        {
            StringSet ntList = new StringSet();

            foreach (NonTerminal nt in _data.NonTerminals)
            {
                if (nt == _data.AugmentedRoot)
                {
                    continue;
                }
                BnfExpressionData data = nt.Rule.Data;
                if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal)
                {
                    ntList.Add(nt.Name);
                }
            }
            if (ntList.Count > 0)
            {
                AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" +
                         "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.");
            }
        }
Beispiel #9
0
        private void ValidateAll()
        {
            //Check rule on all non-terminals
            KeyList ntList = new KeyList();

            foreach (NonTerminal nt in Data.NonTerminals)
            {
                if (nt == Data.AugmentedRoot)
                {
                    continue;                   //augm root does not count
                }
                BnfExpressionData data = nt.Rule.Data;
                if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal)
                {
                    ntList.Add(nt.Name);
                }
            }//foreach
            if (ntList.Count > 0)
            {
                AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" +
                         "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", ntList.ToString(", "));
            }
        }
Beispiel #10
0
 private void CreateProductions()
 {
     _lastItemId = 0;
       //CheckWrapTailHints() method may add non-terminals on the fly, so we have to use for loop here (not foreach)
       for (int i = 0; i < _grammarData.NonTerminals.Count; i++) {
     var nt = _grammarData.NonTerminals[i];
     nt.Productions.Clear();
     //Get data (sequences) from both Rule and ErrorRule
     BnfExpressionData allData = new BnfExpressionData();
     allData.AddRange(nt.Rule.Data);
     if (nt.ErrorRule != null)
       allData.AddRange(nt.ErrorRule.Data);
     //actually create productions for each sequence
     foreach (BnfTermList prodOperands in allData) {
       Production prod = CreateProduction(nt, prodOperands);
       nt.Productions.Add(prod);
     } //foreach prodOperands
     // insert pending custom hints in all productions
     nt.InsertCustomHints();
       }
 }
    private void CreateProductions()
    {
      _data.Productions.Clear();

      LR0Item.instance_counter = 0;
      foreach (NonTerminal nt in _data.NonTerminals)
      {
        nt.Productions.Clear();
        BnfExpressionData allData = new BnfExpressionData();
        allData.AddRange(nt.Rule.Data);

        foreach (BnfTermList prodOperands in allData)
        {
          bool isInitial = (nt == _data.AugmentedRoot);
          Production prod = new Production(isInitial, nt, prodOperands);
          nt.Productions.Add(prod);
          _data.Productions.Add(prod);
        }
      }
    }
Beispiel #12
0
 public BnfExpression(BnfTerm element) : base(null)
 {
     Data = new BnfExpressionData();
     Data.Add(new BnfTermList());
     Data[0].Add(element);
 }
        } //method

        private void CreateProductions()
        {
            _lastItemId = 0;
            //CheckWrapTailHints() method may add non-terminals on the fly, so we have to use for loop here (not foreach)
            foreach (var nt in _grammarData.NonTerminals)
            {
                nt.Productions.Clear();
                //Get data (sequences) from both Rule and ErrorRule
                var allData = new BnfExpressionData();
                allData.AddRange(nt.Rule.Data);
                if (nt.ErrorRule != null)
                    allData.AddRange(nt.ErrorRule.Data);
                //actually create productions for each sequence
                foreach (var prodOperands in allData)
                {
                    var prod = CreateProduction(nt, prodOperands);
                    nt.Productions.Add(prod);
                } //foreach prodOperands
            }
        }
Beispiel #14
0
 public GrammarExpression(GrammarTerm element)
   : base(null)
 {
   Data = new BnfExpressionData();
   Data.Add(new BnfTermList() { element });
 }
 public BnfExpression() : base(null)
 {
     Data = new BnfExpressionData();
     Data.Add(new BnfTermList());
 }