Debian Codegraph @

terps/tads/tads3/test/data/expr.t

raw
1 /*
2 * Parser test - constant expressions. This tests basic parsing, order
3 * of precedence, and constant folding.
4 */
5
6 "test << f1(1)
7 >>";
8
9
10 'simple values';
11 'sstring with\ttab!';
12 "dstring";
13 1; // 1
14
15 'unary operators';
16 -2; // -2
17 +5; // 5
18 ~0x8f7f7f7f; // 0x70808080 = 1887469696
19
20 'magnitude comparisons';
21 1>2; // nil
22 1<2; // true
23 1 >= 2; // nil
24 2 >= 2; // true
25 3 >= 2; // true
26 1 <= 2; // true
27 2 <= 2; // true
28 3 <= 2; // nil
29 'hello' > 'goodbye'; // true
30 'hello' < 'goodbye'; // nil
31
32 'equality comparisons';
33 1 == 2; // nil
34 2 == 2; // true
35 1 != 2; // true
36 3 != 3; // nil
37
38 'addition and subtraction';
39 5+6; // 11
40 7 - 11; // -4
41
42 'multiplication and division';
43 3*4; // 12
44 4 * 5; // 20
45 16/3; // 5
46 17 % 7; // 3
47
48 'bitwise operators';
49 0x101 | 0x21; // 0x121 = 289
50 0x70F & 0x137; // 0x107 -> 263
51 0x101 ^ 0x171; // 0x70 -> 112
52
53 'bit shifts';
54 1 << 3; // 8
55 128 >> 2; // 32
56
57 'logical AND';
58 1 && 2; // true
59 nil && 5; // nil
60 1 && nil; // nil
61 nil && 0; // nil
62 0 && 0; // nil
63 0 && 1; // nil
64 true && a; // non-constant
65 nil && a; // nil
66
67 'logical OR';
68 true || nil; // true
69 1 || nil; // true
70 1 || 2; // true
71 nil || 5; // true
72 1 || nil; // true
73 nil || 0; // nil
74 0 || 0; // nil
75 0 || 1; // true
76 true || a; // true
77 nil || a; // non-constant
78
79 'conditional';
80 1 ? 2 : 3; // 2
81 0 ? 5 : 6; // 6
82 0 ? 111 : 2 ? 222 : 333; // 222
83 1 ? 444 : 2 ? 555 : 666; // 444
84 true ? 1 + 2 + 3 : a + b + c; // 6
85 nil ? a + b + c : 4 + 5 + 6; // 15
86 true ? a + b + c : 1 + 2 + 3; // non-constant
87 nil ? 1 + 2 + 3 : a + b + c; // non-constant
88
89
90 'complex expressions';
91 5+6*7; // 47
92 1+2 > 3+4 ? 'problem' : 'good';
93 1+2 < 3+4 ? 'Also Good' : 'Another Problem';
94 2*(3+4*5); // 46
95
96 'string concatenation';
97 'a' + 'b';
98 'abc' + 'def' + 'ghi';
99 'abc' + 'defghi' + 'jklmnopqrstuvwx' + 'yz';
100 'one' + 1;
101 2 + 'two';
102 3 + 4 + 'five';
103 6 + (7 + 'eight');
104 'six' + 7 + 8;
105 'eight' + (9 + 10);
106 nil + '=NIL';
107 'TRUE=' + true;
108
109 'list values';
110 [];
111 [1, 2, 3];
112 [1+2, 3+4, 5+6*7];
113 ['abc', 456];
114 ['abc', 567, 'def', [1, 2, 3, 4, 5]];
115
116 'list concatenation';
117 [] + 1 + 2 + 3;
118 [x] + 1 + 2 + 3;
119 [] + 1 + 2 + x;
120 [1, 2, 3] + [4, 5, 6];
121 [1, 2, 3] + [[4, 5, 6]];
122
123 'list exclusion';
124 [1, 2, 3, 4] - 3; // [1, 2, 4]
125 [1, 2, 3, 4] - [2, 3]; // [1, 4]
126 [1, 2, 3, 4] - 1; // [2, 3, 4]
127 [1, 2, 3, 4] - 4; // [1, 2, 3]
128 [1, 2, 3, 4] - [1, 2, 3, 4, 5]; // []
129 [1, 2, 3, 4] - [5, 6, 7]; // [1, 2, 3, 4]
130
131 'list indexing';
132 [5, 6, 7][1+1]; // 6
133 ['hello', 'world', 'from', 't3'][5-2]; // 'from'
134
135 'list comparisons';
136 [1, 2, 3] == [1, 2]; // nil
137 [1, 2, 3] == [3, 2, 1]; // nil
138 [1, 2, 3] == [1, 2, 4]; // nil
139 [1, 2, 3] == [1, 2, 3]; // true
140 [1, 2, 3] == [1, 2, '3']; // nil
141 [1, [2, 3], 4] == [1, 2, 3, 4]; //nil
142 [1, [2, 3], 4] == [1, [1+1, 1+1+1], [5, 4, 3][2]]; // true
143 ['hello', 'a' + 'b'] == ['hello', 'ab']; // true
144
145 'address comparisons';
146 &a == &b; // nil
147 &a == &aa; // nil
148 &a == &a; // true
149 &a != &b; // true
150 &a != &aa; // true
151 &a != &a; // nil
152 &a == &(((a))); // true
153 &a == &(((b))); // nil
154
155 'lists with constant symbolic entries';
156 [obj1, obj2];
157 [&f1, &f2];
158 [&f1, obj1, [&f2, obj2]];
159 [obj1] + [&f1];
160 [obj1, obj2, &f1, &f2] - [obj2, &f2];
161 [obj1, obj2, &f1, &f2][2];
162
163 'comparisons of constant symbolic entries';
164 obj1 == obj2; // nil
165 obj1 == obj1; // true
166 obj1 != obj2; // true
167 obj1 != obj1; // nil
168 &f1 == &f2; // nil
169 &f1 == &f1; // true
170 &f1 != &f2; // true
171 &f1 != &f1; // nil
172
173 '&& and || expressions with constant symbolic entries';
174 obj1 == obj2 && &f1 == &f2; // nil
175 obj1 == obj1 && &f1 != &f2; // true
176 obj1 == obj2 || &f1 == &f2; // nil
177 obj1 == obj2 || &f1 == &f1; // true
178 !(obj1 != obj2); // nil
179 !(obj1 == obj2); // true
180
181 'assign to list element';
182 lcl1[2] = 5;
183
184 'function calls';
185 f1(obj1, 'hello', 3);
186 lcl1 = f2(lcl1, lcl2 + lcl1);
187
188 'property evaluation with pointer';
189 obj1.lcl1;
190 obj1.lcl1 = 5;
191
192 'embedded string expressions';
193 "Local 1 is <<lcl1>>, and f1(obj1) is <<
194 f1(obj1) >>!";
195
196 // define some symbols
197 local lcl1;
198 local lcl2;
199 object obj1;
200 object obj2;
201 function f1;
202 function f2;
203