996
|
1 <HTML>
|
|
2 <HEAD>
|
|
3 <TITLE>CLC-INTERCAL Reference</TITLE>
|
|
4 </HEAD>
|
|
5 <BODY>
|
|
6 <H1>CLC-INTERCAL Reference</H1>
|
|
7 <H2>... Expressions</H2>
|
|
8
|
|
9 <P>
|
|
10 Table of contents:
|
|
11 <UL>
|
|
12 <LI><A HREF="index.html">Parent directory</A>
|
|
13 <LI><A HREF="#constants">Constants</A>
|
|
14 <LI><A HREF="#variables">Variables</A>
|
|
15 <LI><A HREF="#indirect">Indirect Variables</A>
|
|
16 <LI><A HREF="#unary">Unary Operators</A>
|
|
17 <LI><A HREF="#binary">Binary Operators</A>
|
|
18 <LI><A HREF="#overloading">Operand Overloading</A>
|
|
19 <LI><A HREF="#grouping">Grouping</A>
|
|
20 <LI><A HREF="#examples">Examples</A>
|
|
21 </UL>
|
|
22 </P>
|
|
23
|
|
24 <H2><A NAME="constants">Constants</A></H2>
|
|
25
|
|
26 <P>
|
|
27 Constants are simply the symbol <CODE>#</CODE> (mesh) followed by an integer
|
|
28 between 0 and 65535. For example <CODE>#1</CODE>, <CODE>#65535</CODE>.
|
|
29 </P>
|
|
30
|
|
31 <P>
|
|
32 To create 32 bit constants, use the interleave operator
|
|
33 (see <A HREF="#binary">binary operators</A> below).
|
|
34 For example, <CODE>#256¢#0</CODE> has value 65536, and
|
|
35 <CODE>#65535¢#65535</CODE> has value 4294967295.
|
|
36 </P>
|
|
37
|
|
38 <H2><A NAME="variables">Variables</A></H2>
|
|
39
|
|
40 <P>
|
|
41 Variables are represented by up to four pieces of information:
|
|
42 <UL>
|
|
43 <LI>The ownership path. This part is optional.
|
|
44 <LI>The variable identifier, as described below.
|
|
45 <LI>The variable number, an integer between 1 and 65535.
|
|
46 <LI>Subscripts. This part must not be included if the variable is not an
|
|
47 array. If you are trying to extract a value, this part must be present
|
|
48 when the variable is an array register. If you just want to name a
|
|
49 register, always leave it out.
|
|
50 </UL>
|
|
51 </P>
|
|
52
|
|
53 <P>
|
|
54 The ownership path is a simple way to follow the BELONGS TO relationship
|
|
55 between registers. Prefixing a register with big-money (<CODE>$</CODE>)
|
|
56 will take you to its owner. Prefixing with a digit from 2 to 9 will take
|
|
57 you to any minor owner. For more information, see
|
|
58 <A HREF="belongs.html">the chapter on Belongs TO</A>. Note that ownership
|
|
59 paths cannot be used if the compiler is <I>ick</I>,
|
|
60 as the big-money is used for interleave.
|
|
61 </P>
|
|
62
|
|
63 <P>
|
|
64 The variable identifier defines the variable type. There are six types:
|
|
65 <UL>
|
|
66 <LI>One spot (<CODE>.</CODE>) - these can contain 16 bit values.
|
|
67 <LI>Two spots (<CODE>:</CODE>) - these can contain 32 bit values.
|
|
68 <LI>Tail (<CODE>,</CODE>) - arrays of 16 bit values.
|
|
69 <LI>Hybrid (<CODE>;</CODE>) - arrays of 32 bit values.
|
|
70 <LI>Whirlpool (<CODE>@</CODE>) - these cannot contain any value.
|
|
71 <LI>Crawling Horror (<CODE>_</CODE>) - these contain compilers.
|
|
72 </UL>
|
|
73 </P>
|
|
74
|
|
75 <P>
|
|
76 Subscripts, if present, are introduced by the word "SUB" and an expression.
|
|
77 Multidimensional arrays will require many subscripts, for example
|
|
78 <CODE>,1 SUB #1 SUB #2</CODE>.
|
|
79
|
|
80 <P>
|
|
81 For example, the following are all valid variable names without ownership
|
|
82 path:
|
|
83 <UL>
|
|
84 <LI><CODE>,12 SUB .1 #2 :3</CODE>
|
|
85 <LI><CODE>.1</CODE>
|
|
86 <LI><CODE>.0001</CODE> (<I>this is the same as </I><CODE>.1</CODE>)
|
|
87 <LI><CODE>:18 SUB #2</CODE>
|
|
88 <LI><CODE>@21</CODE>
|
|
89 <LI><CODE>;1</CODE>
|
|
90 <LI><CODE>@65535</CODE>
|
|
91 </UL>
|
|
92 </P>
|
|
93
|
|
94 <P>
|
|
95 The following are not valid for some reason:
|
|
96 <UL>
|
|
97 <LI><CODE>,12</CODE> - requires a subscript (unlsss ,12 is overloaded)
|
|
98 <LI><CODE>.0</CODE> - variable number cannot be zero
|
|
99 <LI><CODE>1E-3</CODE> - you might think this is the same as <CODE>.0001</CODE>
|
|
100 but isn't
|
|
101 <LI><CODE>.18 SUB #2</CODE> - this cannot have subscripts (unless .18 is overloaded)
|
|
102 <LI><CODE>@65536</CODE> - variable number too big
|
|
103 </UL>
|
|
104 </P>
|
|
105
|
|
106 <P>
|
|
107 When an ownership path is specified, the variable type need not be the
|
|
108 one specified. For this reason, the following can be valid in some cases
|
|
109 and invalid in other, depending on whether the result of following the
|
|
110 ownership chain is an array or not:
|
|
111 <UL>
|
|
112 <LI><CODE>$,12 SUB .1 SUB #2 SUB :3</CODE>
|
|
113 <LI><CODE>2.01</CODE>
|
|
114 <LI><CODE>$49.99</CODE>
|
|
115 <LI><CODE>$:1 SUB $49.99</CODE>
|
|
116 <LI><CODE>$$21$$21$$21$$21@21 SUB 1$$21$$21$$21$$21@21 SUB 2$$21$$21$$21$$21@21</CODE>
|
|
117 <LI><CODE>1;1</CODE>
|
|
118 <LI><CODE>1_1</CODE>
|
|
119 <LI><CODE>65535$65535@65535</CODE>
|
|
120 </UL>
|
|
121 </P>
|
|
122
|
|
123 <P>
|
|
124 However, the "crawling horror" registers do not currently enjoy full rights
|
|
125 and cannot contain any value (the compilers are stored in them, but there
|
|
126 is no direct access to them). They can, however, be subject to overloading
|
|
127 and the Belongs TO relation. Please note, however, that at present there
|
|
128 are only two crawling horrors, <CODE>_1</CODE> and <CODE>_2</CODE>.
|
|
129 </P>
|
|
130
|
|
131 <P>
|
|
132 CLC-INTERCAL 0.05 introduces a new "variable", "*" (splat). It is not possible
|
|
133 to assign a value to it, but it contains the code of the last error (hence
|
|
134 the name). It is an error to use this variable if the program did not
|
|
135 encounter an error. Since all runtime errors are fatal, it is usually an
|
|
136 error to read this variable, and it should be avoided. However, a quantum
|
|
137 program might have encountered an error and at the same time avoided it,
|
|
138 therefore it is meaningful to use "splat" in quantum programs. Also,
|
|
139 if used inside an <A HREF="statements.html#while">event</A>, it makes
|
|
140 perfect sense to refer to the splat.
|
|
141 </P>
|
|
142
|
|
143 <P>
|
|
144 CLC-INTERCAL 1.-94 contains a number of special registers. These are invisible
|
|
145 to programs, but accessible to compilers, and control the internal working of
|
|
146 the system. They are documented in
|
|
147 <A HREF="parsers.html">the chapter about writing compilers</A>.
|
|
148 </P>
|
|
149
|
|
150 <H2><A NAME="indirect">Indirect Variables</A></H2>
|
|
151
|
|
152 <P>
|
|
153 CLC-INTERCAL 0.05 introduced two new operators which might be useful to
|
|
154 figure out what a register is even after following BELONGS TO, or during
|
|
155 overloading.
|
|
156 </P>
|
|
157
|
|
158 <P>
|
|
159 The worm applied to a register returns its number. For example,
|
|
160 <CODE>-.5</CODE> is the same as #5 (do not confuse the worm with the bookworm,
|
|
161 which might be printed the same on VDUs). As another example, inside
|
|
162 overloading (see below), one can obtain the number of the register being
|
|
163 overloaded with <CODE>-$@0</CODE>.
|
|
164 </P>
|
|
165
|
|
166 <P>
|
|
167 The intersection-worm (never heard of this type of worm? we haven't either)
|
|
168 introduces indirect registers. The syntax is "intersection register worm
|
|
169 register", and represents a register with the type of the first, the number
|
|
170 of the second, for example <CODE>+:7-.3</CODE> is the same as <CODE>:3</CODE>.
|
|
171 Things get interesting when the registers start having ownership paths etc.
|
|
172 </P>
|
|
173
|
|
174 <P>
|
|
175 We were supposed to write some examples here, but frankly, we can't stomach
|
|
176 it just now.
|
|
177 </P>
|
|
178
|
|
179 <H2><A NAME="unary">Unary Operators</A></H2>
|
|
180
|
|
181 <P>
|
|
182 The unary operators are the standard logical operators, <CODE>AND</CODE>,
|
|
183 <CODE>OR</CODE> and <CODE>XOR</CODE> (exclusive <CODE>OR</CODE>). They
|
|
184 should be written as <CODE>&</CODE> for <CODE>AND</CODE> and <CODE>V</CODE>
|
|
185 for <CODE>OR</CODE>. For <CODE>XOR</CODE>, you should use the bookworm symbol,
|
|
186 which we cannot represent in this page because it's not in the character
|
|
187 set. As an approximation, we use the "yen" (<CODE>¥</CODE>) symbol, which
|
|
188 is accepted by the compiler when the input alphabet is ASCII. This only works
|
|
189 if the font is ISO-8859-1, so the compiler also accepts
|
|
190 <CODE>V-backspace-worm</CODE>. If the input alphabet is EBCDIC, only the
|
|
191 bookworm symbol can be used for <CODE>XOR</CODE>. If the compiler is
|
|
192 in "C-INTERCAL compatibility mode", the what (?) is accepted instead of yen.
|
|
193 (The "what" has a completely different meaning in CLC-INTERCAL mode, and
|
|
194 should only be used inside a <CODE>CREATE</CODE> statement).
|
|
195 </P>
|
|
196
|
|
197 <P>
|
|
198 The value of an unary operator is determined by rotating the operand to the
|
|
199 right one bit, and applying the corresponding bitwise binary operation to
|
|
200 the result and the original operand.
|
|
201 </P>
|
|
202
|
|
203 <P>
|
|
204 The INTERCAL-72 specification says that the operation is inserted between the
|
|
205 one spot, two spot or mesh and the number, so <CODE>#¥1</CODE> means
|
|
206 "unary <CODE>XOR</CODE> applied to the number 1" (the result is 32769).
|
|
207 However, older versions of CLC-INTECAL also allowed the operator to be used
|
|
208 as a prefix to an expression,
|
|
209 as in <CODE>V¥&V#¥1</CODE> (it will be obvious by now that the
|
|
210 value is 61440). Current versions no longer allow that. You should not
|
|
211 have been using it anyway.
|
|
212 </P>
|
|
213
|
|
214 <P>
|
|
215 Note that we have absolutely no idea whether the unary operators "bind"
|
|
216 more or less than other things. In case of doubt, assign the result of
|
|
217 subexpressions to some register, or use sparks and rabbit ears to control
|
|
218 the order of evaluation.
|
|
219 </P>
|
|
220
|
|
221 <P>
|
|
222 C-INTERCAL introduced new unary operators for use with bases between 3 and
|
|
223 7. These are now available in CLC-INTERCAL 1.-94, but they use a different
|
|
224 symbol. These are the unary <CODE>BUT</CODE> (a whirlpool (@) in C-INTERCAL,
|
|
225 or a what (?) in CLC-INTERCAL) and the unary "add without carry" (a shark
|
|
226 fin (^) in C-INTERCAL, or a spike (|) in CLC-INTERCAL). For bases 4 or greater,
|
|
227 several types of unary <CODE>BUT</CODE> are available (C-INTERCAL: 2@, 3@, etc;
|
|
228 CLC-INTERCAL: 2?, 3?, etc). Please consult the documentation which comes
|
|
229 with C-INTERCAL for more information about these operators.
|
|
230 </P>
|
|
231
|
|
232 <P>
|
|
233 CLC-INTERCAL 1.-94.-4 introduced a new unary operator, division. This differs
|
|
234 from normal unary operators because it is arithmetic, not bitwise. The
|
|
235 operation is as follows: the operand is shifted right arithmetically, then
|
|
236 the original value is divided by the result of the shift and truncated to
|
|
237 an integer. Note that the most frequent result is the base, since a right
|
|
238 shift is equivalent to a division by the base, truncating the result to
|
|
239 an integer. For example, in base 5, unary division of #62 is #62 divided
|
|
240 by #12, which just happens to be #5. However, the operation can also
|
|
241 return other values, for example in base 5 unary division of #12 is #6.
|
|
242 And of course any value smaller than the base produces a division by zero
|
|
243 splat.
|
|
244 </P>
|
|
245
|
|
246 <P>
|
|
247 A compiler option, <I>bitwise-divide</I>, changes the unary division
|
|
248 to behave like a normal unary operation, performing a bitwise rotate
|
|
249 of its operand and so on. You can figure out what it does.
|
|
250 </P>
|
|
251
|
|
252 <P>
|
|
253 The symbol for the unary division is the worm (<CODE>-</CODE>), so
|
|
254 for example #-62 is the unary division of #62. Note that the worm
|
|
255 is also used to construct indirect registers, but that's OK because
|
|
256 the compiler does not get confused. The programmer might.
|
|
257 </P>
|
|
258
|
|
259 <H2><A NAME="binary">Binary Operators</A></H2>
|
|
260
|
|
261 <P>
|
|
262 There are four binary operators: interleave, select, and two forms of
|
|
263 operand overloading. Operand overloading is implemented in CLC-INTERCAL 0.05
|
|
264 or newer, and are described in <A HREF="#overloading">the next section</A>.
|
|
265 </P>
|
|
266
|
|
267 <P>
|
|
268 Interleave is written <CODE>¢</CODE> (change), but can also be
|
|
269 represented as <CODE>C-backspace-slat</CODE> or <CODE>C-backslace-spike</CODE>
|
|
270 if the input alphabet is ASCII. If the compiler is in "C-INTERCAL compatibility
|
|
271 mode", the big money ($) can be used as well. Note that this means you can't
|
|
272 use it for ownership paths, but that's OK since C-INTERCAL has no BELONGS TO
|
|
273 relation.
|
|
274 </P>
|
|
275
|
|
276 <P>
|
|
277 Interleave takes two 16 bit numbers and "interleaves" their bits. For
|
|
278 example, <CODE>#3¢#0</CODE> is 10. To see why, write the numbers
|
|
279 in binary (3 is 0000000000000011 in binary, so interleaving the bits
|
|
280 with 0000000000000000 you get 00000000000000000000000000001010, which
|
|
281 is 10). It can be used to simply form 32 bit constants by writing all
|
|
282 the "even" bits to the left of the <CODE>¢</CODE> and all the
|
|
283 "odd" bits to the right.
|
|
284 </P>
|
|
285
|
|
286 <P>
|
|
287 Interleave fails if it tries to produce more than 32 bits. Use it only on
|
|
288 16 bit values!
|
|
289 </P>
|
|
290
|
|
291 <P>
|
|
292 If the base is not 2, interleave works the same way, but interleaves
|
|
293 digits instead of bits; for example, in base 3, #3¢#0 is #9.
|
|
294 </P>
|
|
295
|
|
296 <P>
|
|
297 Select is written <CODE>~</CODE> (sqiggle [sic]). It uses the second number
|
|
298 to "select" bits in the first number. The bits selected are the ones where
|
|
299 the second number has a 1. All the bits of the result are right-aligned, and
|
|
300 padded with 0 to form a 16 bit or a 32 bit number depending on the size of
|
|
301 the result. Note that if you are planning to apply an unary operator on the
|
|
302 result of select you don't know in advance whether the 16 bit or 32 bit
|
|
303 operator will be used, because this is data-dependent. As an example,
|
|
304 <CODE>:1~#32768</CODE> selects bit 15 of <CODE>:1</CODE> and returns 0 or
|
|
305 1 accordingly. <CODE>.1~#32770</CODE> selects bits 15 and 2 of <CODE>.1</CODE>
|
|
306 and can return 0, 1, 2, or 3.
|
|
307 </P>
|
|
308
|
|
309 <P>
|
|
310 If the base is not 2, select works similarly. See the documentation coming
|
|
311 with C-INTERCAL for a full discussion.
|
|
312 </P>
|
|
313
|
|
314 <H2><A NAME="overloading">Operand Overloading</A></H2>
|
|
315
|
|
316 <P>
|
|
317 There are two operand overloading operators: they are written <CODE>/</CODE>
|
|
318 (slat) and <CODE>\</CODE> (backslat). These are binary operators, but the
|
|
319 first operand of slat must be a register or a register with subscripts.
|
|
320 The second operand can be any expression.
|
|
321 </P>
|
|
322
|
|
323 <P>
|
|
324 Both overloading operators return the value of their left operand. In the
|
|
325 case of slat, any previous overloading which applies to the left operand
|
|
326 is removed before evaluating it. For example, ".1/#1" returns the value
|
|
327 contained in .1
|
|
328 </P>
|
|
329
|
|
330 <P>
|
|
331 The <I>side effect</I> of the overloading operators is to change the
|
|
332 way some registers are used in future. Slat applies to a single value,
|
|
333 be it a register or an array element. Whenever that value is used after
|
|
334 the overloading, the expression is evaluated instead. For example, after
|
|
335 ".1/.2" using .1 will return the value of .2. The register @0 is temporarily
|
|
336 created and enslaved to the register being overloaded, so ".1/$@0" is a
|
|
337 slightly less efficient way to access the value of .1
|
|
338 </P>
|
|
339
|
|
340 <P>
|
|
341 Assigning to an overloaded register or array element attempts to invert
|
|
342 the relevant operations. For example, if .1 is overloaded to &&.2, then
|
|
343 assigning #4 to .1 will leave .1 unchanged but assign #28 to .2 (this
|
|
344 is because &&#28 is #4). This does not always work, so you might get a
|
|
345 runtime error. However, if the expression includes only interleave,
|
|
346 select, overload, and registers, the assignment always succeeds. The
|
|
347 unary operators sometimes fail because there are values which they can
|
|
348 never return (for example, there is no way to get #10 as the result of
|
|
349 an unary AND, so if .1 is overloaded to .&2, assigning #10 to .1 results
|
|
350 in an error, while of course assigning #12 would be fine because #&28 is
|
|
351 #12). Currently, assigning to a constant works in CLC-INTERCAL 1.-94, as
|
|
352 does assigning to splat (which however produces an error because now the
|
|
353 "splat" variable has a value!). In addition, assigning to anything which
|
|
354 corresponds to a constant causes modification of a constant (for example,
|
|
355 assigning to -.2 is equivalent to assign to #2 or to ?SYMBOL). If you are
|
|
356 not confused now, you never will be.
|
|
357 </P>
|
|
358
|
|
359 <P>
|
|
360 <I>New in CLC-INTERCAL 1.-94</I>. Constants are no longer constants. An
|
|
361 example will make this clear as mud. Suppose .2 is overloaded to &&#2;
|
|
362 assigning #4 to .2 will effectively mean assigning #28 to #2 (see the
|
|
363 discussion in the previous paragraph). Next time your program uses the
|
|
364 number 2, it will actually use 28 instead. For example, .2 will now have
|
|
365 the same value as .28, and an expression containing #2 will use #28 instead.
|
|
366 Moreover, if your program used to have a <CODE>COME FROM (2)</CODE> it
|
|
367 will now have a <CODE>COME FROM (28)</CODE> in the same place. You can
|
|
368 use it as a more elegant alternative to computed <CODE>COME FROM</CODE>.
|
|
369 </P>
|
|
370
|
|
371 <P>
|
|
372 The backslat operator is similar to slat, except that it affects a range
|
|
373 of registers. The expression on the left of the backslat is taken as the
|
|
374 interleaving of two values. The overloading applies to any register with
|
|
375 a number which is between the two values (if the first value is greater
|
|
376 than the second, no overloading is done). The register $@0 might be useful
|
|
377 to retrieve the original register. In the current implementation, this form
|
|
378 of overloading only applies to numeric registers (spot and two-spot), not
|
|
379 to arrays or classes. For example, "#1¢#5"\"$@0~#1" replaces any
|
|
380 registers between .1 and .5, :1 and :5, with their lowest-significant bit.
|
|
381 </P>
|
|
382
|
|
383 <P>
|
|
384 Overloading loops are eliminated. So if you have .1/.2 and .2/.1, using
|
|
385 .1 will return .1 (.1 causes evaluation of .2, which causes evaluation of
|
|
386 .1 - the loop is noted and the overloading of .1 is not applied). This
|
|
387 means that, in particular, .1/.1 can be used to remove any overloading
|
|
388 associated with .1 - however, the resulting code will be slower than the
|
|
389 case when no overloading has been specified, and you should instead localise
|
|
390 the effects of overloading using statements STASH and RETRIEVE as described
|
|
391 in <A HREF="statements.html#stash">the chapter about statements</A>.
|
|
392 </P>
|
|
393
|
|
394 <P>
|
|
395 Note that programmer overloading is implemented by all INTERCAL compilers
|
|
396 known to mankind - it's just that their documentation don't mention this.
|
|
397 </P>
|
|
398
|
|
399 <P>
|
|
400 Also note that you cannot ABSTAIN from overloading, because overloading
|
|
401 is not a statement. However, you can prevent overloading by IGNORING a
|
|
402 register.
|
|
403 </P>
|
|
404
|
|
405 <H2><A NAME="grouping">Grouping</A></H2>
|
|
406
|
|
407 <P>
|
|
408 The precedence rules for operators are not defined by INTERCAL-72. For
|
|
409 CLC-INTERCAL, we have absolutely no idea, and different versions use
|
|
410 different precedences. It might help to either save the results of
|
|
411 subexpressions in registers or, if all else fails, group subexpression
|
|
412 using the grouping constructs. A group is started with a spark
|
|
413 (<CODE>'</CODE>) or rabbit ears (<CODE>"</CODE>) and closed with the
|
|
414 same symbol it started with. Any expression can go inside a group,
|
|
415 including any number of sparks or rabbit ears. However, remember that
|
|
416 the compiler has to read it somehow, so don't be too cruel on the poor
|
|
417 thing.
|
|
418 </P>
|
|
419
|
|
420 <P>
|
|
421 For example, the expression <CODE>'"#3~#2"¢#0'~#2</CODE> has value
|
|
422 1, whereas the similar expression <CODE>"#3~#2"¢#0~#2</CODE> could
|
|
423 have value 2 - because the compiler may use the whole <CODE>#0~#2</CODE> as
|
|
424 right operand for the interleave.
|
|
425 </P>
|
|
426
|
|
427 <P>
|
|
428 Note that different compilers might have different ideas about precedence,
|
|
429 so always include enough sparks rabbit ears to make the expression unambiguous
|
|
430 if you intend to write portable programs.
|
|
431 </P>
|
|
432
|
|
433 <P>
|
|
434 If a spark is followed immediately by a spot, the two can be "overpunched",
|
|
435 and they will look like a bang. So, for example, <CODE>'.1~.2'</CODE> could
|
|
436 be written <CODE>!1~.2</CODE>. A similar effect applies to the rabbit ears,
|
|
437 but in this case you use a real overpunch (rabbit ears, backspace, spot)
|
|
438 because there isn't a character looking like the result.
|
|
439 </P>
|
|
440
|
|
441 <H2><A NAME="examples">Examples</A></H2>
|
|
442
|
|
443 <P>
|
|
444 Everything should be clear by now, so you won't need any examples.
|
|
445 </P>
|
|
446
|
|
447 </BODY>
|
|
448 </HTML>
|