Example #1
0
def p_expr_and(p: Any) -> None:
    'expr : expr AMPERSAND expr'
    l: syntax.Expr = p[1]
    r: syntax.Expr = p[3]
    span = loc_join(l.span, r.span)
    if isinstance(l, syntax.NaryExpr) and l.op == 'AND':
        p[0] = syntax.NaryExpr('AND', l.args + (r,), span=span)
    else:
        p[0] = syntax.NaryExpr('AND', (l, r), span=span)
Example #2
0
def p_expr_or(p: Any) -> None:
    'expr : expr PIPE expr'
    l: syntax.Expr = p[1]
    r: syntax.Expr = p[3]
    span = loc_join(l.span, r.span)
    if isinstance(l, syntax.NaryExpr) and l.op == 'OR':
        p[0] = syntax.NaryExpr('OR', l.args + (r,), span=span)
    else:
        span = loc_join(l.span, r.span)
        p[0] = syntax.NaryExpr('OR', (l, r), span=span)
Example #3
0
def p_expr_or(p: Any) -> None:
    'expr : expr PIPE expr'
    l = p[1]
    if isinstance(l, syntax.NaryExpr) and l.op == 'OR':
        l.args.append(p[3])
        p[0] = l
    else:
        p[0] = syntax.NaryExpr(p.slice[2], 'OR', [l, p[3]])
Example #4
0
def p_expr_and(p: Any) -> None:
    'expr : expr AMPERSAND expr'
    l = p[1]
    if isinstance(l, syntax.NaryExpr) and l.op == 'AND':
        l.args.append(p[3])
        p[0] = l
    else:
        p[0] = syntax.NaryExpr(p.slice[2], 'AND', [l, p[3]])
Example #5
0
def p_expr_or(p: Any) -> None:
    'expr : expr PIPE expr'
    l: syntax.Expr = p[1]
    r: syntax.Expr = p[3]
    if isinstance(l, syntax.NaryExpr) and l.op == 'OR':
        l.args.append(p[3])
        l.span = loc_join(l.span, r.span)
        p[0] = l
    else:
        span = loc_join(l.span, r.span)
        p[0] = syntax.NaryExpr('OR', [l, r], span=span)
Example #6
0
def p_expr_and(p: Any) -> None:
    'expr : expr AMPERSAND expr'
    l: syntax.Expr = p[1]
    r: syntax.Expr = p[3]
    if isinstance(l, syntax.NaryExpr) and l.op == 'AND':
        l.args.append(r)
        l.span = loc_join(l.span, r.span)
        p[0] = l
    else:
        span = loc_join(l.span, r.span)
        p[0] = syntax.NaryExpr('AND', [l, r], span=span)
Example #7
0
def negate_clause(c: Expr) -> Expr:
    if isinstance(c, syntax.Bool):
        return syntax.Bool(not c.val)
    elif isinstance(c, syntax.UnaryExpr):
        assert c.op == 'NOT'
        return c.arg
    elif isinstance(c, syntax.BinaryExpr):
        assert c.op in ['EQUAL', 'NOTEQ']
        op = 'NOTEQ' if c.op == 'EQUAL' else 'EQUAL'
        return syntax.BinaryExpr(op, c.arg1, c.arg2)
    elif isinstance(c, syntax.NaryExpr):
        assert c.op == 'OR'
        return syntax.NaryExpr('AND', [negate_clause(arg) for arg in c.args])
    elif isinstance(c, syntax.AppExpr) or isinstance(c, syntax.Id):
        return syntax.Not(c)
    else:
        assert False, f'unsupported expression {c} in negate_clause'
Example #8
0
def negate_clause(c: Expr) -> Expr:
    if isinstance(c, syntax.Bool):
        return syntax.Bool(not c.val)
    elif isinstance(c, syntax.UnaryExpr):
        assert c.op == 'NOT'
        return c.arg
    elif isinstance(c, syntax.BinaryExpr):
        assert c.op in ['EQUAL', 'NOTEQ']
        op = 'NOTEQ' if c.op == 'EQUAL' else 'EQUAL'
        return syntax.BinaryExpr(op, c.arg1, c.arg2)
    elif isinstance(c, syntax.NaryExpr):
        assert c.op == 'OR'
        return syntax.NaryExpr('AND', tuple(negate_clause(arg) for arg in c.args))
    elif isinstance(c, syntax.AppExpr) or isinstance(c, syntax.Id):
        return syntax.Not(c)
    elif isinstance(c, syntax.QuantifierExpr):
        assert c.quant == 'FORALL'
        return syntax.QuantifierExpr('EXISTS', c.get_vs(), negate_clause(c.body))
    else:
        assert False, f'unsupported expression {c} in negate_clause'
Example #9
0
def p_expr_distinct(p: Any) -> None:
    'expr : DISTINCT LPAREN args1 RPAREN'
    p[0] = syntax.NaryExpr(p.slice[1], 'DISTINCT', p[3])
Example #10
0
def p_expr_distinct(p: Any) -> None:
    'expr : DISTINCT LPAREN args1 RPAREN'
    p[0] = syntax.NaryExpr('DISTINCT', p[3], span=loc_join(p.slice[1], p.slice[4]))