t52_strcat_nest.pas 987 B

12345678910111213141516171819202122232425
  1. { t52_strcat_nest: nested concatenations, a concatenation compared, and a
  2. string ELEMENT as an operand.
  3. `+' associates to the left, so `a + b + '!'' is two occurrences and gets two
  4. scratch strings, and the first result is still alive when the second consumes
  5. it. A concatenation result is an ordinary string variable, so it can be an
  6. operand of `=' (ParseCmp), and `+' can take an `s[i]' element as its left
  7. operand, in which case an element ADDRESS is what reaches the runtime rather
  8. than a whole-string address.
  9. a[2] is 'e' - subscripts are 1-based, the length byte is at s[0]. }
  10. program t52_strcat_nest (input, output);
  11. var
  12. a, b : string[12];
  13. begin
  14. a := 'hello';
  15. b := 'world';
  16. writeln (a + b + '!'); { (a + b) + '!' }
  17. writeln ('<' + a + '>'); { ('<' + a) + '>' }
  18. if (a + b) = 'helloworld' then
  19. writeln ('concat-eq')
  20. else
  21. writeln ('concat-ne');
  22. writeln (a[2] + b) { a string element + a string }
  23. end.