Esempio n. 1
0
 void PushOperator(TTEOperator op)
 {
     // while (_operators.Peek().Precedence > op.Precedence)
     while (TTEOperator.Compare(_operators.Peek(), op))
     {
         PopOperator();
     }
     _operators.Push(op);
 }
Esempio n. 2
0
 bool MatchUnary(out TTEOperator op)
 {
     if (Match("!"))
     {
         op = TTEOperator.Not;
     }
     else
     {
         op = null;
         return(false);
     }
     return(true);
 }
        public static bool Compare(TTEOperator op1, TTEOperator op2)
        {
            if ((op1 == Ternary || op1 == RhsTernary) && (op2 == Ternary || op2 == RhsTernary))
            {
                return(op1 == RhsTernary && op2 == RhsTernary);
            }

            if (op1 == Sentinel || op2 == Sentinel)
            {
                return(false);
            }
            return(op1.Precedence > op2.Precedence);
        }
Esempio n. 4
0
        bool LegacyOperator(out ITTEExpression expr)
        {
            TTEOperator op = null;

            if (MatchAll(true, Kw("Add"), "("))
            {
                op = TTEOperator.Add;
            }
            else if (MatchAll(true, Kw("Subtract"), "("))
            {
                op = TTEOperator.Subtract;
            }
            else if (MatchAll(true, Kw("Multiply"), "("))
            {
                op = TTEOperator.Multiply;
            }
            else if (MatchAll(true, Kw("Divide"), "("))
            {
                op = TTEOperator.Divide;
            }
            else if (MatchAll(true, Kw("Modulo"), "("))
            {
                op = TTEOperator.Modulo;
            }
            else if (MatchAll(true, Kw("Raise To Power"), "("))
            {
                op = TTEOperator.Power;
            }
            else if (MatchAll(true, Kw("And"), "("))
            {
                op = TTEOperator.And;
            }
            else if (MatchAll(true, Kw("Or"), "("))
            {
                op = TTEOperator.Or;
            }
            else if (MatchAll(true, Kw("Compare"), "("))
            {
                ContainExpression(out ITTEExpression compareLeft);
                Match(",");

                if (Match("=="))
                {
                    op = TTEOperator.Equal;
                }
                else if (Match("!="))
                {
                    op = TTEOperator.NotEqual;
                }
                else if (Match(">="))
                {
                    op = TTEOperator.GreaterThanOrEqual;
                }
                else if (Match("<="))
                {
                    op = TTEOperator.LessThanOrEqual;
                }
                else if (Match(">"))
                {
                    op = TTEOperator.GreaterThan;
                }
                else if (Match("<"))
                {
                    op = TTEOperator.LessThan;
                }

                Match(",");
                ContainExpression(out ITTEExpression compareRight);
                Match(")");

                expr = new BinaryOperatorExpression(compareLeft, compareRight, op);
                return(true);
            }
            else if (MatchAll(true, Kw("If-Then-Else"), "("))
            {
                ContainExpression(out ITTEExpression condition);
                Match(",");
                ContainExpression(out ITTEExpression consequent);
                Match(",");
                ContainExpression(out ITTEExpression alternative);
                Match(")");

                expr = new TernaryExpression(condition, consequent, alternative);
                return(true);
            }

            if (op == null)
            {
                expr = null;
                return(false);
            }

            ContainExpression(out ITTEExpression left);
            Match(",");
            ContainExpression(out ITTEExpression right);
            Match(")");

            expr = new BinaryOperatorExpression(left, right, op);
            return(true);
        }
Esempio n. 5
0
        // Operators
        bool MatchOperator(out TTEOperator op)
        {
            // Make sure we do not match modify operators.
            // +=, -=, ect.
            bool isModify = false;

            Lookahead(() => {
                isModify = Match("-=") || Match("+=") || Match("%=") || Match("/=") || Match("*=") || Match("^=");
                return(false);
            });

            // If we do, set op to null then return false.
            if (isModify)
            {
                op = null;
                return(false);
            }

            if (Match("&&"))
            {
                op = TTEOperator.And;
            }
            else if (Match("||"))
            {
                op = TTEOperator.Or;
            }
            else if (Match("-"))
            {
                op = TTEOperator.Subtract;
            }
            else if (Match("+"))
            {
                op = TTEOperator.Add;
            }
            else if (Match("%"))
            {
                op = TTEOperator.Modulo;
            }
            else if (Match("/"))
            {
                op = TTEOperator.Divide;
            }
            else if (Match("*"))
            {
                op = TTEOperator.Multiply;
            }
            else if (Match("^"))
            {
                op = TTEOperator.Power;
            }
            else if (Match("=="))
            {
                op = TTEOperator.Equal;
            }
            else if (Match("!="))
            {
                op = TTEOperator.NotEqual;
            }
            else if (Match(">="))
            {
                op = TTEOperator.GreaterThanOrEqual;
            }
            else if (Match("<="))
            {
                op = TTEOperator.LessThanOrEqual;
            }
            else if (Match(">"))
            {
                op = TTEOperator.GreaterThan;
            }
            else if (Match("<"))
            {
                op = TTEOperator.LessThan;
            }
            else if (Match("?"))
            {
                op = TTEOperator.Ternary;
            }
            else if (Match(":"))
            {
                op = TTEOperator.RhsTernary;
            }
            else
            {
                op = null;
                return(false);
            }
            return(true);
        }
 public BinaryOperatorExpression(ITTEExpression left, ITTEExpression right, TTEOperator op)
 {
     Left     = left;
     Right    = right;
     Operator = op;
 }
Esempio n. 7
0
 // Operators
 bool MatchOperator(out TTEOperator op)
 {
     if (Match("&&"))
     {
         op = TTEOperator.And;
     }
     else if (Match("||"))
     {
         op = TTEOperator.Or;
     }
     else if (Match("-"))
     {
         op = TTEOperator.Subtract;
     }
     else if (Match("+"))
     {
         op = TTEOperator.Add;
     }
     else if (Match("%"))
     {
         op = TTEOperator.Modulo;
     }
     else if (Match("/"))
     {
         op = TTEOperator.Divide;
     }
     else if (Match("*"))
     {
         op = TTEOperator.Multiply;
     }
     else if (Match("^"))
     {
         op = TTEOperator.Power;
     }
     else if (Match("=="))
     {
         op = TTEOperator.Equal;
     }
     else if (Match("!="))
     {
         op = TTEOperator.NotEqual;
     }
     else if (Match(">="))
     {
         op = TTEOperator.GreaterThanOrEqual;
     }
     else if (Match("<="))
     {
         op = TTEOperator.LessThanOrEqual;
     }
     else if (Match(">"))
     {
         op = TTEOperator.GreaterThan;
     }
     else if (Match("<"))
     {
         op = TTEOperator.LessThan;
     }
     else if (Match("?"))
     {
         op = TTEOperator.Ternary;
     }
     else if (Match(":"))
     {
         op = TTEOperator.RhsTernary;
     }
     else
     {
         op = null;
         return(false);
     }
     return(true);
 }