Exemple #1
0
        internal static void AddArgumentSymbol(ISymbolicExpressionTreeGrammar originalGrammar, ISymbolicExpressionTreeGrammar grammar, IEnumerable <int> argumentIndexes, IEnumerable <CutPoint> argumentCutPoints)
        {
            foreach (var pair in argumentIndexes.Zip(argumentCutPoints, (a, b) => new { Index = a, CutPoint = b }))
            {
                var argSymbol = new Argument(pair.Index);
                grammar.AddSymbol(argSymbol);
                grammar.SetSubtreeCount(argSymbol, 0, 0);

                foreach (var symb in grammar.Symbols)
                {
                    if (symb is ProgramRootSymbol || symb is StartSymbol)
                    {
                        continue;
                    }
                    if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol))
                    {
                        grammar.AddAllowedChildSymbol(symb, argSymbol);
                    }
                    else
                    {
                        for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++)
                        {
                            if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol, i))
                            {
                                grammar.AddAllowedChildSymbol(symb, argSymbol, i);
                            }
                        }
                    }
                }
            }
        }
    internal static void AddArgumentSymbol(ISymbolicExpressionTreeGrammar originalGrammar, ISymbolicExpressionTreeGrammar grammar, IEnumerable<int> argumentIndexes, IEnumerable<CutPoint> argumentCutPoints) {
      foreach (var pair in argumentIndexes.Zip(argumentCutPoints, (a, b) => new { Index = a, CutPoint = b })) {
        var argSymbol = new Argument(pair.Index);
        grammar.AddSymbol(argSymbol);
        grammar.SetSubtreeCount(argSymbol, 0, 0);

        foreach (var symb in grammar.Symbols) {
          if (symb is ProgramRootSymbol || symb is StartSymbol) continue;
          if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol))
            grammar.AddAllowedChildSymbol(symb, argSymbol);
          else {
            for (int i = 0; i < grammar.GetMaximumSubtreeCount(symb); i++) {
              if (originalGrammar.IsAllowedChildSymbol(symb, pair.CutPoint.Child.Symbol, i))
                grammar.AddAllowedChildSymbol(symb, argSymbol, i);
            }
          }
        }
      }
    }
    internal static void AddInvokeSymbol(ISymbolicExpressionTreeGrammar grammar, string functionName, int nArgs, CutPoint startCutPoint, IEnumerable<CutPoint> argumentCutPoints) {
      if (!grammar.ContainsSymbol(startCutPoint.Child.Symbol)) return;

      var invokeSym = new InvokeFunction(functionName);
      grammar.AddSymbol(invokeSym);
      grammar.SetSubtreeCount(invokeSym, nArgs, nArgs);

      //allow invoke symbol everywhere, where the child of the startCutPoint was allowed
      SetAllowedParentSymbols(grammar, startCutPoint.Child.Symbol, invokeSym);

      if (nArgs > 0) {
        //set allowed child symbols of invoke symbol 
        foreach (ISymbol child in grammar.Symbols) {
          if (child.Name == invokeSym.Name) continue;
          int i = 0;
          foreach (CutPoint argumentCutPoint in argumentCutPoints) {
            if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex))
              grammar.AddAllowedChildSymbol(invokeSym, child, i);
            i++;
          }
        }
      }
    }
Exemple #4
0
        internal static void AddInvokeSymbol(ISymbolicExpressionTreeGrammar grammar, string functionName, int nArgs, CutPoint startCutPoint, IEnumerable <CutPoint> argumentCutPoints)
        {
            if (!grammar.ContainsSymbol(startCutPoint.Child.Symbol))
            {
                return;
            }

            var invokeSym = new InvokeFunction(functionName);

            grammar.AddSymbol(invokeSym);
            grammar.SetSubtreeCount(invokeSym, nArgs, nArgs);

            //allow invoke symbol everywhere, where the child of the startCutPoint was allowed
            SetAllowedParentSymbols(grammar, startCutPoint.Child.Symbol, invokeSym);

            if (nArgs > 0)
            {
                //set allowed child symbols of invoke symbol
                foreach (ISymbol child in grammar.Symbols)
                {
                    if (child.Name == invokeSym.Name)
                    {
                        continue;
                    }
                    int i = 0;
                    foreach (CutPoint argumentCutPoint in argumentCutPoints)
                    {
                        if (grammar.IsAllowedChildSymbol(argumentCutPoint.Parent.Symbol, child, argumentCutPoint.ChildIndex))
                        {
                            grammar.AddAllowedChildSymbol(invokeSym, child, i);
                        }
                        i++;
                    }
                }
            }
        }