ternary : expr '?' expr ':' expr
14820
Expr ternary() {
		Expr cond = or();
		if (peek().sym == Sym.QUESTION) {
			move();
			Expr exprOne = expr();
			match(Sym.COLON);
			return new Ternary(cond, exprOne, expr(), location);
		}
		return cond;
	}
713023
def _expression(expression):
    # type: (QuilParser.ExpressionContext) -> Any
    
    if isinstance(expression, QuilParser.ParenthesisExpContext):
        return _expression(expression.expression())
    elif isinstance(expression, QuilParser.PowerExpContext):
        if expression.POWER():
            return _binary_exp(expression, operator.pow)
    elif isinstance(expression, QuilParser.MulDivExpContext):
        if expression.TIMES():
            return _binary_exp(expression, operator.mul)
        elif expression.DIVIDE():
            return _binary_exp(expression, operator.truediv)
    elif isinstance(expression, QuilParser.AddSubExpContext):
        if expression.PLUS():
            return _binary_exp(expression, operator.add)
        elif expression.MINUS():
            return _binary_exp(expression, operator.sub)
    elif isinstance(expression, QuilParser.SignedExpContext):
        if expression.sign().PLUS():
            return _expression(expression.expression())
        elif expression.sign().MINUS():
            return -1 * _expression(expression.expression())
    elif isinstance(expression, QuilParser.FunctionExpContext):
        return _apply_function(expression.function(), _expression(expression.expression()))
    elif isinstance(expression, QuilParser.AddrExpContext):
        return _addr(expression.addr())
    elif isinstance(expression, QuilParser.NumberExpContext):
        return _number(expression.number())
    elif isinstance(expression, QuilParser.VariableExpContext):
        return _variable(expression.variable())

    raise RuntimeError("Unexpected expression type:" + expression.getText())
1137209
def expr(obj, simplify=True):
    """"""
    if isinstance(obj, Expression):
        return obj
    # False, True, 0, 1
    elif isinstance(obj, int) and obj in {0, 1}:
        return _CONSTS[obj]
    elif isinstance(obj, str):
        ast = pyeda.parsing.boolexpr.parse(obj)
        ex = ast2expr(ast)
        if simplify:
            ex = ex.simplify()
        return ex
    else:
        return One if bool(obj) else Zero
1216379
def p_exprs(p):
    
    if len(p) == 2:
        p[0] = node.expr_list([p[1]])
    elif len(p) == 4:
        p[0] = p[1]
        p[0].append(p[3])
    else:
        assert (0)
    assert isinstance(p[0], node.expr_list)
600250
def _parse_expr(self, part):
        
        self._logger.debug("parsing expression: " + unicode(part))
        key, op, val = part

        success = True
        dictsql = {
                'operator': op,
                'val1': key,
                'val2': unicode(val),
                'interpretation': {
                    'string': key + op + val,
                    'interpretation': 'expression',
                    'attribute': key,
                    'operator': op,
                    'error': False
                }
            }

        if key in self.attributes:
            if type(self.attributes[key]) is list:
                if val not in self.attributes[key]:
                    dictsql['interpretation']['error'] = True
                    dictsql['interpretation']['error_message'] = 'invalid value'
                    success = False

        else:
            dictsql['interpretation']['error'] = True
            dictsql['interpretation']['error_message'] = 'unknown attribute'
            success = False

        return success, dictsql
863444
def p_control_expr(self, p):
        ''''''
        if len(p) == 9:
            p[0] = (p[1], (p[3], p[6], p[8]))
        elif len(p) == 8:
            p[0] = (p[1], (p[3], *p[6]))
438555
def p_expr(self, p):
        
        if len(p) == 2:
            p[0] = p[1]
        else:
            p[0] = self.asttypes.Comma(left=p[1], right=p[3])
            p[0].setpos(p, 2)
349431
def p_conditional_expr(self, p):
        
        if len(p) == 2:
            p[0] = p[1]
        else:
            p[0] = ast.Conditional(
                predicate=p[1], consequent=p[3], alternative=p[5])
169956
def ternary_operator(allow_assignments, wrapped)
      if (buffer = accept :exp_ternary)
        buffer += expression(allow_assignments, wrapped)[@value]
        if (else_branch = accept :exp_ternary_else)
          buffer += else_branch
          buffer += expression(allow_assignments, wrapped)[@value]
        end
        return buffer
      end
    end
966974
def p_pvar_expr(self, p):
        ''''''
        if len(p) == 2:
            p[0] = ('pvar_expr', (p[1], None))
        elif len(p) == 5:
            p[0] = ('pvar_expr', (p[1], p[3]))
950646
function parseConditionalExpression() {
        var expr, previousAllowIn, consequent;

        expr = parseLogicalORExpression();

        if (match('?')) {
            lex();
            previousAllowIn = state.allowIn;
            state.allowIn = true;
            consequent = parseAssignmentExpression();
            state.allowIn = previousAllowIn;
            expect(':');

            expr = {
                type: Syntax.ConditionalExpression,
                test: expr,
                consequent: consequent,
                alternate: parseAssignmentExpression()
            };
        }

        return expr;
    }
1353105
def eval_bool(self, expr):
        
        result = expr.eval(self)
        iterator = iter(result)
        try:
            next(iterator)
        except StopIteration:
            return False
        else:
            return True
        finally:
            if hasattr(iterator, "close"):
                iterator.close()
1127037
def p_expr_include(p):
    ''
    p[0] = ast.Include(p[2], False, lineno=p.lineno(1))
1296739
public final void ternaryExpression() throws RecognitionException {
		ParserRuleReturnScope ts =null;
		ParserRuleReturnScope fs =null;

		 ternOp++; 
		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:175:5: ( QUESTION ts= expression COLON fs= expression )
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:175:7: QUESTION ts= expression COLON fs= expression
			{
			match(input,QUESTION,FOLLOW_QUESTION_in_ternaryExpression854); if (state.failed) return;
			pushFollow(FOLLOW_expression_in_ternaryExpression858);
			ts=expression();
			state._fsp--;
			if (state.failed) return;
			match(input,COLON,FOLLOW_COLON_in_ternaryExpression860); if (state.failed) return;
			pushFollow(FOLLOW_expression_in_ternaryExpression864);
			fs=expression();
			state._fsp--;
			if (state.failed) return;
			}

		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
			 ternOp--; 
		}
	}
615861
def p_expr_lbound_expr(p):
    
    entry = SYMBOL_TABLE.access_array(p[3], p.lineno(3))
    if entry is None:
        p[0] = None
        return

    entry.accessed = True
    num = make_typecast(TYPE.uinteger, p[5], p.lineno(6))

    if is_number(num):
        if num.value == 0:  # 0 => Number of dims
            p[0] = make_number(len(entry.bounds), p.lineno(3), TYPE.uinteger)
            return

        val = num.value - 1
        if val < 0 or val >= len(entry.bounds):
            syntax_error(p.lineno(6), "Dimension out of range")
            p[0] = None
            return

        if p[1] == 'LBOUND':
            p[0] = make_number(entry.bounds[val].lower, p.lineno(3), TYPE.uinteger)
        else:
            p[0] = make_number(entry.bounds[val].upper, p.lineno(3), TYPE.uinteger)
        return

    if p[1] == 'LBOUND':
        entry.lbound_used = True
    else:
        entry.ubound_used = True

    p[0] = make_builtin(p.lineno(1), p[1], [entry, num], type_=TYPE.uinteger)
38439
def p_expr_LT_expr(p):
    
    p[0] = make_binary(p.lineno(2), 'LT', p[1], p[3], lambda x, y: x < y)
113625
function readLogicalANDExpr(walker) {
    var expr = readEqualityExpr(walker);
    walker.goUntil();

    if (walker.currentCode() === 38) { // &
        if (walker.nextCode() === 38) {
            walker.go(1);
            return {
                type: ExprType.BINARY,
                operator: 76,
                segs: [expr, readLogicalANDExpr(walker)]
            };
        }

        walker.go(-1);
    }

    return expr;
}