Ejemplo n.º 1
0
        /// <summary>
        /// Evaluates a list expression
        /// </summary>
        /// <returns></returns>
        private Expression EvaluateListExpression()
        {
            Expression retVal = null;

            string listOp = LookAhead(ListOperators.ListOperatorExpression.LIST_OPERATORS);

            if (listOp != null)
            {
                Match(listOp);
                Expression listExpression = Expression(0);

                Expression condition = null;
                if (LookAhead("|"))
                {
                    Match("|");
                    condition = Expression(0);
                }

                if (listOp.CompareTo(ListOperators.MapExpression.OPERATOR) == 0 ||
                    listOp.CompareTo(ListOperators.ReduceExpression.OPERATOR) == 0 ||
                    listOp.CompareTo(ListOperators.SumExpression.OPERATOR) == 0)
                {
                    Match("USING");
                    Expression iteratorExpression = Expression(0);
                    if (iteratorExpression != null)
                    {
                        if (ListOperators.MapExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            retVal = new ListOperators.MapExpression(Root, listExpression, condition, iteratorExpression);
                        }
                        else if (ListOperators.SumExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            retVal = new ListOperators.SumExpression(Root, listExpression, condition, iteratorExpression);
                        }
                        else if (ListOperators.ReduceExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            Match("INITIAL_VALUE");
                            Expression initialValue = Expression(0);
                            if (initialValue != null)
                            {
                                retVal = new ListOperators.ReduceExpression(Root, listExpression, condition, iteratorExpression, initialValue);
                            }
                            else
                            {
                                throw new ParseErrorException("REDUCE requires an initial value");
                            }
                        }
                    }
                    else
                    {
                        throw new ParseErrorException("Function designator expected");
                    }
                }
                else
                {
                    // Create the right class for this list operation
                    if (ListOperators.ThereIsExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.ThereIsExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.ForAllExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.ForAllExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.FirstExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.FirstExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.LastExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.LastExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.CountExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.CountExpression(Root, listExpression, condition);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Evaluates a list expression
        /// </summary>
        /// <returns></returns>
        private Expression EvaluateListExpression()
        {
            Expression retVal = null;

            SkipWhiteSpaces();
            int start = Index;
            string listOp = LookAhead(ListOperatorExpression.ListOperators);
            if (listOp != null)
            {
                Match(listOp);

                if (MapExpression.Operator.Equals(listOp)
                    || ReduceExpression.Operator.Equals(listOp)
                    || SumExpression.Operator.Equals(listOp) )
                {
                    Expression listExpression = Expression(0);
                    if (listExpression != null)
                    {
                        Expression condition = null;
                        if (LookAhead("|"))
                        {
                            Match("|");
                            condition = Expression(0);
                        }

                        Match("USING");
                        string iteratorIdentifier = Identifier();
                        Match("IN");
                        Expression iteratorExpression = Expression(0);
                        if (iteratorExpression != null)
                        {
                            if (MapExpression.Operator.Equals(listOp))
                            {
                                retVal = new MapExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                    iteratorExpression, start, Index);
                            }
                            else if (SumExpression.Operator.Equals(listOp))
                            {
                                retVal = new SumExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                    iteratorExpression, start, Index);
                            }
                            else if (ReduceExpression.Operator.Equals(listOp))
                            {
                                Match("INITIAL_VALUE");
                                Expression initialValue = Expression(0);
                                if (initialValue != null)
                                {
                                    retVal = new ReduceExpression(Root, RootLog, listExpression, iteratorIdentifier,
                                        condition, iteratorExpression, initialValue, start, Index);
                                }
                                else
                                {
                                    throw new ParseErrorException("REDUCE requires an initial value", Index, Buffer);
                                }
                            }
                        }
                        else
                        {
                            throw new ParseErrorException("Function designator expected", Index, Buffer);
                        }
                    }
                }
                else
                {
                    string iteratorIdentifier = Identifier();
                    Match("IN");
                    Expression listExpression = Expression(6);
                    if (listExpression != null)
                    {
                        Expression condition = null;
                        if (LookAhead("|"))
                        {
                            Match("|");
                            condition = Expression(0);
                        }

                        // Create the right class for this list operation
                        if (ThereIsExpression.Operator.Equals(listOp))
                        {
                            retVal = new ThereIsExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                start, Index);
                        }
                        else if (ForAllExpression.Operator.Equals(listOp))
                        {
                            retVal = new ForAllExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                start, Index);
                        }
                        else if (FirstExpression.Operator.Equals(listOp))
                        {
                            retVal = new FirstExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                start, Index);
                        }
                        else if (LastExpression.Operator.Equals(listOp))
                        {
                            retVal = new LastExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                start, Index);
                        }
                        else if (CountExpression.Operator.Equals(listOp))
                        {
                            retVal = new CountExpression(Root, RootLog, listExpression, iteratorIdentifier, condition,
                                start, Index);
                        }
                    }
                }
            }

            return retVal;
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Visits a FIRST expression
 /// </summary>
 /// <param name="firstExpression"></param>
 protected virtual void VisitFirstExpression(FirstExpression firstExpression)
 {
     if (firstExpression != null)
     {
         VisitConditionBasedListExpression(firstExpression);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Evaluates a list expression
        /// </summary>
        /// <returns></returns>
        private Expression EvaluateListExpression()
        {
            Expression retVal = null;

            string listOp = LookAhead(ListOperators.ListOperatorExpression.LIST_OPERATORS);
            if (listOp != null)
            {
                Match(listOp);
                Expression listExpression = Expression(0);

                Expression condition = null;
                if (LookAhead("|"))
                {
                    Match("|");
                    condition = Expression(0);
                }

                if (listOp.CompareTo(ListOperators.MapExpression.OPERATOR) == 0
                    || listOp.CompareTo(ListOperators.ReduceExpression.OPERATOR) == 0
                    || listOp.CompareTo(ListOperators.SumExpression.OPERATOR) == 0)
                {
                    Match("USING");
                    Expression iteratorExpression = Expression(0);
                    if (iteratorExpression != null)
                    {
                        if (ListOperators.MapExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            retVal = new ListOperators.MapExpression(Root, listExpression, condition, iteratorExpression);
                        }
                        else if (ListOperators.SumExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            retVal = new ListOperators.SumExpression(Root, listExpression, condition, iteratorExpression);
                        }
                        else if (ListOperators.ReduceExpression.OPERATOR.CompareTo(listOp) == 0)
                        {
                            Match("INITIAL_VALUE");
                            Expression initialValue = Expression(0);
                            if (initialValue != null)
                            {
                                retVal = new ListOperators.ReduceExpression(Root, listExpression, condition, iteratorExpression, initialValue);
                            }
                            else
                            {
                                throw new ParseErrorException("REDUCE requires an initial value");
                            }
                        }
                    }
                    else
                    {
                        throw new ParseErrorException("Function designator expected");
                    }
                }
                else
                {
                    // Create the right class for this list operation
                    if (ListOperators.ThereIsExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.ThereIsExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.ForAllExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.ForAllExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.FirstExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.FirstExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.LastExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.LastExpression(Root, listExpression, condition);
                    }
                    else if (ListOperators.CountExpression.OPERATOR.CompareTo(listOp) == 0)
                    {
                        retVal = new ListOperators.CountExpression(Root, listExpression, condition);
                    }
                }
            }

            return retVal;
        }