Ejemplo n.º 1
0
 public static void AddOperationNode(ref string input, OpType opType, TreePriority priority, int i, ref int currentIndex)
 {
     string operand = input.Substring(currentIndex, i - currentIndex);
     MathNode newNode = new MathNode(null, null, opType, priority);
     char prevChar = i > 0 ? input[i-1] : '\0'; 
     bool twoCharOperator = false;
     char nextChar;
     if (opType == OpType.And || opType == OpType.Or || opType == OpType.NotEqualTo 
         || opType == OpType.EqualTo || opType == OpType.GThanOrEqualTo || opType == OpType.LThanOrEqualTo)
     {
         nextChar = input.Length > (i+2) ? input[i+2] : '\0';
         twoCharOperator = true;
     }
     else
     {
         nextChar = input.Length > (i+1) ? input[i+1] : '\0';
     }
     if (operand == "")
     {
         // the only character possible before an operator is )
         if (i > 0 && input[i - 1] == ')')
         {
             bool hasFollowingOpenParen = false; // special case--requires decreased priority when inserting this node
             if (nextChar == '(')
             {
                 hasFollowingOpenParen = true;
             }
             if (hasFollowingOpenParen)
             {
                 TreePriority prevPriority = newNode.Priority;
                 newNode.Priority = TreePriority.AddSub; // SHOULD THIS BE CHANGED TO JUST DECREASING BY ONE? OR ALWAYS ADD SUB?
                 InsertIntoTree(currentRoot, newNode);
                 newNode.Priority = prevPriority;
             }
             else InsertIntoTree(currentRoot, newNode);
         }
         else throw new UberScriptException("Math parse error: no operand before + for input= " + input);
     }
     else
     {
         if (currentRoot == null) { currentRoot = newNode; InsertIntoTree(currentRoot, ParseOperand(operand)); }
         else { InsertIntoTree(currentRoot, ParseOperand(operand)); InsertIntoTree(currentRoot, newNode); }
     }
     if (twoCharOperator)
         currentIndex = i + 2;
     else
         currentIndex = i + 1;
 }
Ejemplo n.º 2
0
		public MathNode(UberNode parent, string scriptInput, OpType opType, TreePriority priority)
			: this(parent, scriptInput, opType)
		{
			Priority = priority;
		}
Ejemplo n.º 3
0
		public MathNode(UberNode parent, string scriptInput, OpType opType, TreePriority priority, Object value)
			: this(parent, scriptInput, opType, priority)
		{
			Value = value;
		}
Ejemplo n.º 4
0
        public static void AddOperationNode(ref string input, OpType opType, TreePriority priority, int i, ref int currentIndex)
        {
            string   operand         = input.Substring(currentIndex, i - currentIndex);
            MathNode newNode         = new MathNode(null, null, opType, priority);
            char     prevChar        = i > 0 ? input[i - 1] : '\0';
            bool     twoCharOperator = false;
            char     nextChar;

            if (opType == OpType.And || opType == OpType.Or || opType == OpType.NotEqualTo ||
                opType == OpType.EqualTo || opType == OpType.GThanOrEqualTo || opType == OpType.LThanOrEqualTo)
            {
                nextChar        = input.Length > (i + 2) ? input[i + 2] : '\0';
                twoCharOperator = true;
            }
            else
            {
                nextChar = input.Length > (i + 1) ? input[i + 1] : '\0';
            }
            if (operand == "")
            {
                // the only character possible before an operator is )
                if (i > 0 && input[i - 1] == ')')
                {
                    bool hasFollowingOpenParen = false; // special case--requires decreased priority when inserting this node
                    if (nextChar == '(')
                    {
                        hasFollowingOpenParen = true;
                    }
                    if (hasFollowingOpenParen)
                    {
                        TreePriority prevPriority = newNode.Priority;
                        newNode.Priority = TreePriority.AddSub; // SHOULD THIS BE CHANGED TO JUST DECREASING BY ONE? OR ALWAYS ADD SUB?
                        InsertIntoTree(currentRoot, newNode);
                        newNode.Priority = prevPriority;
                    }
                    else
                    {
                        InsertIntoTree(currentRoot, newNode);
                    }
                }
                else
                {
                    throw new UberScriptException("Math parse error: no operand before + for input= " + input);
                }
            }
            else
            {
                if (currentRoot == null)
                {
                    currentRoot = newNode; InsertIntoTree(currentRoot, ParseOperand(operand));
                }
                else
                {
                    InsertIntoTree(currentRoot, ParseOperand(operand)); InsertIntoTree(currentRoot, newNode);
                }
            }
            if (twoCharOperator)
            {
                currentIndex = i + 2;
            }
            else
            {
                currentIndex = i + 1;
            }
        }