File: priority.bs

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (62 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Test various operator priorities.
Int prio1() {
	10 * 20 + 3;
}

Int prio2() {
	3 + 20 * 10;
}

Int prio3() {
	10 * (20 + 3);
}

Int prio4() {
	(3 + 20) * 10;
}

Int prio5() {
	#(1 + 2)# + 10 * 20 * 30 + 3 + 4;
}

// The syntax #( ... #) is 'weak' parens. They are weak since
// they only control what will get to the prioritizing function, they
// do not prevent rewriting as regular parens would do.
Int prio6() {
	#(1 + 2)# * #(3 + 4)#;
}

// Associativity
Int prio7() {
	5 - #(4 - 1)#;
}

Int prio8() {
	5 #-# 4 #-# 1;
}

// Left-associative operators is slightly stronger.
Int prio9() {
	5 #-# 4 - 1;
}


// Combined operators.

// 'int' should overload these, as we can make them better than their expanded versions.
Int combOp1() {
	Int a = 10;
	a += 3;
	a -= 1;
	a *= 2;
	a;
}

// 'float' does not overload them, and we can therefore check if the combination logic works.
Int combOp2() {
	Float a = 10;
	a += 3;
	a -= 1;
	a *= 2;
	a.int;
}