public BinaryExpression(int line, int column, Expression lhs, TokenType op, Expression rhs)
     : base(line, column)
 {
     this.lhs = lhs;
     this.op = op;
     this.rhs = rhs;
 }
Beispiel #2
0
 private bool EvalCondition(Expression expr, TemplateContext context)
 {
     object val = expr.Eval(context);
     if (val is Boolean)
         return (Boolean)val;
     else if (val is Int32)
         return ((Int32)val) != 0;
     else if (val is Decimal)
         return ((Decimal)val) != 0;
     else if (val != null)
         return true;
     else
         return false;
 }
Beispiel #3
0
 private Expression ParseAdditiveExpressionRest(Expression lhs)
 {
     if (Current.TokenType == TokenType.Plus
         || Current.TokenType == TokenType.Minus)
     {
         Token tok = Consume(); // +, -
         Expression rhs = ParseMultiplyExpression();
         BinaryExpression lhsChild = new BinaryExpression(lhs.Line, lhs.Column, lhs, tok.TokenType, rhs);
         return ParseAdditiveExpressionRest(lhsChild);
     }
     else
     {
         return lhs;
     }
 }
Beispiel #4
0
        private Expression ParseMultiplyExpressionRest(Expression lhs)
        {
            if (Current.TokenType == TokenType.Mult
                || Current.TokenType == TokenType.Div
                || Current.TokenType == TokenType.Mod)
            {
                Token tok = Consume(); // *, /, %
                Expression rhs = ParseUnaryExpression();
                BinaryExpression lhsChild = new BinaryExpression(lhs.Line, lhs.Column, lhs, tok.TokenType, rhs);
                return ParseMultiplyExpressionRest(lhsChild);
            }

            return lhs;
        }
Beispiel #5
0
 private Expression ParseLogicalExpressionRest(Expression lhs)
 {
     if (Current.TokenType == TokenType.And || Current.TokenType == TokenType.Or)
     {
         Consume(); // &&, ||
         Expression rhs = ParseRelationalExpression();
         BinaryExpression lhsChild = new BinaryExpression(lhs.Line, lhs.Column, lhs, TokenType.And, rhs);
         return ParseLogicalExpressionRest(lhsChild);
     }
     else
     {
         return lhs;
     }
 }