private bool TryMatch(ExpressionNode node, PatternNode pattern)
        {
            if (pattern.Compare(node))
            {
                if (pattern.ChildrenCount() == 0)
                {
                    return(true);
                }

                int i = 0;
                for (int j = 0; j < node.ChildrenCount(); j++)
                {
                    if (TryMatch((ExpressionNode)(node.GetChild(j)),
                                 (PatternNode)(pattern.GetChild(i))))
                    {
                        i++;
                        if (i >= pattern.ChildrenCount())
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private static Pattern CreateDeleteZeroAdditionPattern()
        {
            PatternNode node = new PatternNode(typeof(Addition));

            node.AddChild(new PatternNode(typeof(Scalar), null, 0));
            return(new Pattern(node));
        }
        private static Pattern CreatePerformScalarOperationPattern()
        {
            PatternNode node = new PatternNode(
                new Type[] { typeof(Addition), typeof(Multiplication) });

            node.AddChild(new PatternNode(typeof(Scalar)));
            node.AddChild(new PatternNode(typeof(Scalar)));
            return(new Pattern(node));
        }
 private Pattern(PatternNode pattern)
 {
     this.pattern = pattern;
 }