1
2 08/04/86 pascal_strings.gi.info
3 This info file describes string implementation in Multics Pascal.
4 Strings are an extension to the Standard, and they have been
5 implemented in some from in many versions of the language. This
6 implementation refers to a document of the BSI "Extensions to
7 Standard Pascal for string handling" 25 February 1985.
8
9
10 Terminology:
11 The following terms are used in this document:
12 "fixed-string"
13 Will designate the current "packed array of char" character string.
14 Multics Pascal accepts any packed array of char conformant or not.
15 "dynamic-string"
16 Will designate the string of the new form.
17 A dynamic string has a maximum length, given at the definition of
18 its type, and a current length which is >= 0 and <= the maximum
19 length.
20 There is an implementation defined limit for the maximum length
21 of a string. Under Multics, this limit is one segment and is the
22 value of the predefined constant "maxstring".
23
24
25 Representation:
26 A dynamic-string value consists of an ordered sequence of elements of type
27 char: the number of elements is the current length which may be zero.
28 The representation of a string is implementation defined. Under Multics
29 it is similar to the following structure:
30
31 RECORD
32 current_length : 0..maxlength ;
33 character_sequence : PACKED ARRAY 1..maxlength of char
34 END;
35
36 and is compatible with the PL/1 "char maxlength varying" declaration.
37
38
39 Variables:
40 The form of declaration of a dynamic-string variable is "string n"
41 where n is its maxlength, which must be > 0. "string" is a
42 predeclared shema identifier. Multics Pascal does not provide
43 general implementation of schemas but string is implemented like a
44 schema.
45
46 Ex : TYPE
47 s_256 : string 256 ;
48 VAR
49 s1, s2 : string 32 ;
50 s3 : s_256 ;
51
52 A dynamic string is not an array, but its elements may be referenced
53 by indexing, e.g. sv i. Such references are of type char. It is
54 an error if the index is less than 1 or exceeds the current length.
55
56
57 Literals:
58 The notation for string litterals is extended to include the null string ''.
59 All other string-type litterals and declared constants are of the
60 fixed-string type determined from their length.
61
62
63 String expressions:
64 Dynamic-string values, fixed-string values, and values of type char
65 may be mixed within expressions. In such expressions, there is
66 implicit coercion of fixed-strings and characters to dynamic-string
67 type.
68
69 The "+" operator is used within expressions to denote concatenation of
70 dynamic-string values.
71
72 Ex:
73 s_132 + 'abc' + 'x'
74
75
76 Assignment:
77 A dynamic-string expression can be assigned to a dynamic-string
78 variable. It is an error if the length of the value exceeds the
79 maximum lenth of the variable.
80
81 Ex:
82 s1 := '' ;
83 s1 := 'abc' + s2 + 'X' ;
84 s1 := s2 ;
85 s1 := 'x' ;
86
87
88 Notes: Standard rules concerning assignment to fixed-strings are
89 unchanged. So it is not allowed to assign a dynamic-string to a
90 fixed-string using an assignment statement.
91
92
93 Parameters:
94 Value and VAR formal parameters are available. The only special rule
95 is that a VAR formal parameter declared as type "string" with no
96 length is compatible with an actual dynamic-string variable of any
97 length.
98
99
100 Comparison: The comparisons are allowed between dynamic-string values,
101 the process beeing defined as a lexical comparison according to the
102 Standard rules of corresponding elements from 1 to the length of the
103 shorter string, and if this yelds equality then the result of
104 comparing the lengths.
105
106 Ex:
107 IF sv = fixstr + '.ABC' THEN
108
109
110 Read and write:
111 Read f sv
112 Reads from a text file f into a dynamic-string variable sv.
113 Characters are transfered sequentially with sv 1 until the number
114 of characters equals the maxlength of sv or eoln f becomes true.
115 If eoln f was true initially the effect is the same as sv := ''.
116 write f s : w
117 writes a dynamic-string value s to the text file f, the characters
118 of s beeing written sequentially starting with s1.
119 Let ls represent length s. If w > ls then w-ls leading spaces
120 are inserted. If ls > w then the last ls-w characters of s are
121 not transfered. If w is omitted, exactly ls characters are
122 transmitted.
123
124
125 Additional standard procedures and functions:
126
127 Function length s
128 Where s is any dynamic string value returns an integer being
129 the current length of s.
130 Function maxlength sv
131 Where sv is any dynamic-string variable reference returns an
132 integer being the the maxlength of the variable. Function
133 position s1 s2 where s1 and s2 are dynamic-string values,
134 returns an integer which is zero if s2 does not contain s1,
135 else the index in s2 of the first occurrence of s1 in s2.
136
137
138 Function substr s i n
139 Where s is a dynamic-string value and i and n are integer
140 values returns a dynamic-string value containing the
141 elements si, si+1..si+n-1. It an error if these
142 elements are not within the current length of s.
143 Procedure insert s sv i
144 Where s is a dynamic-string value, sv a dynamic-string variable
145 reference, and i an integer value, inserts s into sv at index i.
146 It is an error if i < 1, if i > lengthsv+1, or if
147 length s + length sv > maxlength s.
148
149
150 Procedure delete sv i n
151 Where sv is a dynamic-string variable reference, and i is an
152 integer value, ;deletes n characters of sv at index i.
153 Elements si..si+n-1 are deleted, and elements if any
154 si+n..slengths are moved into si.. etc... It is an
155 error if i+n > length s.