summaryrefslogtreecommitdiff
path: root/misc/pascal/doc/PascalGrammar.txt
blob: 54b1edf4b7451ea770b01c22a432b150679b2ee9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
PASCAL GRAMMAR:
The start symbol for this grammar is pascal.

   actual-parameter = expression | variable-access |
       procedure-identifier | function-identifier

   actual-parameter-list = '(' actual-parameter { ',' actual-parameter } ')'

   adding-operator = '+' | '-' | 'or' | 'or_else' | 'xor'

   array-type = 'array' '[' index-type-list ']' 'of' type-denoter

   array-variable = variable-access

   assignment-statement = assignment-statement-lhs ':=' expression

   assignment-statement-lhs = variable-access | function-identifier | property-designator

   binary-digit = '0' | '1'

   binary-digit-sequence = binary-digit { binary-digit }

   binary-integer = '%' binary-digit-sequence

   block = declaration-group compound-statement

   boolean-expression = expression

   buffer-variable = file-variable '^' | file-variable '@'

   c-string-type = 'cstring' [ max-string-length ]

   case-body = case-list-elements [ [ ';' ] case-statement-completer ] |
                       case-statement-completer

   case-constant = ordinal-constant

   case-constant-list = case-specifier { ',' case-specifier }

   case-index = ordinal-expression

   case-list-element = case-constant-list ':' statement

   case-list-elements = case-list-element { ';' case-list-element }

   case-specifier = case-constant [ '..' case-constant ]

   case-statement = 'case' case-index case-body [ ';' ] 'end'

   case-statement-completer = ( 'otherwise' | 'else' ) statement-sequence

   character-code = digit-sequence

   character-literal = ''' string-element-one ''' |
                            '"' string-element-two '"' |
                            '#' character-code

   component-variable = indexed-variable | field-designator

   compound-statement = 'begin' statement-sequence 'end'

   conditional-statement = if-statement | case-statement

   constant = [ sign ] integer-number |
                    [ sign ] real-number |
                    [ sign ] constant-identifier |
                               character-literal |
                               string-literal

   constant-definition = identifier '=' constant

   constant-definition-group = 'const' constant-definition ';' { constant-definition ';' }

   constant-identifier = identifier

   control-variable = entire-variable

   decimal-integer = digit-sequence

   declaration-group =
             label-declaration-group |
             constant-definition-group |
             type-definition-group |
             variable-declaration-group |
             function-declaration  |
             procedure-declaration

   digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

   digit-sequence = digit { digit }

   directive = forward-directive | external-directive

   dllname = string-literal

   domain-type = type-identifier

   else-part = 'else' statement

   empty-statement =

   empty-string = '''' | '""'

   entire-variable = variable-identifier

   enumerated-constant = identifier

   enumerated-constant-list = enumerated-constant { ',' enumerated-constant }

   enumerated-type = '(' enumerated-constant-list ')'

   exponent = 'e' | 'E'

   exported-heading =  procedure-heading ';' [ directive ] | function-heading ';' [ directive ]

   expression = shift-expression [ relational-operator shift-expression ]

   external-directive = 'external' 'dll' '=' dllname [ 'name' '=' name ] [ 'stdcall' | 'cdecl' ]

   factor = [ sign ] unsigned-constant |
                [ sign ] variable-access |
                [ sign ] '(' expression ')' |
                [ sign ] function-designator |
                [ sign ] function-method-designator |
                [ sign ] 'not' factor |
                set-constructor

   field-designator = record-variable '.' field-specifier | field-designator-identifier

   field-designator-identifier = identifier

   field-identifier = identifier

   field-list = [
         fixed-part [ ';' ] variant-part [ ';' ] |
         fixed-part [ ';' ] |
         variant-part [ ';' ] |
      ]

   field-specifier = field-identifier

   file-type = 'file' 'of' type-denoter

   file-variable = variable-access

   final-value = ordinal-expression

   fixed-part = record-section { ';' record-section }

   for-statement = 'for' control-variable ':=' initial-value ( 'to' | 'downto' ) final-value
                  'do' statement

   formal-parameter-list = '(' formal-parameter-section { ';' formal-parameter-section } ')'

   formal-parameter-section = value-parameter-specification |
                  variable-parameter-specification |
                  procedure-parameter-specification |
                  function-parameter-specification

   forward-directive = 'forward'

   function-block = block

   function-declaration =
       function-heading ';' directive |
       function-heading ';' function-block

   function-designator = function-identifier [ actual-parameter-list ]

   function-heading = 'function' function-identifier [ formal-parameter-list ] ':' result-type

   function-identifier = identifier

   function-method-designator = object-variable '.' function-method-identifier [ actual-parameter-list ]

   function-method-identifier = identifier

   function-parameter-specification = function-heading

   goto-statement = 'goto' label

   hex-digit = digit | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'

   hex-digit-sequence = hex-digit { hex-digit }

   hexadecimal-integer = '$' hex-digit-sequence

   identified-variable = pointer-variable '^' | pointer-variable '@'

   identifier = letter { letter | digit }

   identifier-list = identifier { ',' identifier }

   if-statement = 'if' boolean-expression 'then' statement [ else-part ]

   implementation-section = 'implementation' [ uses-section ] declaration-group

   index-expression = expression

   index-type = ordinal-type

   index-type-list = index-type { ',' index-type }

   indexed-variable = indexed-variable-array | indexed-variable-string

   indexed-variable-array = array-variable '[' index-expression { ',' index-expression } ']'

   indexed-variable-string = string-variable '[' integral-expression ']'

   initial-value = ordinal-expression

   init-section = 'initialization statement-sequence
       ['finalization' statement-sequence] 'end' |
       compound-statement | 'end'

   integer-number = decimal-integer | hexadecimal-integer | binary-integer

   integral-constant = constant

   integral-expression = expression

   interface-declaration = [ constant-definition-group ]
      [ type-definition-group ] [ variable-declaration-group ]
      exported-heading

   interface-section = 'interface' [ uses-section ] interface-declaration

   label = digit-sequence | identifier

   label-declaration-group = 'label' label { ',' label } ';'

   letter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' |
               'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' |
               'u' | 'v' | 'w' | 'x' | 'y' | 'z' |
               '_'

   list-type = 'list' 'of' type-denoter

   list-variable = variable-access

   max-string-length = '[' integral-constant ']' | '(' integral-constant ')'

   member-designator = ordinal-expression [ '..' ordinal-expression ]

   multiplying-operator = '*' | '/' | 'div' | 'mod' | 'and' | 'and_then'

   name = identifier

   new-complex-type = new-structured-type | new-pointer-type

   new-ordinal-type = enumerated-type | subrange-type

   new-pointer-type = '^' domain-type | '@' domain-type

   new-structured-type =
      [ 'packed' ] array-type |
      [ 'packed' ] record-type |
      [ 'packed' ] set-type |
      [ 'packed' ] file-type |
      [ 'packed' ] list-type |
                         object-type |
                         string-type

   new-type = new-ordinal-type | new-complex-type

   non-empty-string =
       ''' string-element-one string-element-one { string-element-one } ''' |
       '"' string-element-two string-element-two { string-element-two } '"'

   object-type = 'object' | 'class'

   object-variable = variable-access

   ordinal-constant = constant

   ordinal-expression = expression

   ordinal-type = new-ordinal-type | ordinal-type-identifier

   ordinal-type-identifier = identifier

   pascal = program | unit

   pascal-string-type = 'string' [ max-string-length ]

   pointer-variable = variable-access

   printable-character = any character (including a space) that has a visual representation.

   procedure-block = block

   procedure-declaration =
       procedure-heading ';' directive |
       procedure-heading ';' procedure-block

   procedure-heading = 'procedure' procedure-identifier
      [ formal-parameter-list ]

   procedure-identifier = identifier

   procedure-method-identifier = identifier

   procedure-method-specifier = object-variable '.' procedure-method-identifier

   procedure-method-statement = procedure-method-specifier [ actual-parameter-list ]

   procedure-parameter-specification = procedure-heading

   procedure-statement = procedure-identifier (
         [ actual-parameter-list ] |
         read-parameter-list | readln-parameter-list |
         write-parameter-list | writeln-parameter-list
      )

   program = program-heading ';' [ uses-section ] block '.'

   program-heading = 'program' identifier [ '(' identifier-list ')' ]

   property-designator = object-variable '.' property-specifier

   property-identifier = identifier

   property-specifier = property-identifier | '(' property-string ')'

   property-string = string-expression

   read-parameter-list = '(' [ file-variable ',' ] variable-access { ',' variable-access } ')'

   readln-parameter-list = [ '(' ( file-variable | variable-access ) { ',' variable-access } ')' ]

   real-number =
       digit-sequence '.' [digit-sequence] [ exponent scale-factor ] |
       '.' digit-sequence [ exponent scale-factor ] |
       digit-sequence exponent scale-factor

   record-section = identifier-list ':' type-denoter

   record-type = 'record' field-list 'end'

   record-variable = variable-access

   record-variable-list = record-variable { ';' record-variable }

   relational-operator = '=' | '<>' | '<' | '<=' | '>' | '>=' | 'in'

   repeat-statement = 'repeat' statement-sequence 'until' boolean-expression

   repetitive-statement = repeat-statement | while-statement | for-statement

   result-type = type-identifier

   scale-factor = [ sign ] digit-sequence

   selected-variable = list-variable '[' index-expression { ',' index-expression } ']'

   set-constructor = '[' [ member-designator { ',' member-designator } ] ']'

   set-type = 'set' 'of' ordinal-type

   shift-expression = simple-expression [ shift-operator simple-expression ]

   shift-operator = 'shl' | 'shr'

   sign = '-' | '+'

   simple-expression = term { adding-operator term }

   simple-statement = empty-statement | assignment-statement |
              procedure-statement | procedure-method-statement |
              goto-statement

   statement = [ label ':' ] ( simple-statement | structured-statement )

   statement-sequence = statement { ';' statement }

   string-element-one = '''' | printable-character

   string-element-two = '""' | printable-character

   string-expression = expression

   string-literal = empty-string | non-empty-string

   string-type = pascal-string-type | c-string-type

   string-variable = variable-access

   structured-statement = compound-statement |
              conditional-statement |
              repetitive-statement |
              with-statement

   subrange-type = constant '..' constant

   term = factor { multiplying-operator factor }

   type-definition = identifier '=' type-denoter

   type-definition-group = 'type' type-definition ';' { type-definition ';' }

   type-denoter = type-identifier | new-type

   type-identifier = identifier

   unit = 'unit' identifer ';' interface-section implementation-section
      init-section '.'

   unit-import = identifier ['in' non-empty-string ]

   unit = unit-heading ';' interface-section implementation-section init-section

   unit-heading = 'unit' identifer

   unsigned-constant = integer-number | real-number |
         character-literal | string-literal | constant-identifier |
         'nil'

   uses-section = 'uses' [ uses-unit-list ] ';'

   uses-unit-list = unit-import {';' uses-unit-list }

   value-parameter-specification = identifier-list ':' type-identifier

   variable-access = entire-variable | component-variable | identified-variable |
              selected-variable | buffer-variable

   variable-declaration = identifier-list ':' type-denoter

   variable-declaration-group = 'var' variable-declaration { ';' variable-declaration }

   variable-identifier = identifier

   variable-parameter-specification = 'var' identifier-list ':' type-identifier

   variant = case-constant-list ':' '(' field-list ')'

   variant-body = variant-list [ [ ';' ] variant-part-completer ] | variant-part-completer

   variant-list = variant { ';' variant }

   variant-part = 'case' variant-selector 'of' variant-body

   variant-part-completer = ( 'otherwise' | 'else' ) ( field-list )

   variant-selector = [ identifier ':' ] ordinal-type-identifer

   while-statement = 'while' boolean-expression 'do' statement

   with-statement = 'with' record-variable-list 'do' statement

   write-parameter = expression [ ':' expression [ ':' expression ] ]

   write-parameter-list = '(' [ file-variable ',' ] write-parameter { ',' write-parameter } ')'

   writeln-parameter-list = [ '(' ( file-variable | write-parameter ) { ',' write-parameter } ')' ]