1 | start= program | unit | library | package .
|
---|
2 |
|
---|
3 | identifier_list= ID_NAME { ',' ID_NAME } .
|
---|
4 | unit_qualified_identifier= ID_NAME { '.' ID_NAME } .
|
---|
5 |
|
---|
6 | type_name= TYPE_NAME | STRING | FILE .
|
---|
7 | unit_qualified_type_name= type_name [ '.' type_name ] .
|
---|
8 |
|
---|
9 | function_result_type= type_name .
|
---|
10 |
|
---|
11 | constant_expression= F .
|
---|
12 | string_expression= ( STRING_NAME | STRING_LITTERAL )
|
---|
13 | { '+' ( STRING_NAME | STRING_LITTERAL ) } .
|
---|
14 |
|
---|
15 | variable_access= ( ACCESS_NAME | STRING ) { end_access_ } .
|
---|
16 | end_access_= { array_access_ | record_access_ | '^' | function_parameters_ } .
|
---|
17 | array_access_= '[' constant_expression { ',' constant_expression } ']' .
|
---|
18 | record_access_= '.' variable_access .
|
---|
19 | function_parameters_= '(' [ constant_expression { ',' constant_expression } ] ')' .
|
---|
20 |
|
---|
21 | set_factor= '[' [ set_element { ',' set_element } ] ']' .
|
---|
22 | set_element= constant_expression [ '..' constant_expression ] .
|
---|
23 |
|
---|
24 | constant_expression= simple_expression__ [ ('=' | '<>' | '<' | '<=' | '>' | '>=' | IN )
|
---|
25 | simple_expression__ ] .
|
---|
26 | simple_expression__= [ '+' | '-' ] term__ { ('+' | '-' | OR | XOR ) term__ } .
|
---|
27 | term__= factor__ { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor__ } .
|
---|
28 | factor__= NUMBER | STRING_LITTERAL | NIL
|
---|
29 | | variable_access
|
---|
30 | | NOT factor__ | '@' factor__ | set_factor
|
---|
31 | | '^' NAME
|
---|
32 | | '(' constant_expression ')'.
|
---|
33 |
|
---|
34 | typed_constant= simple_expression_ [ ('=' | '<>' | '<' | '<=' | '>' | '>=' | IN )
|
---|
35 | simple_expression_ ] .
|
---|
36 | simple_expression_= [ '+' | '-' ] term_ { ('+' | '-' | OR | XOR ) term_ } .
|
---|
37 | term_= factor_ { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor_ } .
|
---|
38 | factor_= NUMBER | STRING_LITTERAL | NIL
|
---|
39 | // -- id or field "(f1: v1; f2: v2)"
|
---|
40 | | variable_access [ ':' typed_constant
|
---|
41 | { ';' variable_access ':' typed_constant } ]
|
---|
42 | | NOT factor_ | '@' factor_
|
---|
43 | | '^' NAME
|
---|
44 | | '(' [ typed_constant_] ')'
|
---|
45 | | set_factor .
|
---|
46 | // -- array "(1, 2, 3)" or "fn(p1, p2")
|
---|
47 | typed_constant_= typed_constant { ',' typed_constant } .
|
---|
48 |
|
---|
49 | formal_parameters= '(' formal_parameter { ';' formal_parameter } ')' .
|
---|
50 | formal_parameter= [ parameter | var_parameter
|
---|
51 | | const_parameter | out_parameter | in_parameter ] .
|
---|
52 | parameter_name_list= PARAMETER_NAME { ',' PARAMETER_NAME } .
|
---|
53 | array_or_name_type= ARRAY OF ( CONST | unit_qualified_type_name )
|
---|
54 | | unit_qualified_type_name .
|
---|
55 | parameter= parameter_name_list ':' array_or_name_type
|
---|
56 | ['=' constant_expression ] .
|
---|
57 | var_parameter= VAR parameter_name_list [ ':' array_or_name_type ] .
|
---|
58 | const_parameter= CONST parameter_name_list
|
---|
59 | [ ':' array_or_name_type ['=' constant_expression ] ] .
|
---|
60 | out_parameter= OUT parameter_name_list [ ':' array_or_name_type ] .
|
---|
61 | in_parameter= IN parameter .
|
---|
62 |
|
---|
63 | dos_directives= NEAR | FAR | EXPORT | ASSEMBLER .
|
---|
64 | calling_directives= CDECL | PASCAL | REGISTER | SAFECALL | STDCALL .
|
---|
65 | overload_directive= OVERLOAD .
|
---|
66 | method_directives= ABSTRACT | VIRTUAL | DYNAMIC
|
---|
67 | | OVERRIDE | REINTRODUCE | MESSAGE constant_expression .
|
---|
68 |
|
---|
69 | const_type_var_declarations= constant_definitions | resource_defintions
|
---|
70 | | type_definitions | variable_declarations .
|
---|
71 |
|
---|
72 | type= keyed_types | type_0 .
|
---|
73 | // -- called by i_type
|
---|
74 | enumeration_type= '(' identifier_list ')' .
|
---|
75 | expression_t= simple_expression_t
|
---|
76 | [ ( ('=' | '<>' | '<' | '<=' | '>' | '>=' | IN ) simple_expression_t
|
---|
77 | | '..' end_range_type ) ] .
|
---|
78 | simple_expression_t= [ '+' | '-' ] term_t { ('+' | '-' | OR | XOR ) term_t } .
|
---|
79 | term_t= factor_t { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor_t } .
|
---|
80 | factor_t= NUMBER | STRING_LITTERAL | NIL
|
---|
81 | | variable_access
|
---|
82 | | NOT factor_t | '@' factor_t
|
---|
83 | | '^' NAME
|
---|
84 | | '(' expression_t ')'
|
---|
85 | | set_factor .
|
---|
86 | end_range_type= simple_expression_t .
|
---|
87 | type_0= ( NUMBER | STRING_LITTERAL | NIL | NOT | '+' | '-' | '@' | '(' | '[' | NAME )
|
---|
88 | $i_type .
|
---|
89 | keyed_types= string_type | structured_type | pointer_type | procedural_type .
|
---|
90 | // -- handle STRING as array[index_type]
|
---|
91 | string_type= STRING [ '[' constant_expression ']' ] .
|
---|
92 | structured_type= [ PACKED ] ( array_type | record_type | set_type | file_type ) .
|
---|
93 | array_type= ARRAY [ '[' index_type { ',' index_type } ']' ] OF type .
|
---|
94 | index_type= constant_expression [ '..' constant_expression ] .
|
---|
95 | record_type= RECORD field_list END .
|
---|
96 | field_list= { common_field ';' } [ variant_fields ] .
|
---|
97 | common_field= identifier_list ':' type .
|
---|
98 | variant_fields= CASE tag OF cases { cases } .
|
---|
99 | tag= VARIANT_TAG_NAME [ ':' unit_qualified_type_name ] .
|
---|
100 | cases= constant_expression { ',' constant_expression }
|
---|
101 | ':' one_case .
|
---|
102 | one_case= '(' [ common_field { ';' [ ( common_field | variant_fields ) ] }
|
---|
103 | | variant_fields ]
|
---|
104 | ')' [ ';' ] .
|
---|
105 | set_type= SET OF type .
|
---|
106 | file_type= FILE [ OF type ] .
|
---|
107 | pointer_type= '^' POINTED_NAME .
|
---|
108 | procedural_type= ( PROCEDURE [ formal_parameters ]
|
---|
109 | | FUNCTION [ formal_parameters ] ':' function_result_type )
|
---|
110 | $<dir( [ OF OBJECT ] | i_procedural_type_directives ) $>dir .
|
---|
111 | procedural_type_directives= calling_directives .
|
---|
112 | i_procedural_type_directives= ( ';'
|
---|
113 | | CDECL | PASCAL | REGISTER | SAFECALL | STDCALL ) $i_directives .
|
---|
114 |
|
---|
115 | constant_definitions= CONST constant_definition { constant_definition } .
|
---|
116 | constant_definition= CONST_NAME [ ':' type ] '=' typed_constant ';' .
|
---|
117 |
|
---|
118 | resource_defintions= RESOURCESTRING resource_definition { resource_definition } .
|
---|
119 | resource_definition= RESOURCE_NAME '=' string_expression ';' .
|
---|
120 |
|
---|
121 | type_definitions= TYPE type_definition { type_definition } .
|
---|
122 | type_definition= TYPE_NAME '=' [ TYPE ] ( class_type | interface_type | type ) ';' .
|
---|
123 |
|
---|
124 | // -- used in INTERFACE also
|
---|
125 | property= PROPERTY $>priv PROPERTY_NAME [ property_type ] property_specifiers .
|
---|
126 | property_type= [ property_indexes ] ':' unit_qualified_type_name .
|
---|
127 | property_indexes= '[' property_index { ';' property_index } ']' .
|
---|
128 | property_index= [ CONST ] INDEX_NAME { ',' INDEX_NAME }
|
---|
129 | ':' unit_qualified_type_name .
|
---|
130 | property_specifiers= $<prop [ INDEX constant_expression ] $>prop
|
---|
131 | // -- "READ FTabSize.Y"
|
---|
132 | $<prop [ READ variable_access | READONLY ]
|
---|
133 | [ WRITE WRITE_NAME | WRITEONLY ] $>prop
|
---|
134 | // -- some params called "dispid"
|
---|
135 | $<prop [ DISPID constant_expression ] [ ';' ] $>prop
|
---|
136 | $<prop { storage_specifier [';' ] } $>prop
|
---|
137 | [ IMPLEMENTS unit_qualified_identifier { ',' unit_qualified_identifier } ';' ] .
|
---|
138 | storage_specifier= storage_stored | storage_default | storage_no_default .
|
---|
139 | storage_stored= STORED [ constant_expression ] .
|
---|
140 | storage_default= DEFAULT [ constant_expression ] .
|
---|
141 | storage_no_default= NODEFAULT .
|
---|
142 |
|
---|
143 | // -- the ; is in the type_definitions
|
---|
144 | class_type= CLASS [ class_reference | class_definition ] .
|
---|
145 | class_reference= OF unit_qualified_type_name .
|
---|
146 | // -- class_definition : can be foward with inheritance
|
---|
147 | class_definition= [ inheritance ] [ class_body ] .
|
---|
148 | inheritance= '(' unit_qualified_type_name { ',' unit_qualified_type_name } ')' .
|
---|
149 | class_body= fields_and_procs_section { fields_and_procs_section } END .
|
---|
150 | fields_and_procs_section= $<priv protection fields_and_procs $>priv .
|
---|
151 | protection= [ PRIVATE | PROTECTED | PUBLIC | PUBLISHED ] .
|
---|
152 | fields_and_procs= { class_field } { class_methods | property $<priv } .
|
---|
153 | class_field= identifier_list $>priv ':' type ';' $<priv .
|
---|
154 | class_methods= constructor | destructor |
|
---|
155 | [ CLASS ] ( class_procedure | class_function ) .
|
---|
156 | method_directives_= $<dir
|
---|
157 | { (method_directives | overload_directive | calling_directives)
|
---|
158 | [ ';'] } $>dir .
|
---|
159 | // -- if interfaces : "FUNCTION i_xxx.yyy = zzz;"
|
---|
160 | rename_method= '.' NAME '=' NAME ';' .
|
---|
161 | constructor= CONSTRUCTOR $>priv PR_NAME [ formal_parameters ] ';'
|
---|
162 | method_directives_ $<priv .
|
---|
163 | destructor= DESTRUCTOR $>priv PR_NAME [ formal_parameters ] ';'
|
---|
164 | method_directives_ $<priv .
|
---|
165 | class_procedure= PROCEDURE $>priv PR_NAME
|
---|
166 | ( rename_method | [ formal_parameters ] ';'
|
---|
167 | method_directives_ ) $<priv .
|
---|
168 | class_function= FUNCTION $>priv FN_NAME
|
---|
169 | ( rename_method | [ formal_parameters ] ':' function_result_type ';'
|
---|
170 | method_directives_ ) $<priv .
|
---|
171 |
|
---|
172 | interface_type= ( INTERFACE | DISPINTERFACE ) [ interface_definition ] .
|
---|
173 | interface_definition= [ interface_heritage] [interface_g_u_i_d ]
|
---|
174 | interface_member_list END .
|
---|
175 | interface_heritage= '(' identifier_list ')' .
|
---|
176 | interface_g_u_i_d= '[' string_expression ']' .
|
---|
177 | interface_member_list= { class_procedure_ | class_function_ | property } .
|
---|
178 | interface_directives_= $<dir
|
---|
179 | { (method_directives | overload_directive | calling_directives | dispid )
|
---|
180 | [ ';'] } $>dir .
|
---|
181 | dispid= DISPID constant_expression .
|
---|
182 | // -- redefinition "PROCEDURE x.y= z;" (axctrls)
|
---|
183 | class_procedure_= ( PROCEDURE | CONSTRUCTOR | DESTRUCTOR )
|
---|
184 | PR_NAME [ formal_parameters ] ';' interface_directives_ .
|
---|
185 | class_function_= FUNCTION FN_NAME [ formal_parameters ] ':' function_result_type ';'
|
---|
186 | interface_directives_ .
|
---|
187 |
|
---|
188 | variable_declarations= (THREADVAR | VAR) variable_declaration { variable_declaration } .
|
---|
189 | // -- has separated in 2 because of initialization
|
---|
190 | // -- absolute can be after a list, but not with initialization
|
---|
191 | variable_declaration= ID_NAME
|
---|
192 | ( ':' type [ '=' typed_constant | absolute ] ';'
|
---|
193 | | { ',' ID_NAME } ':' type [ absolute ] ';' ) .
|
---|
194 | absolute= ABSOLUTE OTHER_VAR_NAME .
|
---|
195 |
|
---|
196 | // -- code
|
---|
197 |
|
---|
198 | expression= simple_expression [ ('=' | '<>' | '<' | '<=' | '>' | '>=' | IN | IS )
|
---|
199 | simple_expression ] .
|
---|
200 | simple_expression= [ '+' | '-' ] term { ('+' | '-' | OR | XOR ) term } .
|
---|
201 | term= factor { ('*' | '/' | DIV | MOD | AND | SHR | SHL ) factor } .
|
---|
202 | // -- called by $i_access_or_expression
|
---|
203 | // -- can be empty if fn call "fn()"
|
---|
204 | parenthized_expression= '(' [ expression { ',' expression } ] ')' .
|
---|
205 | factor= NUMBER | STRING_LITTERAL | NIL
|
---|
206 | | NOT factor | '@' factor | INHERITED [ factor ]
|
---|
207 | | '^' NAME
|
---|
208 | | set_factor
|
---|
209 | // -- x= (Sender AS tButton).Caption
|
---|
210 | // -- the AS is only for the level 0
|
---|
211 | | ( NAME | STRING ) { parenthized_expression | end_access }
|
---|
212 | | parenthized_expression { end_access } .
|
---|
213 | end_access= { array_access | record_access | '^' | as_access } .
|
---|
214 | array_access= '[' expression { ',' expression } ']' .
|
---|
215 | record_access= '.' expression .
|
---|
216 | as_access= AS NAME .
|
---|
217 |
|
---|
218 | // -- instructions
|
---|
219 |
|
---|
220 | asm= ASM { asm_statement } END .
|
---|
221 | // -- for pasting in i_asm
|
---|
222 | asm_statement_= { NAME | NUMBER | STRING_LITTERAL
|
---|
223 | | '[' | ']' | '.' | ','
|
---|
224 | | ':'
|
---|
225 | | '+' | '-' | '*' | '/'
|
---|
226 | | NOT | AND | OR | XOR | SHR | SHL | DIV } .
|
---|
227 | label_= '@' [ '@'] ( ALL_NAME | NUMBER ) .
|
---|
228 |
|
---|
229 | asm_statement= ( NAME | NUMBER | STRING_LITTERAL
|
---|
230 | | '[' | ']' | '.' | ','
|
---|
231 | | '@'
|
---|
232 | | ':'
|
---|
233 | | '+' | '-' | '*' | '/'
|
---|
234 | | NOT | AND | OR | XOR | SHR | SHL | DIV ) $i_asm .
|
---|
235 |
|
---|
236 | composed_instruction= F .
|
---|
237 |
|
---|
238 | // -- allows empty ";" instruction
|
---|
239 | instruction_list= [ instruction ] { ';' [ instruction ] } .
|
---|
240 | instruction= { assignment_or_call | structured_instruction } .
|
---|
241 |
|
---|
242 | // -- this covers "x[3].z:= u;" or "my_proc(3+ zz)";
|
---|
243 | // -- acces or (pchar+ 1)^ := ...
|
---|
244 | assignment_or_call= expression [ end_assignment ] .
|
---|
245 | // -- "(Sender As tButton).Caption:= xxx"
|
---|
246 | end_assignment= ':=' expression .
|
---|
247 |
|
---|
248 | structured_instruction= composed_instruction | test | repetition | with
|
---|
249 | | try | inherited_call | raise_statement | asm .
|
---|
250 | test= if | case .
|
---|
251 | if= IF expression THEN instruction [ ELSE instruction ] .
|
---|
252 | // -- D5: ';' after last instr or before ELSE optional !
|
---|
253 | case= CASE expression OF case_element
|
---|
254 | { ';' [ ELSE $NOREAD | END $NOREAD | case_element ] }
|
---|
255 | [ ELSE instruction_list ] END .
|
---|
256 | case_element= case_label ':' instruction .
|
---|
257 | // -- a general constant constant_expression, but no set [],
|
---|
258 | // -- unless in a function call
|
---|
259 | case_label= constant_expression
|
---|
260 | { ( ',' constant_expression | '..' constant_expression ) } .
|
---|
261 | repetition= while | repeat | for .
|
---|
262 | while= WHILE expression DO instruction .
|
---|
263 | repeat= REPEAT instruction_list UNTIL expression .
|
---|
264 | for= FOR unit_qualified_identifier ':=' expression [ TO | DOWNTO ]
|
---|
265 | expression DO instruction .
|
---|
266 | // -- "with xxx AS"
|
---|
267 | with= WITH expression { ',' expression } DO instruction .
|
---|
268 | try= TRY instruction_list
|
---|
269 | ( EXCEPT except_block | FINALLY instruction_list ) END .
|
---|
270 | except_block= on [ ELSE instruction_list ] | instruction_list .
|
---|
271 | // -- can have "ON ezero DO ELSE xxx ;" or "ON xxx DO ;"
|
---|
272 | on= handle_instruction { ';' [ handle_instruction ] } .
|
---|
273 | exception_identifier= unit_qualified_identifier [ ':' unit_qualified_identifier ] .
|
---|
274 | handle_instruction= ON exception_identifier DO [ instruction ';' ] .
|
---|
275 |
|
---|
276 | // -- "Inherited Items[Index]:= "
|
---|
277 | inherited_call= INHERITED [ instruction ] .
|
---|
278 | // inline_statement= INLINE '(' INTEGERCONST {'/' INTEGERCONST } ')' .
|
---|
279 | raise_statement= $<at RAISE [ variable_access ] [ AT constant_expression ] $>at .
|
---|
280 |
|
---|
281 | composed_instruction= BEGIN instruction_list END .
|
---|
282 |
|
---|
283 | // -- bloc
|
---|
284 | // -- VIRTUAL etc only in CLASS
|
---|
285 |
|
---|
286 | routine_header= class_methods_header | constructor_header | destructor_header
|
---|
287 | | procedure_header | function_header .
|
---|
288 | // -- methods have no directives in implementation
|
---|
289 | class_methods_header= CLASS (class_procedure_method | class_function_method ) .
|
---|
290 | class_procedure_method= PROCEDURE CLASS_NAME '.' PR_NAME [ formal_parameters ] ';' .
|
---|
291 | // -- repeating the result is optional
|
---|
292 | class_function_method= FUNCTION CLASS_NAME [ '.' FN_NAME ]
|
---|
293 | [ formal_parameters ] [ ':' function_result_type ] ';' .
|
---|
294 | constructor_header= CONSTRUCTOR CLASS_NAME '.' PR_NAME [ formal_parameters ] ';' .
|
---|
295 | destructor_header= DESTRUCTOR CLASS_NAME '.' PR_NAME [ formal_parameters ] ';' .
|
---|
296 | // -- always ; before directives (for procedural cdecl is without ? )
|
---|
297 | code_procedure_directives= $<dir { (dos_directives
|
---|
298 | | calling_directives | overload_directive)
|
---|
299 | [ ';'] } $>dir .
|
---|
300 | procedure_header= PROCEDURE
|
---|
301 | CLASS_OR_PR_NAME [ '.' PR_NAME ] [ formal_parameters ] ';'
|
---|
302 | code_procedure_directives .
|
---|
303 | // -- for the functions, STDCALL does not require ; "fn xxx: yyy STDCALL;"
|
---|
304 | function_header= FUNCTION CLASS_OR_FN_NAME [ '.' FN_NAME ]
|
---|
305 | [ formal_parameters ] [ ':' function_result_type ]
|
---|
306 | [ ';' ] code_procedure_directives [ ';' ] .
|
---|
307 |
|
---|
308 | bloc= F .
|
---|
309 | main_declarations= const_type_var_declarations | procedure_declarations_and_body .
|
---|
310 | procedure_declarations_and_body= { procedure_declaration } .
|
---|
311 | procedure_declaration= routine_header
|
---|
312 | $<dir ( FORWARD $>dir | EXTERNAL $>dir end_external | $>dir bloc ) ';' .
|
---|
313 | // "procedure xxx; external;"
|
---|
314 | // "procedure xxx; external 'xxx';"
|
---|
315 | // "procedure xxx; external xxx;"
|
---|
316 | // "procedure xxx; external xxx NAME 'MessageBoxA';"
|
---|
317 | // "procedure xxx; external xxx 'MessageBoxA' INDEX 31;"
|
---|
318 | end_external= [ constant_expression $<index [ index ] $>index ] '.' .
|
---|
319 | index= INDEX constant_expression .
|
---|
320 | bloc= { main_declarations } ( composed_instruction | asm ) .
|
---|
321 |
|
---|
322 | main_uses= USES uses_in { ',' uses_in } ';' .
|
---|
323 | uses_in= UNIT_NAME [ IN constant_expression ] .
|
---|
324 |
|
---|
325 | // -- program / units / library / packages
|
---|
326 |
|
---|
327 | program= PROGRAM NAME ';' [ main_uses ] bloc '.' .
|
---|
328 |
|
---|
329 | unit= UNIT UNIT_NAME ';' unit_interface unit_implementation unit_end '.' .
|
---|
330 | uses= USES identifier_list ';' .
|
---|
331 | unit_interface= INTERFACE [ uses ] { const_type_var_declarations | routine_header } .
|
---|
332 | unit_implementation= IMPLEMENTATION [ uses ] { main_declarations } .
|
---|
333 | unit_end= ( BEGIN instruction_list | initialization ) END .
|
---|
334 | initialization= [ INITIALIZATION instruction_list [ FINALIZATION instruction_list ]] .
|
---|
335 |
|
---|
336 | library= LIBRARY LIBRARY_NAME main_uses bloc '.' .
|
---|
337 |
|
---|
338 | package= PACKAGE PACKAGE_NAME ';'
|
---|
339 | $<pack [ requires_clause ] [ contains_clause ] $>pack END '.' .
|
---|
340 | requires_clause= REQUIRES REQUIRES_NAME {',' REQUIRES_NAME } ';' .
|
---|
341 | contains_clause= CONTAINS contains_statement {',' contains_statement } ';' .
|
---|
342 | contains_statement= CONTAINS_NAME [ IN constant_expression ] .
|
---|
343 | .
|
---|