コード例 #1
0
            /// <summary>
            /// Converts a tree into binary
            /// </summary>
            /// <param name="expr"></param>
            internal static void OptimizeTree(ref Entity expr)
            {
                if (expr.entType == Entity.EntType.OPERATOR)
                {
                    if (expr.Name == "sumf" || expr.Name == "minusf")
                    {
                        var children = TreeAnalyzer.LinearChildren(expr, "sumf", "minusf", Const.FuncIfSum);
                        expr = TreeAnalyzer.MultiHangBinary(children, "sumf", expr.Priority);
                    }
                    if (expr.Name == "mulf" || expr.Name == "divf")
                    {
                        var children = TreeAnalyzer.LinearChildren(expr, "mulf", "divf", Const.FuncIfMul);
                        expr = TreeAnalyzer.MultiHangBinary(children, "mulf", expr.Priority);
                    }
                }

                for (int i = 0; i < expr.Children.Count; i++)
                {
                    var tmp = expr.Children[i];
                    OptimizeTree(ref tmp);
                    expr.Children[i] = tmp;
                }
            }