Inheritance: DataDictionary.Interpreter.Statement.Statement, ISubDeclarator
Esempio n. 1
0
 /// <summary>
 ///     Visits an APPLY statement
 /// </summary>
 /// <param name="applyStatement"></param>
 protected virtual void VisitApplyStatement(ApplyStatement applyStatement)
 {
     if (applyStatement.AppliedStatement != null)
     {
         VisitStatement(applyStatement.AppliedStatement);
     }
     if (applyStatement.ListExpression != null)
     {
         VisitExpression(applyStatement.ListExpression);
     }
     if (applyStatement.ConditionExpression != null)
     {
         VisitExpression(applyStatement.ConditionExpression);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Provides the Term at position Index of the Buffer.
        /// </summary>
        /// <param name="root">The root element for which this term is built</param>
        /// <returns></returns>
        private Statement.Statement Statement(ModelElement root)
        {
            Statement.Statement retVal = null;

            Root = root;
            if (LookAhead("APPLY"))
            {
                Match("APPLY");
                Call callExpression = Expression(0) as Call;
                if (callExpression != null)
                {
                    Statement.ProcedureCallStatement call = new Statement.ProcedureCallStatement(root, callExpression);
                    Match("ON");
                    Expression listExpression = Expression(0);
                    Expression condition      = null;
                    if (LookAhead("|"))
                    {
                        Match("|");
                        condition = Expression(0);
                    }
                    retVal = new Statement.ApplyStatement(root, call, listExpression, condition);
                }
                else
                {
                    Root.AddError("Cannot parse call expression");
                }
            }
            else if (LookAhead("INSERT"))
            {
                Match("INSERT");
                Expression value = Expression(0);
                if (value != null)
                {
                    Match("IN");
                    Expression list           = Expression(0);
                    Expression replaceElement = null;
                    if (LookAhead("WHEN"))
                    {
                        Match("WHEN");
                        Match("FULL");
                        Match("REPLACE");

                        replaceElement = Expression(0);
                    }
                    retVal = new Statement.InsertStatement(root, value, list, replaceElement);
                }
            }
            else if (LookAhead("REMOVE"))
            {
                Match("REMOVE");

                Statement.RemoveStatement.PositionEnum position = Interpreter.Statement.RemoveStatement.PositionEnum.First;
                if (LookAhead("FIRST"))
                {
                    Match("FIRST");
                }
                else if (LookAhead("LAST"))
                {
                    Match("LAST");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.Last;
                }
                else if (LookAhead("ALL"))
                {
                    Match("ALL");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.All;
                }

                Expression condition = null;
                if (!LookAhead("IN"))
                {
                    condition = Expression(0);
                }
                Match("IN");
                Expression list = Expression(0);
                retVal = new Statement.RemoveStatement(root, condition, position, list);
            }
            else if (LookAhead("REPLACE"))
            {
                Match("REPLACE");
                Expression condition = Expression(0);
                Match("IN");
                Expression list = Expression(0);
                Match("BY");
                Expression value = Expression(0);

                retVal = new Statement.ReplaceStatement(root, value, list, condition);
            }
            else
            {
                Expression expression = Expression(0);
                if (expression != null)
                {
                    if (LookAhead("<-"))
                    {
                        // This is a variable update
                        Match("<-");
                        if (LookAhead("%"))
                        {
                            Match("%");
                        }
                        Expression expression2 = Expression(0);

                        if (expression2 != null)
                        {
                            retVal = new Statement.VariableUpdateStatement(root, expression, expression2);
                        }
                        else
                        {
                            Root.AddError("Invalid <- right side");
                        }
                        expression.Enclosing = retVal;
                    }
                    else
                    {
                        // This is a procedure call
                        Call call = expression as Call;
                        if (call != null)
                        {
                            retVal = new Statement.ProcedureCallStatement(root, call);
                        }
                        else
                        {
                            Root.AddError("Cannot parse call expression");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot parse expression");
                }
            }

            return(retVal);
        }
Esempio n. 3
0
        /// <summary>
        ///     Parses a statement
        /// </summary>
        /// <returns></returns>
        private Statement.Statement InnerParseStatement()
        {
            Statement.Statement retVal = null;

            int start = Index;
            if (LookAhead("APPLY"))
            {
                Match("APPLY");
                Statement.Statement appliedStatement = InnerParseStatement();
                if (appliedStatement != null)
                {
                    Match("ON");
                    Expression listExpression = Expression(0);
                    Expression condition = null;
                    if (LookAhead("|"))
                    {
                        Match("|");
                        condition = Expression(0);
                    }
                    retVal = new ApplyStatement(Root, RootLog, appliedStatement, listExpression, condition, start, Index);
                }
                else
                {
                    RootLog.AddError("Cannot parse call expression");
                }
            }
            else if (LookAhead("INSERT"))
            {
                Match("INSERT");
                Expression value = Expression(0);
                if (value != null)
                {
                    Match("IN");
                    Expression list = Expression(0);
                    Expression replaceElement = null;
                    if (LookAhead("WHEN"))
                    {
                        Match("WHEN");
                        Match("FULL");
                        Match("REPLACE");

                        replaceElement = Expression(0);
                    }
                    retVal = new InsertStatement(Root, RootLog, value, list, replaceElement, start, Index);
                }
            }
            else if (LookAhead("REMOVE"))
            {
                Match("REMOVE");

                RemoveStatement.PositionEnum position = RemoveStatement.PositionEnum.First;
                if (LookAhead("FIRST"))
                {
                    Match("FIRST");
                }
                else if (LookAhead("LAST"))
                {
                    Match("LAST");
                    position = RemoveStatement.PositionEnum.Last;
                }
                else if (LookAhead("ALL"))
                {
                    Match("ALL");
                    position = RemoveStatement.PositionEnum.All;
                }

                Expression condition = null;
                if (!LookAhead("IN"))
                {
                    condition = Expression(0);
                }
                Match("IN");
                Expression list = Expression(0);
                retVal = new RemoveStatement(Root, RootLog, condition, position, list, start, Index);
            }
            else if (LookAhead("REPLACE"))
            {
                Match("REPLACE");
                Expression condition = Expression(0);
                Match("IN");
                Expression list = Expression(0);
                Match("BY");
                Expression value = Expression(0);

                retVal = new ReplaceStatement(Root, RootLog, value, list, condition, start, Index);
            }
            else
            {
                Expression expression = Expression(0);
                if (expression != null)
                {
                    string assignOp = LookAhead(AssignOps);
                    if (assignOp != null)
                    {
                        // This is a variable update
                        Match(assignOp);
                        if (LookAhead("%"))
                        {
                            Match("%");
                        }
                        Expression expression2 = Expression(0);

                        if (expression2 != null)
                        {
                            retVal = new VariableUpdateStatement(Root, RootLog, expression, expression2, start, Index);
                        }
                        else
                        {
                            RootLog.AddError("Invalid <- right side");
                        }
                        expression.Enclosing = retVal;
                    }
                    else
                    {
                        // This is a procedure call
                        Call call = expression as Call;
                        if (call != null)
                        {
                            retVal = new ProcedureCallStatement(Root, RootLog, call, start, Index);
                        }
                    }
                }
            }

            return retVal;
        }
Esempio n. 4
0
        /// <summary>
        /// Provides the Term at position Index of the Buffer.        
        /// </summary>
        /// <param name="root">The root element for which this term is built</param>
        /// <returns></returns>
        private Statement.Statement Statement(ModelElement root)
        {
            Statement.Statement retVal = null;

            Root = root;
            if (LookAhead("APPLY"))
            {
                Match("APPLY");
                Call callExpression = Expression(0) as Call;
                if (callExpression != null)
                {
                    Statement.ProcedureCallStatement call = new Statement.ProcedureCallStatement(root, callExpression);
                    Match("ON");
                    Expression listExpression = Expression(0);
                    Expression condition = null;
                    if (LookAhead("|"))
                    {
                        Match("|");
                        condition = Expression(0);
                    }
                    retVal = new Statement.ApplyStatement(root, call, listExpression, condition);
                }
                else
                {
                    Root.AddError("Cannot parse call expression");
                }
            }
            else if (LookAhead("INSERT"))
            {
                Match("INSERT");
                Expression value = Expression(0);
                if (value != null)
                {
                    Match("IN");
                    Expression list = Expression(0);
                    Expression replaceElement = null;
                    if (LookAhead("WHEN"))
                    {
                        Match("WHEN");
                        Match("FULL");
                        Match("REPLACE");

                        replaceElement = Expression(0);
                    }
                    retVal = new Statement.InsertStatement(root, value, list, replaceElement);
                }
            }
            else if (LookAhead("REMOVE"))
            {
                Match("REMOVE");

                Statement.RemoveStatement.PositionEnum position = Interpreter.Statement.RemoveStatement.PositionEnum.First;
                if (LookAhead("FIRST"))
                {
                    Match("FIRST");
                }
                else if (LookAhead("LAST"))
                {
                    Match("LAST");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.Last;
                }
                else if (LookAhead("ALL"))
                {
                    Match("ALL");
                    position = Interpreter.Statement.RemoveStatement.PositionEnum.All;
                }

                Expression condition = null;
                if (!LookAhead("IN"))
                {
                    condition = Expression(0);
                }
                Match("IN");
                Expression list = Expression(0);
                retVal = new Statement.RemoveStatement(root, condition, position, list);
            }
            else if (LookAhead("REPLACE"))
            {
                Match("REPLACE");
                Expression condition = Expression(0);
                Match("IN");
                Expression list = Expression(0);
                Match("BY");
                Expression value = Expression(0);

                retVal = new Statement.ReplaceStatement(root, value, list, condition);
            }
            else
            {
                Expression expression = Expression(0);
                if (expression != null)
                {
                    if (LookAhead("<-"))
                    {
                        // This is a variable update
                        Match("<-");
                        if (LookAhead("%"))
                        {
                            Match("%");
                        }
                        Expression expression2 = Expression(0);

                        if (expression2 != null)
                        {
                            retVal = new Statement.VariableUpdateStatement(root, expression, expression2);
                        }
                        else
                        {
                            Root.AddError("Invalid <- right side");
                        }
                        expression.Enclosing = retVal;
                    }
                    else
                    {
                        // This is a procedure call
                        Call call = expression as Call;
                        if (call != null)
                        {
                            retVal = new Statement.ProcedureCallStatement(root, call);
                        }
                        else
                        {
                            Root.AddError("Cannot parse call expression");
                        }
                    }
                }
                else
                {
                    Root.AddError("Cannot parse expression");
                }
            }

            return retVal;
        }