source: branches/generator/Grammers/Pascal2.ebnf

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