예제 #1
0
        public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild)
        {
            var parent = this.Parent;

            if (newChild == null)
            {
                // make sure that one subtree can be removed and that only the last subtree is removed
                return(grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&
                       this.ChildIndex == parent.SubtreeCount - 1);
            }
            else
            {
                // check syntax constraints of direct parent - child relation
                if (!grammar.ContainsSymbol(newChild.Symbol) ||
                    !grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex))
                {
                    return(false);
                }

                bool result = true;
                // check point type for the whole branch
                newChild.ForEachNodePostfix((n) => {
                    result =
                        result &&
                        grammar.ContainsSymbol(n.Symbol) &&
                        n.SubtreeCount >= grammar.GetMinimumSubtreeCount(n.Symbol) &&
                        n.SubtreeCount <= grammar.GetMaximumSubtreeCount(n.Symbol);
                });
                return(result);
            }
        }
예제 #2
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++;
          }
        }
      }
    }
예제 #3
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++;
                    }
                }
            }
        }