grammars-v4 icon indicating copy to clipboard operation
grammars-v4 copied to clipboard

[rexx] Concatenation by abuttal and by whitespace are not supported

Open RossPatterson opened this issue 1 year ago • 4 comments

Rexx has a quirky definition for concatenation. In addition to the common case of an infix binary || operator, there are two more ways to concatenate values. The Rexx standard doesn't give them names, but I call them "concatenation by abuttal" and "concatenation by whitespace". Concatenation by abuttal has the same result as concatenation by the || operator: the two values are simply concatenated. Concatenation by whitespace inserts a single blank between the values.

Abuttal is a weird syntactic case. Basically, if two values can be abutted (i.e., with no intervening whitespace), without lexical confusion (e.g., "a string>"3, or a_function()"a string"), then doing so will concatenate the values. There are some combinations of tokens for which this isn't allowed. For example, "string""string" is the single string value string"string, not two separate strings that will be concatenated. Such cases result in an interpretation that is not concatenation.

I am working on a change to the grammar to represent all three forms of concatenation, and to specifcally make it possible to differentiate between the whitespace and non-whitespace cases from the parse tree.

RossPatterson avatar Aug 05 '22 21:08 RossPatterson

Are you saying an expression of a_function()"a string" is syntactically legal, but a_function() "a string" is not?

kaby76 avatar Aug 05 '22 22:08 kaby76

No, they're both legal, but they have different results. Let me put it more succinctly:

  • a_function() || "a string" is exactly equal to the value of a_function() concatenated to the value "a string"
  • a_function()"a string" is exactly equal to a_function() || "a string"
  • a_function() "a string" is exactly equal to a_function() || " " || "a string"
  • a_function()...lots of whitespace..."a string" is also exactly equal to a_function() || " " || "a string"

RossPatterson avatar Aug 05 '22 23:08 RossPatterson

Mike Cowlishaw, who created Rexx, describes concatenation this way in The Rexx Language (2nd. ed.):

The concatenation operators are used to combine two strings to form one string by appending the second string to the right-hand end of the first string. The concatenation may occur with or without an intervening blank:

(blank) Concatenate terms with one blank in between. || Concatenate without an intervening blank. (abuttal) Concatenate without an intervening blank.

Concatenation without a blank may be forced by using the I I operator, but it is useful to remember that when two terms are adjacent and are not separated by an operator, [19] they will be concatenated in the same way. This is the abuttal operation. For example, if the variable TOTAL had the value '3 7 . 4', then Total '%' would evaluate to '3 7 . 4 % '.

[19] This can occur when the terms are syntactically distinct (such as a literal string and a symbol), or when they are separated only by a comment.

RossPatterson avatar Aug 06 '22 01:08 RossPatterson

Fixed by fbe2034.

RossPatterson avatar Aug 08 '22 00:08 RossPatterson

Cleaned up by 37d69f57ee646bdc0672f46f0ec3e8660727ef1f at @KvanTTT's request.

All done, closing.

RossPatterson avatar Aug 16 '22 20:08 RossPatterson