The syntax of string constants in Larch/C++ includes all of the syntax for C++ string literals (see Section 2.5.4 of [Ellis-Stroustrup90]). It also allows some non-standard escape sequences. See section 4.13.3 Character Constants for details of std-esc.
string-literal ::= [L
]"
[ string-character ] ..."
string-character ::= normal-char | escape-sequence |'
escape-sequence ::= std-esc | non-std-esc non-std-esc ::=\
non-escape-code non-escape-code::= any character that cannot follow\
in a std-esc
Some examples of string-literals follow.
"" L"the previous line contains the empty string" "the standard escape characters are:\n\t\v\b\r\f\a\\\?\'\"\032\xff" "\in Larch/C++, use non-standard escapes \/ not /\ it's okay" L"the line above means the following" "\\in Larch/C++, use non-standard escapes \\/ not /\\ it's okay"
The meaning of a non-std-esc, such as \g
is the character backslash
followed by the next character
(i.e., the meaning of \\
followed by the meaning of g
).
Thus \/
means the same thing as \\/
.
This is a convenience in writing informal descriptions
(see section 6.1.4 Informal Descriptions),
where one may want to use \/
and /\
to mean "or" and "and".
(However, one must be careful, not to put /\
just before the closing
double quote of such a string.)
In Larch/C++, a distinction is made between array types and pointer types
(as in LCL [Guttag-Horning93]).
So unlike C++, a string-literal in Larch/C++ has sort
Arr[Obj[char]]
(which is considered different from
Ptr[Obj[char]]
).(3)
A string constant preceded by L
is a wide-character string,
and has sort Arr[Obj[wchar_t]]
(see Section 2.5.4 of [Ellis-Stroustrup90]).
Note the difference between a character constant and a string that
contains a single character: 'x'
is not the same as "x"
.
The former is a single character of sort char
while the latter is
a string constant of sort Arr[Obj[char]]
.
See section 11.9 Character Strings for some traits that are helpful in specifying functions dealing with C++ strings.
Go to the first, previous, next, last section, table of contents.