Beispiel #1
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="token"></param>
 /// <param name="arguments"></param>
 public IfThenElse(LogicalExpression expression, IStatement @do, IStatement @else=null, Engine engine = null)
     : base(engine)
 {
     // TODO: check the argumetns
     this.NodeType = otXPTNodeType.IfThenElse;
     if (@else != null)
         this.Nodes = new ObservableCollection<INode>(new INode[]{expression, @do, @else});
     else this.Nodes = new ObservableCollection<INode>(new INode[] { expression, @do });
 }
Beispiel #2
0
        /// <summary>
        /// build a XPT Node out of a selection conditions
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public bool BuildXPTNode(SelectConditionsContext ctx)
        {
            //  L_SQUARE_BRACKET  R_SQUARE_BRACKET // all
            if (ctx.selectCondition() == null || ctx.selectCondition().Count()==0)
            {
                // simple true operator
                ctx.XPTreeNode = LogicalExpression.TRUE();
                return true;
            }
            // only one condition
            //    selectCondition [$ClassName, $keypos]

            if (ctx.selectCondition().Count() == 1)
            {
                if (ctx.NOT().Count() == 0) ctx.XPTreeNode = ctx.selectCondition()[0].XPTreeNode;
                else ctx.XPTreeNode = LogicalExpression.NOT((IExpression)ctx.selectCondition()[0].XPTreeNode);
                return true;
            }

            // if we have more than this
            //|	selectCondition [$ClassName, $keypos] (logicalOperator_2 selectCondition [$ClassName, $keypos])*
            if (ctx.selectCondition().Count() > 1)
            {
               eXPressionTree.LogicalExpression theLogical = (LogicalExpression)ctx.selectCondition()[0].XPTreeNode;
               if (theLogical == null) return false;

               for(uint i = 0; i < ctx.selectCondition().Count()-1;i++)
               {
                   Operator anOperator = ctx.logicalOperator_2()[i].Operator;

                    // x or y and z ->  ( x or  y) and z )
                   if (theLogical.Priority >= anOperator.Priority)
                   {
                       if ((LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode != null)
                            theLogical = new LogicalExpression(anOperator, theLogical, (LogicalExpression)ctx.selectCondition()[i + 1].XPTreeNode);
                       else return false;
                       // negate
                       if (ctx.NOT().Count() >= i+1 && ctx.NOT()[i + 1] != null)
                           theLogical = LogicalExpression.NOT((IExpression)theLogical);
                   }
                   else
                   {   // x and y or z ->  x and ( y or z )
                       // build the new (lower) operation in the higher level tree (right with the last operand)
                       IExpression right = (IExpression)theLogical.RightOperand;
                       theLogical.RightOperand = new LogicalExpression(anOperator, right, (IExpression)ctx.selectCondition()[i + 1].XPTreeNode);
                       // negate
                       if (ctx.NOT().Count() >= i + 1 &&  ctx.NOT()[i + 1] != null)
                           theLogical.RightOperand = LogicalExpression.NOT((IExpression)theLogical.RightOperand);

                   }

               }
               ctx.XPTreeNode = theLogical;
               return true;
               }

               return false;
        }