1 | ;;-----------------------------------------------------------------------------
|
---|
2 | ;; Pascal.ebnf
|
---|
3 | ;; Transcribed from The Pascal User Manual and Report 4th ed.
|
---|
4 |
|
---|
5 | program = programheading semicolon block dot.
|
---|
6 | programheading = proglit identifier [ programparameterlist ] .
|
---|
7 | programparameterlist = lparen identifierlist rparen .
|
---|
8 | block = label-declaration-part const-declaration-part type-definition-part variable-declaration-part procedure-declaration-part procedure-and-function-declaration-part statement-part.
|
---|
9 | label-declaration-part = ["label" number {"," number} semicolon].
|
---|
10 | const-declaration-part = ["const" constant-definition semicolon {constant-definition semicolon}].
|
---|
11 | type-definition-part = ["type" type-definition ";" {type-definition ";"}].
|
---|
12 | variable-declaration-part = ["var" variable-declaration semicolon {variable-declaration semicolon}].
|
---|
13 | procedure-and-function-declaration-part = {(procedure-declaration | function-declaration) semicolon}.
|
---|
14 | statement-part = compound-statement.
|
---|
15 | constant-definition = identifier "=" constant.
|
---|
16 | type-definition = identifier "=" type.
|
---|
17 | variable-declaration = identifierlist ":" type.
|
---|
18 | procedure-declaration = procedure-heading semicolon directive
|
---|
19 | | procedure-identification semicolon block.
|
---|
20 | function-declaration = function-heading semicolon block
|
---|
21 | | function-heading semicolon directive
|
---|
22 | | function-identification semicolon block.
|
---|
23 | procedure-heading = "procedure" identifier [formal-parameters-list].
|
---|
24 | procedure-identification = "procedure" procedure-identifier.
|
---|
25 | function-heading = "function" identifier [formal-parameters-list] colon result-type.
|
---|
26 | formal-parameters-list = lparen formal-parameters-section {semicolon formal-parameters-section} rparen.
|
---|
27 | formal-parameters-section = value-parameter-specification
|
---|
28 | | variable-parameter-specification
|
---|
29 | | procedural-parameter-specification
|
---|
30 | | functional-parameter-specification .
|
---|
31 | value-parameter-specification = identifier-list ":" (type-identifier | conformat-array-schema).
|
---|
32 | variable-parameter-specification = "var" identifier-list ":" (type-identifier | conformat-array-schema).
|
---|
33 | procedural-parameter-specification = procedure-heading.
|
---|
34 | functional-parameter-specification = function-heading.
|
---|
35 | conformat-array-schema = packed-constant-array-schema
|
---|
36 | | unpacked-constant-array-schema.
|
---|
37 | packed-constant-array-schema = "packed" "array" "[" index-type-specification "]" "of" type-identifier.
|
---|
38 | unpacked-constant-array-schema = "array" "[" index-type-specification { ";" index-type-specification } "]" "of" (type-identifier | conformat-array-schema).
|
---|
39 | index-type-specification = identifier ".." identifier ":" ordinal-type-identifier.
|
---|
40 | compound-statement = "begin" statement-sequence "end".
|
---|
41 | statement-sequence = statement {";" statement}.
|
---|
42 | statement = [label ":"] (simple-statement | structured-statement).
|
---|
43 | simple-statement = empty-statement
|
---|
44 | | assignment-statement
|
---|
45 | | procedure-statement
|
---|
46 | | goto-statement.
|
---|
47 | structured-statement = compound-statement
|
---|
48 | | conditional-statement
|
---|
49 | | repetitive-statement
|
---|
50 | | with-statement.
|
---|
51 | conditional-statement = if-statement
|
---|
52 | | case-statement.
|
---|
53 | repetitive-statement = while-statement
|
---|
54 | | repeat-statement
|
---|
55 | | for-statement.
|
---|
56 | empty-statement = empty.
|
---|
57 | assignment-statement = (variable | function-identifier) ":=" expression.
|
---|
58 | procedure-statement = procedure-identifier [actual-parameter-list | write-parameter-list].
|
---|
59 | goto-statement = "goto" label.
|
---|
60 | if-statement = "if" boolean-expression "then" statement ["else" statement].
|
---|
61 | case-statement = "case" case-index "of" case {semicolon case} [semicolon] end.
|
---|
62 | repeat-statement = "repeat" statement-sequence "until" boolean-expression.
|
---|
63 | while-statement = "while" boolean-expression "do" statement.
|
---|
64 | for-statement = "for" control-variable ":=" initial-value ("to" | "downto") final-value "do" statement.
|
---|
65 | with-statement = "with" record-variable-list "do" statement.
|
---|
66 | record-variable-list = record-variable {comma record-variable}.
|
---|
67 | case-index = ordinal-expression.
|
---|
68 | case = constant {comma constant} semicolon statement.
|
---|
69 | control-variable = variable-identifier.
|
---|
70 | initial-value = ordinal-expression.
|
---|
71 | final-value = ordinal-expression.
|
---|
72 | type = simple-type | structured-type | pointer-type.
|
---|
73 | simple-type = ordinal-type | real-type-identifier.
|
---|
74 | structured-type = ["packed"] unpacked-structure-type | structured-type-identifier.
|
---|
75 | pointer-type = "^" domain-type | pointer-type-identifier.
|
---|
76 | ordinal-type = enumerated-type | subrange-type | ordinal-type-identifier.
|
---|
77 | unpacked-structure-type = array-type | record-type | set-type | file-type.
|
---|
78 | domain-type = type-identifier.
|
---|
79 | enumerated-type = lparen identifier-list rparen.
|
---|
80 | subrange-type = constant dotdot constant.
|
---|
81 | array-type = "array" "[" index-type {comma index-type} "]" "of" component-type.
|
---|
82 | record-type = "record" field-list "end".
|
---|
83 | set-type = "set" "of" basetype.
|
---|
84 | file-type = "file" "of" component-type.
|
---|
85 | index-type = ordinal-type.
|
---|
86 | component-type = type.
|
---|
87 | base-type = ordinal-type.
|
---|
88 | result-type = ordinal-type-identifier
|
---|
89 | | real-type-identifier
|
---|
90 | | pointer-type-identifier.
|
---|
91 | field-list = [(fixed-part [";" variant-part] | variant-part) [";"]].
|
---|
92 | fixed-part = record-section {";" record-section}.
|
---|
93 | variant-part = "case" variant-selector "of" variant {";" variant}.
|
---|
94 | record-section = identifier-list colon type.
|
---|
95 | variant-selector = [tag-field colon] tag-type.
|
---|
96 | variant = constant {comma constant} colon lparen field-list rparen.
|
---|
97 | tag-type = ordinal-type-identifier.
|
---|
98 | tag-field = identifier.
|
---|
99 | constant = [sign] (unsigned-number | constant-identifier | character-string).
|
---|
100 | expression = simple-expression [relational-operator simple-expression].
|
---|
101 | simple-expression = [sign] term {adding-operator term}.
|
---|
102 | term = factor {multiplying-operator factor}.
|
---|
103 | factor = unsigned-constant | bound-identifier | variable | set-constructor | function-designator | "not" factor | lparen expression rparen.
|
---|
104 | relational-operator = op-eq | op-ne | op-lt | op-le | op-gt | op-ge | op-in.
|
---|
105 | adding-operator = op-add | op-sub | op-or.
|
---|
106 | multiplying-operator = op-mul | op-div | op-divdiv | op-mod | op-and.
|
---|
107 | unsigned-constant = unsigned-number | character-string | constant-identifier | "nil".
|
---|
108 | function-designator = function-identifier [actual-parameter-list].
|
---|
109 | variable = entire-variable | component-variable | identified-variable | buffer-variable.
|
---|
110 | entire-variable = variable-identifier.
|
---|
111 | component-variable = indexed-variable | field-designator.
|
---|
112 | identified-variable = pointer-variable "^".
|
---|
113 | buffer-variable = file-variable "^".
|
---|
114 | indexed-variable = array-variable "[" index {"," index} "]".
|
---|
115 | field-designator = [record-variable "."] field-identifier.
|
---|
116 | set-constructor = "[" [ elememt-description {"," elememt-description} ] "]".
|
---|
117 | elememt-description = ordinal-expression [".." ordinal-expression].
|
---|
118 | actual-parameter-list = lparen actual-parameter {comma actual-parameter} rparen.
|
---|
119 | actual-parameter = expression | variable | procedure-identifier | function-identifier.
|
---|
120 | write-parameter-list = lparen (file-variable | write-parameter) rparen.
|
---|
121 | write-parameter = expression [colon integer-expression [colon integer-expression]].
|
---|
122 | array-variable = variable.
|
---|
123 | record-variable = variable.
|
---|
124 | file-variable = variable.
|
---|
125 | pointer-variable = variable.
|
---|
126 | integer-expression = ordinal-expression.
|
---|
127 | boolean-expression = ordinal-expression.
|
---|
128 | ordinal-expression = expression.
|
---|
129 | pointer-variable = type-identifier.
|
---|
130 | structured-type-identifier = type-identifier.
|
---|
131 | ordinal-type-identifier = type-identifier.
|
---|
132 | real-type-identifier = type-identifier.
|
---|
133 | constant-identifier = identifier.
|
---|
134 | type-identifier = identifier.
|
---|
135 | variable-identifier = identifier.
|
---|
136 | field-identifier = identifier.
|
---|
137 | procedure-identifier = identifier.
|
---|
138 | function-identifier = identifier.
|
---|
139 | bound-identifier = identifier.
|
---|
140 | unsigned-number = unsigned-integer | unsigned-real.
|
---|
141 | identifier-list = identifier {"," identifier}.
|
---|