Ejemplo n.º 1
0
        private Expression And()
        {
            var expression = Equality();

            while (Match(TokenType.And))
            {
                var token = Previous();
                var right = Equality();
                expression = new Expression.Logical(expression, token, right);
            }

            return(expression);
        }
Ejemplo n.º 2
0
        private Expression Or()
        {
            var expression = And();

            while (Match(TokenType.Or))
            {
                var token = Previous();
                var right = And();
                expression = new Expression.Logical(expression, token, right);
            }

            return(expression);
        }
Ejemplo n.º 3
0
        public object VisitLogical(Expression.Logical expression)
        {
            var left = Evaluate(expression.Left);

            if (expression.Operator.Type == TokenType.Or)
            {
                if (IsTruthy(left))
                {
                    return(left);
                }
            }
            else
            {
                if (!IsTruthy(left))
                {
                    return(left);
                }
            }

            return(Evaluate(expression.Right));
        }
Ejemplo n.º 4
0
 public string VisitLogical(Expression.Logical expression)
 {
     return(Parenthesize(expression.Left.Accept(this) + expression.Operator.Lexeme + expression.Right.Accept(this)));
 }