Example #1
0
        public void SetChildren(ExpressionTreeBase left, ExpressionTreeBase right)
        {
            if (left != null) Left.SetParent(this);
            Left = left;

            if (right != null) right.SetParent(this);
            Right = right;
        }
Example #2
0
 private void MultiAdd(ExpressionTreeBase parent, ExpressionTreeBase child)
 {
     if (parent is MultiNodeTree)
     {
         ((MultiNodeTree)parent).AddChild(child);
     }
     else if (parent is ConditionalExpression && child is ConditionalExpression)
     {
         ((ConditionalExpression)parent).AddCondition((ConditionalExpression)child);
     }
     else if (parent is SingleNodeTree)
     {
         ((SingleNodeTree)parent).SetChild(child);
     }
 }
Example #3
0
        void Conditional(MultiNodeTree parent)
        {
            ExpressionTreeBase addTo = parent; SingleNodeTree condition = null; ConditionalExpression lastOperation = null;

            while (StartOf(2))
            {
                lastOperation = lastOperation ?? new AndCondition();
                MultiAdd(addTo, lastOperation);
                addTo = lastOperation;

                if (la.kind == 5)
                {
                    Get();
                    NotCondition not = new NotCondition(); lastOperation.SetChild(not); lastOperation = not;
                }
                if (StartOf(3))
                {
                    Condition(lastOperation);
                }
                else if (la.kind == 6)
                {
                    ConditionGroup(lastOperation);
                }
                else
                {
                    SynErr(44);
                }
                if (la.kind == 9 || la.kind == 10)
                {
                    Operation(out lastOperation);
                }
                else
                {
                    lastOperation = null;
                }
            }
            if (lastOperation != null && lastOperation.Child == null)
            {
                SemErr("Invalid Condition");
            }
        }
Example #4
0
 public static void PrintTree(ExpressionTreeBase treeItem, int indent)
 {
     string add = "";
     for (int i = 0; i < indent; i++)
     {
         add += "  ";
     }
     Console.Out.WriteLine(add + treeItem);
     indent++;
     if (treeItem is GetExpression)
     {
         //Console.Out.WriteLine(add + "Types: ");
         //foreach (GetTypes current in ((GetExpression)treeItem).Types)
         //{
             //Console.Out.WriteLine(add + current);
         //}
         Console.Out.WriteLine(add + "Conditions: ");
     }
     if (treeItem is MultiNodeTree)
     {
         foreach (ExpressionTreeBase current in ((MultiNodeTree)treeItem).Children)
         {
             PrintTree(current, indent);
         }
     }
     else if (treeItem is SingleNodeTree)
     {
         PrintTree(((SingleNodeTree)treeItem).Child, indent);
     }
     if (treeItem is ConditionalExpression)
     {
         if (((ConditionalExpression)treeItem).AdditionalConditions.Count > 0)
         {
             //Console.Out.WriteLine(add + "Additional Conditions:");
             foreach (ConditionalExpression current in ((ConditionalExpression)treeItem).AdditionalConditions)
             {
                 PrintTree(current, indent);
             }
         }
     }
 }
Example #5
0
private void MultiAdd(ExpressionTreeBase parent, ExpressionTreeBase child)
{
	if (parent is MultiNodeTree)
	{
		((MultiNodeTree)parent).AddChild(child);
	}
	else if (parent is ConditionalExpression && child is ConditionalExpression)
	{
		((ConditionalExpression)parent).AddCondition((ConditionalExpression)child);
	}
	else if (parent is SingleNodeTree)
	{
		((SingleNodeTree)parent).SetChild(child);  
	}
}
Example #6
0
	void LiteralExpression(ref ExpressionTreeBase expr) {
		if (la.kind == 35) {
			Get();
			expr = new RangeExpression(t.val); 
		} else if (la.kind == 3) {
			Get();
			expr = new LiteralExpression(t.val); 
		} else if (la.kind == 4) {
			Get();
			expr = new LiteralExpression(t.val.Substring(1, t.val.Length - 2), true); 
		} else if (la.kind == 5) {
			Get();
			expr = new ValueExpression(Int32.Parse(t.val.Substring(1))); 
		} else if (la.kind == 1) {
			Get();
			expr = new LiteralExpression(t.val); 
		} else SynErr(53);
	}
Example #7
0
 public override bool Equals(ExpressionTreeBase other) => other is ParameterDeclaration pd && base.Expression.Type == pd.Expression.Type;
Example #8
0
 public SelectorExpression(SelectorTypes field, ModifierTypes modifier, ExpressionTreeBase left) : this()
 {
     NodeType = field;
     Modifier = modifier;
     SetLeft( left );
 }
Example #9
0
        internal static IEnumerable<LogicalItem> Convert(ExpressionTreeBase item)
        {
            JoiningType? type;
            bool negate;
            ConditionalExpression lastParent;

            ExpressionTreeBase actualItem = ExtractItem(item, out type, out negate, out lastParent);

            LogicalItem result;

            if (actualItem is SelectorExpression)
            {
                result = new LogicalSelector((SelectorExpression)actualItem);
            }
            else if (actualItem is ConditionGroup)
            {
                result = new LogicalGroup((ConditionGroup)actualItem);
            }
            else
            {
                throw new Exception();
            }

            result.Negated = negate;
            result.JoiningType = type ?? JoiningType.And;

            yield return result;

            if (lastParent != null)
            {
                foreach (LogicalItem current in lastParent.AdditionalConditions.SelectMany(x => Convert(x)))
                {
                    yield return current;
                }
            }
        }
Example #10
0
        private static ExpressionTreeBase ExtractItem(ExpressionTreeBase item, out JoiningType? type, out bool negate, out ConditionalExpression lastParent)
        {
            lastParent = null;
            type = GetJoiningType(item);

            if (item is ConditionalExpression && !(item is NotCondition))
            {
                lastParent = (ConditionalExpression)item;
                item = ((ConditionalExpression)item).Child;
            }

            if (item is NotCondition)
            {
                negate = true;
                item = ((NotCondition)item).Child;
            }
            else
            {
                negate = false;
            }

            return item;
        }
Example #11
0
 private static JoiningType? GetJoiningType(ExpressionTreeBase item)
 {
     if (item is AndCondition)
     {
         return JoiningType.And;
     }
     else if (item is OrCondition)
     {
         return JoiningType.Or;
     }
     return null;
 }
 public void AddArgument(ExpressionTreeBase dim)
 {
     if (dim != null) dim.SetParent(this);
     Dimensions.Add(dim);
 }
Example #13
0
 public void AddSelect(ExpressionTreeBase sel)
 {
     sel.SetParent(this);
     _selects.Add(sel as DimensionExpression);
 }
Example #14
0
 public void AddDimension(ExpressionTreeBase dim)
 {
     dim.SetParent(this);
     _dimensions.Add(dim as DimensionExpression);
 }
Example #15
0
 public override bool Equals(ExpressionTreeBase other) => other is DeBruijnParameter dbp && base.Expression.Type == dbp.Expression.Type && _scope == dbp._scope && _index == dbp._index;
Example #16
0
        void ComplexCondition(SingleNodeTree parent, SelectorExpression selector)
        {
            ConditionGroup group = new ConditionGroup(); parent.SetChild(group); ExpressionTreeBase addTo = group; SingleNodeTree condition = null; ConditionalExpression lastOperation = null;

            Expect(6);
            while (StartOf(2))
            {
                lastOperation = lastOperation ?? new AndCondition();
                MultiAdd(addTo, lastOperation);
                addTo    = lastOperation;
                selector = new SelectorExpression(selector.Field, ModifierTypes.Equals, selector.Path);

                if (la.kind == 5)
                {
                    Get();
                    NotCondition not = new NotCondition(); lastOperation.SetChild(not); lastOperation = not;
                }
                if (la.kind == 6)
                {
                    ComplexCondition(lastOperation, selector);
                }
                else if (StartOf(3))
                {
                    SelectorExpression nestedSelector = new SelectorExpression(selector.Field, ModifierTypes.Equals, selector.Path); MultiAdd(lastOperation, nestedSelector);
                    Literal(nestedSelector);
                }
                else
                {
                    SynErr(49);
                }
                if (la.kind == 9 || la.kind == 10)
                {
                    Operation(out lastOperation);
                }
                else
                {
                    lastOperation = null;
                }
            }
            Expect(7);
        }
Example #17
0
 public void SetChild(ExpressionTreeBase child)
 {
     Child = child;
     if(Child != null) Child.SetParent(this);
 }
Example #18
0
 public void SetLeft(ExpressionTreeBase left) 
 {
     if(left != null) left.SetParent(this); 
     Left = left; 
 }
Example #19
0
 public void SetMiddle(ExpressionTreeBase child)
 {
     Middle = child;
     if (Middle != null) Child.SetParent(this);
 }
Example #20
0
 public void SetRight(ExpressionTreeBase right) { Right = right; }
Example #21
0
 public void AddItem(ExpressionTreeBase lit)
 {
     AddChild(lit);
 }
Example #22
0
 public void AddChild(ExpressionTreeBase child)
 {
     _children.Add(child);
     child.SetParent(this);
 }