Beispiel #1
0
        private Expression ParseExponent(Type Desired = null)
        {
            ConsumeWS();
            Expression C1, C2;
            char       ch;

            C1 = ParseUnary();
            do
            {
                ConsumeWS();
                ch = Read()[0];
                switch (ch)
                {
                case '^':
                    C2 = ParseUnary();
                    C1 = Expression.Power(
                        C1.ConvertTo(typeof(double)),
                        C2.ConvertTo(typeof(double)));
                    continue;
                }
                SeekRelative(-1);
                break;
            } while (!EOL);
            return(C1);
        }
Beispiel #2
0
        private Expression ParseMultiplicative(Type Desired = null)
        {
            ConsumeWS();
            Expression C1, C2;
            char       ch;

            C1 = ParseExponent();
            do
            {
                ConsumeWS();
                ch = Read()[0];
                switch (ch)
                {
                case '*':
                    if (Peek() == "=")
                    {
                        break;
                    }
                    C2 = ParseExponent();
                    C1 = Expression.Multiply(
                        C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                        C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    continue;

                case '/':
                    if (Peek() == "=")
                    {
                        break;
                    }
                    C2 = ParseExponent();
                    C1 = Expression.Divide(
                        C1.ConvertTo(typeof(double)),
                        C2.ConvertTo(typeof(double)));
                    continue;

                case '%':
                    C2 = ParseExponent();
                    C1 = Expression.Modulo(
                        C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                        C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    continue;
                }
                SeekRelative(-1);
                break;
            } while (!EOL);
            return(C1);
        }
Beispiel #3
0
        private Expression ParseBoolean(bool ExpectAssign = true, Type Desired = null)
        {
            ConsumeWS();
            Expression C1;
            char       ch;

            C1 = ParseRelationnal(ExpectAssign);
            do
            {
                ConsumeWS();
                ch = char.ToUpper(Read()[0]);
                switch (ch)
                {
                case 'A': if (Peek(3).ToUpper() == "ND ")
                    {
                        Consume(3);
                        C1 = Expression.AndAlso(C1.ConvertTo(typeof(bool)), ParseRelationnal(ExpectAssign).ConvertTo(typeof(bool)));
                    }
                    else
                    {
                        break;
                    }
                    continue;

                case 'O': if (Peek(2).ToUpper() == "R ")
                    {
                        Consume(2);
                        C1 = Expression.OrElse(C1.ConvertTo(typeof(bool)), ParseRelationnal(ExpectAssign).ConvertTo(typeof(bool)));
                    }
                    else
                    {
                        break;
                    }
                    continue;
                }
                SeekRelative(-1);
                break;
            } while (!EOL);
            if (C1 is VarAutExpression)
            {
                C1 = (C1 as VarAutExpression).Getter(null);
            }
            return(C1);
        }
        private Expression ParseAdditive(Type Desired = null)
        {
            ConsumeWS();
            Expression C1, C2;
            char       ch;

            C1 = ParseMultiplicative();
            do
            {
                ConsumeWS();
                ch = Read()[0];
                switch (ch)
                {
                case '+':
                    if (Peek() == "=")
                    {
                        break;
                    }
                    C2 = ParseMultiplicative();
                    C1 = Expression.Add(
                        C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                        C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    continue;

                case '-':
                    if (Peek() == "=")
                    {
                        break;
                    }
                    C2 = ParseMultiplicative();
                    C1 = Expression.Subtract(
                        C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                        C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    continue;
                }
                SeekRelative(-1);
                break;
            } while (!EOL);
            return(C1);
        }
        private Expression ParseRelationnal(bool ExpectAssign = true, Type Desired = null)
        {
            ConsumeWS();
            Expression C1, C2;
            char       ch;

            C1 = ParseConcat();
            do
            {
                ConsumeWS();
                ch = Read()[0];
                switch (ch)
                {
                case '<':
                    if (Peek() == ">")
                    {
                        Consume();
                        C2 = ParseConcat().ConvertTo(C1.Type);
                        C1 = Expression.NotEqual(C1, C2);
                    }
                    else if (Peek() == "=")
                    {
                        Consume();
                        C2 = ParseConcat();
                        C1 = Expression.LessThanOrEqual(
                            C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                            C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    }
                    else
                    {
                        C2 = ParseConcat();
                        C1 = Expression.LessThan(
                            C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                            C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    }

                    continue;

                case '>':
                    if (Peek() == "=")
                    {
                        Consume();
                        C2 = ParseConcat();
                        C1 = Expression.GreaterThanOrEqual(
                            C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                            C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    }
                    else
                    {
                        C2 = ParseConcat();
                        C1 = Expression.GreaterThan(
                            C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                            C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    }
                    continue;

                case '=':
                    if (Peek() == "=")
                    {
                        throw new NotSupportedException("Sorry, No support for ==");
                        C2 = ParseConcat();
                        C1 = Expression.AndAlso(Expression.TypeEqual(C1, C2.Type), Expression.Equal(C1, C2));
                    }
                    else if (ExpectAssign)
                    {
                        if (C1 is VarAutExpression)
                        {
                            Consume();
                            var value = ParseBoolean(false);
                            C1 = (C1 as VarAutExpression).Setter(value);
                        }
                        else
                        {
                            throw new AutoitException(AutoitExceptionType.ASSIGNTONOTVARIABLE, LineNumber, Cursor, C1.ToString());
                        }
                    }
                    else
                    {
                        C2 = ParseConcat();
                        C1 = Expression.Equal(
                            C1.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                            C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type)));
                    }
                    continue;

                case '+':
                    if (Peek() != "=" || !ExpectAssign)
                    {
                        break;
                    }
                    Consume();
                    if (C1 is VarAutExpression)
                    {
                        ConsumeWS();
                        C2 = ParseBoolean(false);
                        C1 = (C1 as VarAutExpression).Setter(
                            Expression.Add(
                                (C1 as VarAutExpression).Getter(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                                C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type))
                                )
                            );
                    }
                    else
                    {
                        throw new AutoitException(AutoitExceptionType.ASSIGNTONOTVARIABLE, LineNumber, Cursor, C1.ToString());
                    }
                    continue;

                case '-':
                    if (Peek() != "=" || !ExpectAssign)
                    {
                        break;
                    }
                    Consume();
                    if (C1 is VarAutExpression)
                    {
                        ConsumeWS();
                        C2 = ParseBoolean(false);
                        C1 = (C1 as VarAutExpression).Setter(
                            Expression.Subtract(
                                (C1 as VarAutExpression).Getter(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                                C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type))
                                )
                            );
                    }
                    else
                    {
                        throw new AutoitException(AutoitExceptionType.ASSIGNTONOTVARIABLE, LineNumber, Cursor, C1.ToString());
                    }
                    continue;

                case '*':
                    if (Peek() != "=" || !ExpectAssign)
                    {
                        break;
                    }
                    Consume();
                    if (C1 is VarAutExpression)
                    {
                        ConsumeWS();
                        C2 = ParseBoolean(false);
                        C1 = (C1 as VarAutExpression).Setter(
                            Expression.Multiply(
                                (C1 as VarAutExpression).Getter(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                                C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type))
                                )
                            );
                    }
                    else
                    {
                        throw new AutoitException(AutoitExceptionType.ASSIGNTONOTVARIABLE, LineNumber, Cursor, C1.ToString());
                    }
                    continue;

                case '/':
                    if (Peek() != "=" || !ExpectAssign)
                    {
                        break;
                    }

                    ConsumeWS();
                    if (C1 is VarAutExpression)
                    {
                        ConsumeWS();
                        C2 = ParseBoolean(false);
                        C1 = (C1 as VarAutExpression).Setter(
                            Expression.Divide(
                                (C1 as VarAutExpression).Getter(ExpressionTypeBeam.Largest(C1.Type, C2.Type)),
                                C2.ConvertTo(ExpressionTypeBeam.Largest(C1.Type, C2.Type))
                                )
                            );
                    }
                    else
                    {
                        throw new AutoitException(AutoitExceptionType.ASSIGNTONOTVARIABLE, LineNumber, Cursor, C1.ToString());
                    }
                    continue;
                }
                SeekRelative(-1);
                break;
            } while (!EOL);
            return(C1);
        }