Example #1
0
        static Node Treeify(BalanceData data, List <string> input, int start, int end)
        {
            if (end < start)
            {
                return(null);
            }

            if (end == start)
            {
                return(ParseToken(data, input[start]));
            }

            int index = FindHighestPriorityOperationIndex(input, start, end);

            if (index == -1)
            {
                throw new Exception();
            }

            var op = ParseOperation(input[index]);

            op.Left  = Treeify(data, input, start, index - 1);
            op.Right = Treeify(data, input, index + 1, end);

            return(op);
        }
Example #2
0
        static Node ParseToken(BalanceData data, string s)
        {
            double result;

            if (double.TryParse(s, out result))
            {
                return(new ConstNode(result));
            }

            return(new VariableNode(data, s));
        }
Example #3
0
 public VariableNode(BalanceData data, string key)
 {
     this.data = data;
     this.key  = key;
 }
Example #4
0
 public BalanceStringEvaluator(BalanceData data)
 {
     this.data = data;
 }