loom

Форк
0
/
pascal.fuze 
499 строк · 14.2 Кб
1
lex {
2
    lex.setIdExtraSymbols("_");
3
    lex.addMarkup("{", "}", "", lex.LexemeType.Comment);
4
    lex.addMarkup("(*", "*)", "", lex.LexemeType.Comment);
5
    lex.addMarkup("//", "", "", lex.LexemeType.Comment);
6
    lex.addMarkup("'", "'", "", lex.LexemeType.Annotation);
7
    lex.clearMasks();
8
    lex.addMask("@BUILDING_NUMBER_MASK", lex.LexemeType.Number, 10);
9
}
10

11
main program;
12

13
program         = program_heading ";" program_block ".";
14

15
program_block   = block;
16

17
program_heading = "program" ID
18
                = "program" ID "(" program_parameter_list ")";
19

20
program_parameter_list
21
                = "program_parameter_list" ;
22

23
block           = __declaration_part_list__ statement_part
24
                = statement_part;
25

26
__declaration_part_list__
27
                = __declaration_part_list__ __one_declaration_part__ | __one_declaration_part__;
28

29
__one_declaration_part__
30
                = label_declaration_part | constant_definition_part | type_definition_part
31
                variable_declaration_part | procedure_and_function_declaration_part;
32

33

34

35

36

37
label_declaration_part
38
                = "label" __label_list__ ";";
39

40
__label_list__  = __label_list__ "," label | label;
41

42
label           = digit_sequence;
43

44
digit_sequence  = NUMBER;
45

46

47

48

49

50
constant_definition_part
51
                = "const" __constant_definition_list__ ";";
52

53
__constant_definition_list__
54
                = __constant_definition_list__ ";" constant_definition | constant_definition;
55

56
constant_definition
57
                = /*identifier*/ID "=" constant ;
58

59
//identifier      = ID;
60

61
constant        = NUMBER
62
                = /*constant_identifier*/ID
63
//                = sign unsigned_number
64
                = sign /*constant_identifier*/ID
65
                = character_string;
66

67
//unsigned_number = NUMBER;
68

69
//unsigned_integer = digit_sequence;
70

71
//unsigned_real   = digit_sequence "." fractional_part
72
//                = digit_sequence "." fractional_part "e" scale_factor
73
//                = digit_sequence "e" scale_factor;
74

75
//fractional_part = digit_sequence;
76

77
//scale_factor    = digit_sequence
78
//                = sign digit_sequence;
79

80
sign            = "+"
81
                = "-" ;
82

83
//constant_identifier
84
//                = identifier;
85

86
character_string
87
                = ANNOTATION ;
88

89

90

91

92

93
type_definition_part
94
                = "type" __type_definition_list__ ";" ;
95

96
__type_definition_list__
97
                = __type_definition_list__ ";" type_definition | type_definition;
98

99
type_definition
100
                = /*identifier*/ID "=" type_denoter ;
101

102
type_denoter    = /*type_identifier*/ID
103
                = new_type;
104

105
//type_identifier = identifier;
106

107
new_type        = new_ordinal_type | new_structured_type | new_pointer_type;
108

109
new_ordinal_type
110
                = enumerated_type | subrange_type;
111

112
enumerated_type
113
                = "(" identifier_list ")";
114

115
identifier_list = identifier_list "," /*identifier*/ID | /*identifier*/ID;
116

117
subrange_type   = constant ".." constant;
118

119
new_structured_type
120
                = unpacked_structured_type
121
                = "packed" unpacked_structured_type;
122

123
unpacked_structured_type
124
                = array_type | record_type | set_type | file_type;
125

126
array_type      = "array" "[" __index_type_list__ "]" "of" component_type;
127

128
__index_type_list__
129
                = __index_type_list__ "," index_type | index_type;
130

131
index_type      = ordinal_type;
132

133
ordinal_type    = new_ordinal_type | /*ordinal_type_identifier*/ID;
134

135
ordinal_type_identifier
136
                = /*type_identifier*/ID;
137

138
component_type  = type_denoter;
139

140
record_type     = "record" field_list "end"
141
                = "record" "end";
142

143
field_list      = fixed_part
144
                = fixed_part ";"
145
                = fixed_part ";" variant_part
146
                = fixed_part ";" variant_part ";"
147
                = variant_part
148
                = variant_part ";";
149

150
fixed_part      = __record_section_list__ <;
151

152
__record_section_list__
153
                = __record_section_list__  ";" record_section | record_section;
154

155
record_section  = identifier_list ":" type_denoter;
156

157
variant_part    = "case" variant_selector "of" __variant_list__ <;
158

159
variant_selector
160
                = tag_type
161
                = tag_field ":" tag_type;
162

163
tag_field       = /*identifier*/ID;
164

165
tag_type        = ordinal_type_identifier;
166

167
__variant_list__
168
                = __variant_list__ ";" variant | variant;
169

170
variant         = case_constant_list ":" "(" field_list ")"
171
                = case_constant_list ":" "(" ")";
172

173
case_constant_list
174
                = case_constant_list "," case_constant | case_constant;
175

176
case_constant   = constant;
177

178
set_type        = "set" "of" base_type;
179

180
base_type       = ordinal_type;
181

182
file_type       = "file" "of" component_type;
183

184
new_pointer_type
185
                = "↑" /*domain_type*/ID;
186

187
//domain_type     = type_identifier;
188

189

190

191

192

193
variable_declaration_part
194
                = "var" __variable_declaration_list__ ";";
195

196
__variable_declaration_list__
197
                = __variable_declaration_list__  ";" variable_declaration | variable_declaration;
198

199
variable_declaration
200
                = identifier_list ":" type_denoter;
201

202
procedure_and_function_declaration_part
203
                = __procedure_or_function_declaration__ ";" <
204
                = __procedure_or_function_declaration__ ";" procedure_and_function_declaration_part;
205

206
__procedure_or_function_declaration__
207
                = procedure_declaration | function_declaration;
208

209
procedure_declaration
210
                = procedure_heading ";" directive
211
                = /*procedure_identification*/"procedure" ID ";" procedure_block
212
                = procedure_heading ";" procedure_block;
213

214
//procedure_heading
215
//                = "procedure" /*identifier*/ID
216
//                = "procedure" /*identifier*/ID formal_parameter_list;
217

218
formal_parameter_list
219
                = "(" __formal_parameter_section_list__ ")";
220

221
__formal_parameter_section_list__
222
                = __formal_parameter_section_list__ ";" formal_parameter_section | formal_parameter_section;
223

224

225
formal_parameter_section
226
                = value_parameter_specification | variable_parameter_specification | procedural_parameter_specification |functional_parameter_specification;
227

228
formal_parameter_section
229
                = conformant_array_parameter_specification;
230

231
conformant_array_parameter_specification
232
                = value_conformant_array_specification | variable_conformant_array_specification;
233

234
value_conformant_array_specification
235
                = identifier_list ":" conformant_array_schema;
236

237
conformant_array_schema
238
                = packed_conformant_array_schema | unpacked_conformant_array_schema;
239

240
packed_conformant_array_schema
241
                = "packed" "array" "[" index_type_specification "]" "of" /*type_identifier*/ID;
242

243
index_type_specification
244
                = /*identifier*/ID ".." /*identifier*/ID ":" /*ordinal_type_identifier*/ID;
245

246
unpacked_conformant_array_schema
247
                = "array" "[" __index_type_specification_list__  "]" "of" /*type_identifier*/ID
248
                = "array" "[" __index_type_specification_list__  "]" "of" conformant_array_schema ;
249

250
__index_type_specification_list__
251
                = __index_type_specification_list__ ";" index_type_specification | index_type_specification ;
252

253
value_parameter_specification
254
                = identifier_list ":" /*type_identifier*/ID;
255

256
variable_parameter_specification
257
                = "var" identifier_list ":" /*type_identifier*/ID;
258

259
procedural_parameter_specification
260
                = procedure_heading;
261

262
functional_parameter_specification
263
                = function_heading ;
264

265
function_heading
266
                = "function" /*identifier*/ID ":" ID//result_type
267
                = "function" /*identifier*/ID formal_parameter_list ":" ID;//result_type;
268

269
//result_type     = simple_type_identifier | pointer_type_identifier;
270

271
//simple_type_identifier
272
//                = type_identifier;
273

274
//pointer_type_identifier
275
//                = type_identifier;
276

277
directive       = ID;
278

279
//procedure_identification
280
//                = "procedure" ID;//procedure_identifier;
281

282
procedure_identifier
283
                = ID;//identifier ;
284

285
procedure_heading
286
                = "procedure" /*identifier*/ID <
287
                = "procedure" /*identifier*/ID formal_parameter_list;
288

289
procedure_block = block;
290

291
function_declaration
292
                = function_heading ";" directive | function_identification ";" function_block | function_heading ";" function_block;
293

294
function_identification
295
                = "function" function_identifier;
296

297
function_identifier
298
                = "ID";//identifier;
299

300
function_block  = block;
301

302
variable_conformant_array_specification
303
                = "var" identifier_list ":" conformant_array_schema;
304

305

306

307

308

309
statement_part  = compound_statement;
310

311
compound_statement
312
                = "begin" "end"
313
                = "begin" statement_sequence "end";
314

315
statement_sequence
316
                = statement_sequence ";" statement | statement_sequence ";" | statement
317
                = statement_sequence ";"
318
                = ";" ;
319

320
statement       = simple_statement | structured_statement
321
                = label ":" simple_statement
322
                = label ":" structured_statement
323
                = label ":" ;
324

325
simple_statement
326
                = /*empty_statement |*/ assignment_statement | procedure_statement | goto_statement ;
327

328
//empty_statement = "empty_statement";//----------------------------6 .8 .2.1 пустой
329

330
assignment_statement
331
                =  variable_access ":=" expression
332
                =  function_identifier ":=" expression;
333

334
variable_access = entire_variable | component_variable;// | identified_variable | buffer_variable ;
335

336
entire_variable = variable_identifier;
337

338
variable_identifier
339
                = /*identifier*/ID;
340

341
component_variable
342
                = indexed_variable | field_designator;
343

344
indexed_variable
345
                = array_variable "[" __index_expression_list__ "]";
346

347
array_variable  = variable_access;
348

349
__index_expression_list__
350
                = __index_expression_list__ "," index_expression | index_expression;
351

352
index_expression
353
                = expression;
354

355
field_designator
356
                = record_variable "." ID /*field_specifier*/;// | field_designator_identifier;
357

358
record_variable = variable_access;
359

360
//field_specifier = field_identifier;
361

362
//field_identifier
363
//                = identifier;
364

365
//field_designator_identifier
366
//                = identifier;
367

368
//identified_variable
369
//                = pointer_variable "↑" ;
370

371
//pointer_variable
372
//                = variable_access;
373

374
//buffer_variable = file_variable "↑" ;
375

376
file_variable   = variable_access;
377

378
expression      = simple_expression
379
                = simple_expression relational_operator simple_expression;
380

381
simple_expression
382
                = __adding_operator_term_list__
383
                = sign __adding_operator_term_list__;
384

385
term            = __multiplying_operator_factor_list__;
386

387
__multiplying_operator_factor_list__
388
                = __multiplying_operator_factor_list__ multiplying_operator factor
389
                = factor;
390

391
factor          = "ID";//identifier;
392

393
multiplying_operator
394
                = "*" | "/" | "div" | "mod" | "and";
395

396
__adding_operator_term_list__
397
                = __adding_operator_term_list__ adding_operator term
398
                = term;
399

400
adding_operator = "+" | "-" | "or" ;
401

402
relational_operator
403
                = "=" | "<>" | "<" | ">" | "<=" | ">=" | "in" ;
404

405
procedure_statement
406
                = procedure_identifier
407
                = procedure_identifier actual_parameter_list
408
                = procedure_identifier read_parameter_list
409
                = procedure_identifier readln_parameter_list
410
                = procedure_identifier write_parameter_list
411
                = procedure_identifier writeln_parameter_list;
412

413
actual_parameter_list
414
                = "(" __actual_parameter_list__ ")";
415

416
__actual_parameter_list__
417
                = __actual_parameter_list__ "," "actual_parameter" | "actual_parameter" ;
418

419
//actual_parameter
420
//                = "expression" | variable_access | procedure_identifier | function_identifier;
421

422
read_parameter_list
423
                = "(" __variable_access_list__ ")"
424
                = "(" file_variable "," __variable_access_list__ ")";
425

426
__variable_access_list__
427
                = __variable_access_list__ "," "variable_access" | "variable_access";
428

429
readln_parameter_list
430
                = "(" file_variable __variable_access_list__ ")";
431

432
write_parameter_list
433
                = "(" __write_parameter_list__ ")"
434
                = "(" file_variable "," __write_parameter_list__ ")";
435

436
__write_parameter_list__
437
                = __write_parameter_list__ "," write_parameter | write_parameter;
438

439
write_parameter = expression
440
                = expression ":" expression
441
                = expression ":" expression ":" expression;
442

443
writeln_parameter_list
444
                = "(" file_variable  __write_parameter_list__")" ;
445

446
goto_statement  = "goto" label;
447

448
structured_statement
449
                = compound_statement | conditional_statement | repetitive_statement | with_statement;
450

451
conditional_statement
452
                = if_statement | case_statement;
453

454
if_statement    = "if" boolean_expression "then" statement >
455
                = "if" boolean_expression "then" statement else_part;
456

457
boolean_expression
458
                = expression;
459

460
else_part       = "else" statement;
461

462
case_statement  = "case" case_index "of" __case_list_element_list__ "end"
463
                = "case" case_index "of" __case_list_element_list__ ";" "end";
464

465
case_index      = expression;
466

467
__case_list_element_list__
468
                = __case_list_element_list__ ";" case_list_element | case_list_element;
469

470
case_list_element
471
                = case_constant_list ":" statement;
472

473
case_constant_list
474
                = case_constant_list "," case_constant | case_constant;
475

476
case_constant   = constant;
477

478
repetitive_statement
479
                = repeat_statement | while_statement | for_statement;
480

481
repeat_statement
482
                = "repeat" statement_sequence "until" boolean_expression;
483

484
while_statement = "while" boolean_expression "do" statement;
485

486
for_statement   = "for" control_variable ":=" initial_value "to" final_value "do" statement
487
                = "for" control_variable ":=" initial_value "downto" final_value "do" statement;
488

489
control_variable
490
                = entire_variable;
491

492
initial_value   = expression;
493

494
final_value     = expression;
495

496
with_statement  = "with" __record_variable_list__ "do" statement;
497

498
__record_variable_list__
499
                = __record_variable_list__ "," record_variable | record_variable;
500

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.