aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/precedence.zc
blob: 18b323dd29098eb3475c72e4879cf0f80c1c6054 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
// && binds tighter than ||, and both bind below the comparisons and |, as in c.
include rt;
int calls;
int seen(int v) { calls++; return v; }
fn main() {
	int t = 1, f = 0;
	rt.put_n(f && t || t); rt.put_c(32);	// (f && t) || t is 1; f && (t || t) would be 0
	rt.put_n(t || t && f); rt.put_c(32);	// t || (t && f) is 1
	rt.put_n(f && f || t && t); rt.put_c(32);
	rt.put_n(1 | 0 && 2 == 2); rt.put_c(32);
	calls = 0; int r = seen(1) || seen(0) && seen(1);
	rt.put_n(r); rt.put_c(32); rt.put_n(calls); rt.put_c(10);	// || stops after the first call
}