| 1234567891011121314151617181920212223242526272829 |
- { t51_strcat: string concatenation, `a + b', in the places its result can go.
- A concatenation needs storage for its result before anything can consume it,
- so each `+' in the source gets its own 256-byte scratch STRING and the result
- IS that variable. These are the shapes that consume one: as a `writeln'
- argument, assigned to a target, and then used again as an operand.
- The operands cover var+var, literal+var, var+literal, var+char and char+var -
- every pairing a string operand allows except two CHARs, which t53 rejects.
- The CHAR cases are the reason a one-character literal and a CHAR variable
- take the same path: a CHAR operand becomes a one-character string on the
- stack (a length byte and the byte), not a string copied from memory. }
- program t51_strcat (input, output);
- var
- a, b, c : string[12];
- ch : char;
- begin
- a := 'hello';
- b := 'world';
- ch := 'X';
- writeln (a + b); { var + var -> helloworld }
- writeln ('say ' + b); { literal + var -> say world }
- writeln (a + '!'); { var + literal -> hello! }
- writeln (a + ch); { var + char -> helloX }
- writeln (ch + a); { char + var -> Xhello }
- c := a + b; { the result assigned to a variable... }
- writeln (c);
- writeln (b + c) { ...and then used as an operand }
- end.
|