Beispiel #1
0
        public int 計算_if(string expression)
        {
            var row = new Dictionary <string, int>()
            {
                { "X", 4 }, { "Y", 2 }
            };
            var tbl = new[]
            {
                new Dictionary <string, int>()
                {
                    { "A", 1 }, { "B", 3 }
                },
                new Dictionary <string, int>()
                {
                    { "A", 2 }, { "B", 6 }
                },
                new Dictionary <string, int>()
                {
                    { "A", 3 }, { "B", 7 }
                },
            };

            var node = new Node(expression);

            node.Parse();
            return(Node.Compute(node, row, tbl));
        }
Beispiel #2
0
        public int 条件_less(string expression)
        {
            var node = new Node(expression);

            node.Parse();
            return(Node.Compute(node));
        }
Beispiel #3
0
        public int 計算_カラム(string expression)
        {
            var row = new Dictionary <string, int>()
            {
                { "A", 1 }, { "B", 2 }
            };
            var tbl = new[]
            {
                new Dictionary <string, int>()
                {
                    { "A", 1 }
                },
                new Dictionary <string, int>()
                {
                    { "A", 2 }
                },
                new Dictionary <string, int>()
                {
                    { "A", 3 }
                },
            };

            var node = new Node(expression);

            node.Parse();
            var ans = Node.Compute(node, row, tbl);

            return(ans);
        }
Beispiel #4
0
        public int 計算(string expression)
        {
            var node = new Node(expression);

            node.Parse();
            //var ans = node.Compute();
            var ans = Node.Compute(node);

            return(ans);
        }
Beispiel #5
0
 /// <summary>
 /// OR
 /// </summary>
 /// <param name="left"></param>
 /// <param name="tbl"></param>
 /// <returns></returns>
 static public int or(Node[] nodes, Dictionary <string, int> row = null, Dictionary <string, int>[] tbl = null)
 {
     foreach (var node in nodes)
     {
         if (Node.Compute(node, row, tbl) == 1)
         {
             return(1);
         }
     }
     return(0);
 }
Beispiel #6
0
        /// <summary>
        /// IF
        /// </summary>
        /// <param name="left"></param>
        /// <param name="tbl"></param>
        /// <returns></returns>
        static public int iif(Node [] nodes, Dictionary <string, int> row = null, Dictionary <string, int>[] tbl = null)
        {
            var condition = Node.Compute(nodes[0], row, tbl);

            if (condition == 1)
            {
                return(Node.Compute(nodes[1], row, tbl));
            }
            else
            {
                return(Node.Compute(nodes[2], row, tbl));
            }
        }
Beispiel #7
0
        /// <summary>
        /// 比較「>」
        /// </summary>
        /// <param name="left"></param>
        /// <param name="tbl"></param>
        /// <returns></returns>
        static public int gt(Node left, Node right, Dictionary <string, int> row = null, Dictionary <string, int>[] tbl = null)
        {
            var leftVal  = Node.Compute(left, row, tbl);
            var rightVal = Node.Compute(right, row, tbl);

            if (leftVal > rightVal)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Beispiel #8
0
 /// <summary>
 /// 集合関数>累計
 /// </summary>
 /// <param name="item"></param>
 /// <param name="dic"></param>
 /// <returns></returns>
 static public int sum(Node left, Dictionary <string, int>[] tbl)
 {
     return((from n in tbl select Node.Compute(left, n)).Sum());
 }