Pristine Ack-5.5
[Ack-5.5.git] / doc / pascal / syntax.doc
1 .sp 1.5i
2 .LP
3 .vs 14
4 .nh
5 .ft B
6 Appendix A: ISO-PASCAL grammar
7 .ft R
8
9
10 \fBA.1 Lexical tokens\fR
11
12 The syntax describes the formation of lexical tokens from characters and the
13 separation of these tokens, and therefore does not adhere to the same rules
14 as the syntax in A.2.
15
16 The lexical tokens used to construct Pascal programs shall be classified into
17 special-symbols, identifiers, directives, unsigned-numbers, labels and
18 character-strings. The representation of any letter (upper-case or lower-case,
19 differences of font, etc) occurring anywhere outside of a character-string
20 shall be insignificant in that occurrence to the meaning of the program.
21
22 letter = \fBa\fR | \fBb\fR | \fBc\fR | \fBd\fR | \fBe\fR | \fBf\fR | \fBg\fR | \fBh\fR | \fBi\fR | \fBj\fR | \fBk\fR | \fBl\fR | \fBm\fR | \fBn\fR | \fBo\fR | \fBp\fR | \fBq\fR | \fBr\fR | \fBs\fR | \fBt\fR | \fBu\fR | \fBv\fR | \fBw\fR | \fBx\fR | \fBy\fR | \fBz\fR .
23
24 digit = \fB0\fR | \fB1\fR | \fB2\fR | \fB3\fR | \fB4\fR | \fB5\fR | \fB6\fR | \fB7\fR | \fB8\fR | \fB9\fR .
25
26
27 The special symbols are tokens having special meanings and shall be used to
28 delimit the syntactic units of the language.
29
30 special-symbol = \fB+\fR | \fB\-\fR | \fB*\fR | \fB/\fR | \fB=\fR | \fB<\fR | \fB>\fR | \fB[\fR | \fB]\fR | \fB.\fR | \fB,\fR | \fB:\fR | \fB;\fR | \fB^\fR | \fB(\fR | \fB)\fR | \fB<>\fR | \fB<=\fR | \fB>=\fR | \fB:=\fR | \fB..\fR |
31 \h'\w'special-symbol = 'u'word-symbol .
32
33 word-symbol = \fBand\fR | \fBarray\fR | \fBbegin\fR | \fBcase\fR | \fBconst\fR | \fBdiv\fR | \fBdo\fR | \fBdownto\fR | \fBelse\fR | \fBend\fR | \fBfile\fR | \fBfor\fR | \fBfunction\fR |
34 \h'\w'word-symbol = 'u'\fBgoto\fR | \fBif\fR | \fBin\fR | \fBlabel\fR | \fBmod\fR | \fBnil\fR | \fBnot\fR | \fBof\fR | \fBor\fR | \fBpacked\fR | \fBprocedure\fR | \fBprogram\fR | \fBrecord\fR |
35 \h'\w'word-symbol = 'u'\fBrepeat\fR | \fBset\fR | \fBthen\fR | \fBto\fR | \fBtype\fR | \fBuntil\fR | \fBvar\fR | \fBwhile\fR | \fBwith\fR .
36
37
38 Identifiers may be of any length. All characters of an identifier shall be
39 significant. No identifier shall have the same spelling as any word-symbol.
40
41 identifier = letter { letter | digit } .
42
43
44 A directive shall only occur in a procedure-declaration or function-declaration.
45 No directive shall have the same spelling as any word-symbol.
46
47 directive = letter {letter | digit} .
48
49
50 Numbers are given in decimal notation.
51
52 .nf
53 unsigned-integer = digit-sequence .
54 unsigned-real = unsigned-integer \fB.\fR fractional-part [ \fBe\fR scale-factor ] | unsigned-integer \fBe\fR scale-factor .
55 digit-sequence = digit {digit} .
56 fractional-part = digit-sequence .
57 scale-factor = signed-integer .
58 signed-integer = [sign] unsigned-integer .
59 sign = \fB+\fR | \fB\-\fR .
60 .fi
61
62 .bp
63 Labels shall be digit-sequences and shall be distinguished by their apparent
64 integral values and shall be in the closed interval 0 to 9999.
65
66 label = digit-sequence .
67
68
69 A character-string containing a single string-element shall denote a value of
70 the required char-type. Each string-character shall denote an implementation-
71 defined value of the required char-type.
72
73 .nf
74 character-string = \fB'\fR string-element { string-element } \fB'\fR .
75 string-element = apostrophe-image | string-character .
76 apostrophe-image = \fB''\fR .
77 string-character = All 7-bits ASCII characters except linefeed (10), vertical tab (11), and new page (12).
78 .fi
79
80
81 The construct:
82
83         \fB{\fR any-sequence-of-characters-and-separations-of-lines- not-containing-right-brace \fB}\fR
84
85 shall be a comment if the "{" does not occur within a character-string or
86 within a comment. The substitution of a space for a comment shall not alter
87 the meaning of a program.
88
89 Comments, spaces (except in character-strings), and the separation of
90 consecutive lines shall be considered to be token separators. Zero or more
91 token separators may occur between any two consecutive tokens, or before
92 the first token of a program text. No separators shall occur within tokens.
93 .bp
94 .po
95 \fBA.2 Grammar\fR
96
97 The non-terminal symbol \fIprogram\fR is the start symbol of the grammar.
98
99 .nf
100 actual-parameter : expression | variable-access | procedure-identifier | function-identifier .
101 actual-parameter-list : \fB(\fR actual-parameter { \fB,\fR actual-parameter } \fB)\fR .
102 adding-operator : \fB+\fR | \fB\-\fR | \fBor\fR .
103 array-type : \fBarray\fR \fB[\fR index-type { \fB,\fR index-type } \fB]\fR \fBof\fR component-type .
104 array-variable : variable-access .
105 assignment-statement : ( variable-access | function-identifier ) \fB:=\fR expression .
106
107 base-type : ordinal-type .
108 block : label-declaration-part constant-definition-part type-definition-part variable-declaration-part
109 \h'\w'block : 'u'procedure-and-function-declaration-part statement-part .
110 Boolean-expression : expression .
111 bound-identifier : identifier .
112 buffer-variable : file-variable \fB^\fR .
113
114 case-constant : constant .
115 case-constant-list : case-constant { \fB,\fR case-constant } .
116 case-index : expression .
117 case-list-element : case-constant-list \fB:\fR statement .
118 case-statement : \fBcase\fR case-index \fBof\fR case-list-element { \fB;\fR case-list-element } [ \fB;\fR ] \fBend\fR .
119 component-type : type-denoter .
120 component-variable : indexed-variable | field-designator .
121 compound-statement : \fBbegin\fR statement-sequence \fBend\fR .
122 conditional-statement : if-statement | case-statement .
123 conformant-array-parameter-specification : value-conformant-array-specification |
124 \h'+18.5m'variable-conformant-array-specification .
125 conformant-array-schema : packed-conformant-array-schema | unpacked-conformant-array-schema .
126 constant : [ sign ] ( unsigned-number | constant-identifier ) | character-string .
127 constant-definition : identifier \fB=\fR constant .
128 constant-definition-part : [ \fBconst\fR constant-definition \fB;\fR { constant-definition \fB;\fR } ] .
129 constant-identifier : identifier .
130 control-variable : entire-variable .
131
132 domain-type : type-identifier .
133
134 else-part : \fBelse\fR statement .
135 empty-statement : .
136 entire-variable : variable-identifier .
137 enumerated-type : \fB(\fR identifier-list \fB)\fR .
138 expression : simple-expression [ relational-operator simple-expression ] .
139 .bp
140 .po
141 factor : variable-access | unsigned-constant | bound-identifier | function-designator | set-constructor |
142 \h'\w'factor : 'u'\fB(\fR expression \fB)\fR | \fBnot\fR factor .
143 field-designator : record-variable \fB.\fR field-specifier | field-designator-identifier .
144 field-designator-identifier : identifier .
145 field-identifier : identifier .
146 field-list : [ ( fixed-part [ \fB;\fR variant-part ] | variant-part ) [ \fB;\fR ] ] .
147 field-specifier : field-identifier .
148 file-type : \fBfile\fR \fBof\fR component-type .
149 file-variable : variable-access .
150 final-value : expression .
151 fixed-part : record-section { \fB;\fR record-section } .
152 for-statement : \fBfor\fR control-variable \fB:=\fR initial-value ( \fBto\fR | \fBdownto\fR ) final-value \fBdo\fR statement .
153 formal-parameter-list : \fB(\fR formal-parameter-section { \fB;\fR formal-parameter-section } \fB)\fR .
154 formal-parameter-section : value-parameter-specification | variable-parameter-specification |
155 \h'\w'formal-parameter-section : 'u'procedural-parameter-specification | functional-parameter-specification |
156 \h'\w'formal-parameter-section : 'u'conformant-array-parameter-specification .
157 function-block : block .
158 function-declaration : function-heading \fB;\fR directive | function-identification \fB;\fR function-block |
159 \h'\w'function-declaration : 'u'function-heading \fB;\fR function-block .
160 function-designator : function-identifier [ actual-parameter-list ] .
161 function-heading : \fBfunction\fR identifier [ formal-parameter-list ] \fB:\fR result-type .
162 function-identification : \fBfunction\fR function-identifier .
163 function-identifier : identifier .
164 functional-parameter-specification : function-heading .
165
166 goto-statement : \fBgoto\fR label .
167
168 identified-variable : pointer-variable \fB^\fR .
169 identifier-list : identifier { \fB,\fR identifier } .
170 if-statement : \fBif\fR Boolean-expression \fBthen\fR statement [ else-part ] .
171 index-expression : expression .
172 index-type : ordinal-type .
173 index-type-specification : identifier \fB..\fR identifier \fB:\fR ordinal-type-identifier .
174 indexed-variable : array-variable \fB[\fR index-expression { \fB,\fR index-expression } \fB]\fR .
175 initial-value : expression .
176
177 label : digit-sequence .
178 label-declaration-part : [ \fBlabel\fR label { \fB,\fR label } \fB;\fR ] .
179
180 member-designator : expression [ \fB..\fR expression ] .
181 multiplying-operator : \fB*\fR | \fB/\fR | \fBdiv\fR | \fBmod\fR | \fBand\fR .
182 .bp
183 .po
184 new-ordinal-type : enumerated-type | subrange-type .
185 new-pointer-type : \fB^\fR domain-type .
186 new-structured-type : [ \fBpacked\fR ] unpacked-structured-type .
187 new-type : new-ordinal-type | new-structured-type | new-pointer-type .
188
189 ordinal-type : new-ordinal-type | ordinal-type-identifier .
190 ordinal-type-identifier : type-identifier .
191
192 packed-conformant-array-schema : \fBpacked\fR \fBarray\fR \fB[\fR index-type-specification \fB]\fR \fBof\fR type-identifier .
193 pointer-type-identifier : type-identifier .
194 pointer-variable : variable-access .
195 procedural-parameter-specification : procedure-heading .
196 procedure-and-function-declaration-part : { ( procedure-declaration | function-declaration ) \fB;\fR } .
197 procedure-block : block .
198 procedure-declaration : procedure-heading \fB;\fR directive | procedure-identification \fB;\fR procedure-block |
199 \h'\w'procedure-declaration : 'u'procedure-heading \fB;\fR procedure-block .
200 procedure-heading : \fBprocedure\fR identifier [ formal-parameter-list ] .
201 procedure-identification : \fBprocedure \fR procedure-identifier .
202 procedure-identifier : identifier .
203 procedure-statement : procedure-identifier ( [ actual-parameter-list ] | read-parameter-list | readln-parameter-list |
204 \h'\w'procedure-statement : procedure-identifier ( ['u'write-parameter-list | writeln-parameter-list ) .
205 program : program-heading \fB;\fR program-block \fB.\fR .
206 program-block : block .
207 program-heading : \fBprogram\fR identifier [ \fB(\fR program-parameters \fB)\fR ] .
208 program-parameters : identifier-list .
209
210 read-parameter-list : \fB(\fR [ file-variable \fB,\fR ] variable-access { \fB,\fR variable-access } \fB)\fR .
211 readln-parameter-list : [ \fB(\fR ( file-variable | variable-access ) { \fB,\fR variable-access } \fB)\fR ] .
212 record-section : identifier-list \fB:\fR type-denoter .
213 record-type : \fBrecord\fR field-list \fBend\fR .
214 record-variable : variable-access .
215 record-variable-list : record-variable { \fB,\fR record-variable } .
216 relational-operator : \fB=\fR | \fB<>\fR | \fB<\fR | \fB>\fR | \fB<=\fR | \fB>=\fR | \fBin\fR .
217 repeat-statement : \fBrepeat\fR statement-sequence \fBuntil\fR Boolean-expression .
218 repetitive-statement : repeat-statement | while-statement | for-statement .
219 result-type : simple-type-identifier | pointer-type-identifier .
220
221 set-constructor : \fB[\fR [ member-designator { \fB,\fR member-designator } ] \fB]\fR .
222 set-type : \fBset\fR \fBof\fR base-type .
223 sign : \fB+\fR | \fB\-\fR .
224 simple-expression : [ sign ] term { adding-operator term } .
225 simple-statement : empty-statement | assignment-statement | procedure-statement | goto-statement .
226 simple-type-identifier : type-identifier .
227 .bp
228 .po
229 statement : [ label \fB:\fR ] ( simple-statement | structured-statement ) .
230 statement-part : compound-statement .
231 statement-sequence : statement { \fB;\fR statement } .
232 structured-statement : compound-statement | conditional-statement | repetitive-statement | with-statement .
233 subrange-type : constant \fB..\fR constant .
234
235 tag-field : identifier .
236 tag-type : ordinal-type-identifier .
237 term : factor { multiplying-operator factor } .
238 type-definition : identifier \fB=\fR type-denoter .
239 type-definition-part : [ \fBtype\fR type-definition \fB;\fR { type-definition \fB;\fR } ] .
240 type-denoter : type-identifier | new-type .
241 type-identifier : identifier .
242
243 unpacked-conformant-array-schema : \fBarray\fR \fB[\fR index-type-specification { \fB;\fR index-type-specification } \fB]\fR \fBof\fR
244 \h'\w'unpacked-conformant-array-schema : 'u'( type-identifier | conformant-array-schema ) .
245 unpacked-structured-type : array-type | record-type | set-type | file-type .
246 unsigned-constant : unsigned-number | character-string | constant-identifier | \fBnil\fR .
247 unsigned-number : unsigned-integer | unsigned-real .
248
249 value-conformant-array-specification : identifier-list \fB:\fR conformant-array-schema .
250 value-parameter-specification : identifier-list \fB:\fR type-identifier .
251 variable-access : entire-variable | component-variable | identified-variable | buffer-variable .
252 variable-conformant-array-specification : \fBvar\fR identifier-list \fB:\fR conformant-array-schema .
253 variable-declaration : identifier-list \fB:\fR type-denoter .
254 variable-declaration-part : [ \fBvar\fR variable-declaration \fB;\fR { variable-declaration \fB;\fR } ] .
255 variable-identifier : identifier .
256 variable-parameter-specification : \fBvar\fR identifier-list \fB:\fR type-identifier .
257 variant : case-constant-list \fB:\fR \fB(\fR field-list \fB)\fR .
258 variant-part : \fBcase\fR variant-selector \fBof\fR variant { \fB;\fR variant } .
259 variant-selector : [ tag-field \fB:\fR ] tag-type .
260
261 while-statement : \fBwhile\fR Boolean-expression \fBdo\fR statement .
262 with-statement : \fBwith\fR record-variable-list \fBdo\fR statement .
263 write-parameter : expression [ \fB:\fR expression [ \fB:\fR expression ] ] .
264 write-parameter-list : \fB(\fR [ file-variable \fB,\fR ] write-parameter { \fB,\fR write-parameter } \fB)\fR .
265 writeln-parameter-list : [ \fB(\fR ( file-variable | write-parameter ) { \fB,\fR write-parameter } \fB)\fR ] .
266 .fi
267 .vs
268 .bp
269 .po