Пример #1
0
        /// <summary>
        /// Rule: AndExpr -> NotExpr (AND NotExpr )* ;
        /// </summary>
        protected override object EvalAndExpr(ParseTree tree, params object[] paramlist)
        {
            if (GetNode(TokenType.AND) == null)
            {
                return((ExpressionBase)GetNode(TokenType.NotExpr).Eval(tree));
            }

            var expressions = new Stack <ExpressionBase>(nodes.OfTokenType(TokenType.NotExpr).Select(n => n.Eval(tree)).Cast <ExpressionBase>().Reverse());

            while (expressions.Count > 1)
            {
                var leftExpr  = expressions.Pop();
                var rightExpr = expressions.Pop();
                var newExpr   = new AndOrExpr
                {
                    First  = leftExpr,
                    Second = rightExpr,
                    Node   = this,
                    Type   = AndOrOperation.And
                };
                expressions.Push(newExpr);
            }

            return(expressions.First());
        }
Пример #2
0
        public dynamic Visit(AndOrExpr expr)
        {
            var node = Visit((ExpressionBase)expr);

            node.Text = expr.Type.ToString();
            return(node);
        }
        public dynamic Visit(AndOrExpr expr)
        {
            Visit((ExpressionBase)expr);
            if (OptimizeMode.ExpressionSimplify)
            {
                var left  = expr.First as LiteralExpr;
                var right = expr.Second as LiteralExpr;
                if (left != null && right != null)
                {
                    var literal = new LiteralExpr {
                        Namespace = expr.Namespace, Node = expr.Node, SymbolType = expr.GetExprType()
                    };
                    bool result;
                    switch (expr.Type)
                    {
                    case AndOrOperation.Or:
                        result = left.Value || right.Value;
                        break;

                    case AndOrOperation.And:
                        result = left.Value && right.Value;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    literal.Value = result;
                    return(literal);
                }
            }
            return(expr);
        }
 public dynamic Visit(AndOrExpr expr)
 {
     if (expr.FirstType != SymbolType.Bool || expr.SecondType != SymbolType.Bool)
     {
         throw new ParseException("Логические операции можно производить только над типом Bool", expr.Node);
     }
     return(SymbolType.Bool);
 }
        public dynamic Visit(AndOrExpr expr)
        {
            var left  = _codeGen.Local(Visit((dynamic)expr.First)) as Operand;
            var right = _codeGen.Local(Visit((dynamic)expr.Second)) as Operand;

            switch (expr.Type)
            {
            case AndOrOperation.Or:
                return(left || right);

            case AndOrOperation.And:
                return(left && right);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public dynamic Visit(AndOrExpr expr)
 {
     Visit((ExpressionBase)expr);
     return(null);
 }