c.opp.exp 12.8 KB
Newer Older
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
%start translation_unit
%token XOR_ASSIGN
%token WHILE
%token VOLATILE
%token VOID
%token UNSIGNED
%token UNION
%token TYPE_NAME
%token TYPEDEF
%token TILDE
%token SWITCH
%token SUB_ASSIGN
%token STRUCT
%token STRING_LITERAL
%token STATIC
%token STAR
%token SLASH
%token SIZEOF
%token SIGNED
%token SHORT
%token SEMICOLON
%token RPAREN
%token RIGHT_OP
%token RIGHT_ASSIGN
%token RETURN
%token REGISTER
%token RBRACK
%token RBRACE
%token QUESTION
%token PTR_OP
%token PLUS
%token PERCENT
%token OR_OP
%token OR_ASSIGN
%token NE_OP
%token MUL_ASSIGN
%token MOD_ASSIGN
%token MINUS
%token LT
%token LPAREN
%token LONG
%token LE_OP
%token LEFT_OP
%token LEFT_ASSIGN
%token LBRACK
%token LBRACE
%token INT
%token INC_OP
%token IF
%token IDENTIFIER
%token HAT
%token GT
%token GOTO
%token GE_OP
%token FOR
%token FLOAT
%token EXTERN
%token EQ_OP
%token EQUAL
%token ENUM
%token ELSE
%token ELLIPSIS
%token DOUBLE
%token DOT
%token DO
%token DIV_ASSIGN
%token DEFAULT
%token DEC_OP
%token CONTINUE
%token CONSTANT
%token CONST
%token COMMA
%token COLON
%token CHAR
%token CASE
%token BREAK
%token BAR
%token BANG
%token AUTO
%token AND_OP
%token AND_ASSIGN
%token AMPERSAND
%token ADD_ASSIGN

%type <unit> translation_unit
%%

primary_expression:
89 90 91 92 93 94 95 96
| _1 = IDENTIFIER
    { ()}
| _1 = CONSTANT
    { ()}
| _1 = STRING_LITERAL
    { ()}
| _1 = LPAREN _2 = expression _3 = RPAREN
    { ()}
97 98

postfix_expression:
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| _1 = primary_expression
    { ()}
| _1 = postfix_expression _2 = LBRACK _3 = expression _4 = RBRACK
    { ()}
| _1 = postfix_expression _2 = LPAREN _3 = RPAREN
    { ()}
| _1 = postfix_expression _2 = LPAREN _3 = argument_expression_list _4 = RPAREN
    { ()}
| _1 = postfix_expression _2 = DOT _3 = IDENTIFIER
    { ()}
| _1 = postfix_expression _2 = PTR_OP _3 = IDENTIFIER
    { ()}
| _1 = postfix_expression _2 = INC_OP
    { ()}
| _1 = postfix_expression _2 = DEC_OP
    { ()}
115 116

argument_expression_list:
117 118 119 120
| _1 = assignment_expression
    { ()}
| _1 = argument_expression_list _2 = COMMA _3 = assignment_expression
    { ()}
121 122

unary_expression:
123 124 125 126 127 128 129 130 131 132 133 134
| _1 = postfix_expression
    { ()}
| _1 = INC_OP _2 = unary_expression
    { ()}
| _1 = DEC_OP _2 = unary_expression
    { ()}
| _1 = unary_operator _2 = cast_expression
    { ()}
| _1 = SIZEOF _2 = unary_expression
    { ()}
| _1 = SIZEOF _2 = LPAREN _3 = type_name _4 = RPAREN
    { ()}
135 136

unary_operator:
137 138 139 140 141 142 143 144 145 146 147 148
| _1 = AMPERSAND
    { ()}
| _1 = STAR
    { ()}
| _1 = PLUS
    { ()}
| _1 = MINUS
    { ()}
| _1 = TILDE
    { ()}
| _1 = BANG
    { ()}
149 150

cast_expression:
151 152 153 154
| _1 = unary_expression
    { ()}
| _1 = LPAREN _2 = type_name _3 = RPAREN _4 = cast_expression
    { ()}
155 156

multiplicative_expression:
157 158 159 160 161 162 163 164
| _1 = cast_expression
    { ()}
| _1 = multiplicative_expression _2 = STAR _3 = cast_expression
    { ()}
| _1 = multiplicative_expression _2 = SLASH _3 = cast_expression
    { ()}
| _1 = multiplicative_expression _2 = PERCENT _3 = cast_expression
    { ()}
165 166

additive_expression:
167 168 169 170 171 172
| _1 = multiplicative_expression
    { ()}
| _1 = additive_expression _2 = PLUS _3 = multiplicative_expression
    { ()}
| _1 = additive_expression _2 = MINUS _3 = multiplicative_expression
    { ()}
173 174

shift_expression:
175 176 177 178 179 180
| _1 = additive_expression
    { ()}
| _1 = shift_expression _2 = LEFT_OP _3 = additive_expression
    { ()}
| _1 = shift_expression _2 = RIGHT_OP _3 = additive_expression
    { ()}
181 182

relational_expression:
183 184 185 186 187 188 189 190 191 192
| _1 = shift_expression
    { ()}
| _1 = relational_expression _2 = LT _3 = shift_expression
    { ()}
| _1 = relational_expression _2 = GT _3 = shift_expression
    { ()}
| _1 = relational_expression _2 = LE_OP _3 = shift_expression
    { ()}
| _1 = relational_expression _2 = GE_OP _3 = shift_expression
    { ()}
193 194

equality_expression:
195 196 197 198 199 200
| _1 = relational_expression
    { ()}
| _1 = equality_expression _2 = EQ_OP _3 = relational_expression
    { ()}
| _1 = equality_expression _2 = NE_OP _3 = relational_expression
    { ()}
201 202

and_expression:
203 204 205 206
| _1 = equality_expression
    { ()}
| _1 = and_expression _2 = AMPERSAND _3 = equality_expression
    { ()}
207 208

exclusive_or_expression:
209 210 211 212
| _1 = and_expression
    { ()}
| _1 = exclusive_or_expression _2 = HAT _3 = and_expression
    { ()}
213 214

inclusive_or_expression:
215 216 217 218
| _1 = exclusive_or_expression
    { ()}
| _1 = inclusive_or_expression _2 = BAR _3 = exclusive_or_expression
    { ()}
219 220

logical_and_expression:
221 222 223 224
| _1 = inclusive_or_expression
    { ()}
| _1 = logical_and_expression _2 = AND_OP _3 = inclusive_or_expression
    { ()}
225 226

logical_or_expression:
227 228 229 230
| _1 = logical_and_expression
    { ()}
| _1 = logical_or_expression _2 = OR_OP _3 = logical_and_expression
    { ()}
231 232

conditional_expression:
233 234 235 236
| _1 = logical_or_expression
    { ()}
| _1 = logical_or_expression _2 = QUESTION _3 = expression _4 = COLON _5 = conditional_expression
    { ()}
237 238

assignment_expression:
239 240 241 242
| _1 = conditional_expression
    { ()}
| _1 = unary_expression _2 = assignment_operator _3 = assignment_expression
    { ()}
243 244

assignment_operator:
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
| _1 = EQUAL
    { ()}
| _1 = MUL_ASSIGN
    { ()}
| _1 = DIV_ASSIGN
    { ()}
| _1 = MOD_ASSIGN
    { ()}
| _1 = ADD_ASSIGN
    { ()}
| _1 = SUB_ASSIGN
    { ()}
| _1 = LEFT_ASSIGN
    { ()}
| _1 = RIGHT_ASSIGN
    { ()}
| _1 = AND_ASSIGN
    { ()}
| _1 = XOR_ASSIGN
    { ()}
| _1 = OR_ASSIGN
    { ()}
267 268

expression:
269 270 271 272
| _1 = assignment_expression
    { ()}
| _1 = expression _2 = COMMA _3 = assignment_expression
    { ()}
273 274

constant_expression:
275 276
| _1 = conditional_expression
    { ()}
277 278

declaration:
279 280 281 282
| _1 = declaration_specifiers _2 = SEMICOLON
    { ()}
| _1 = declaration_specifiers _2 = init_declarator_list _3 = SEMICOLON
    { ()}
283 284

declaration_specifiers:
285 286 287 288 289 290 291 292 293 294 295 296
| _1 = storage_class_specifier
    { ()}
| _1 = storage_class_specifier _2 = declaration_specifiers
    { ()}
| _1 = type_specifier
    { ()}
| _1 = type_specifier _2 = declaration_specifiers
    { ()}
| _1 = type_qualifier
    { ()}
| _1 = type_qualifier _2 = declaration_specifiers
    { ()}
297 298

init_declarator_list:
299 300 301 302
| _1 = init_declarator
    { ()}
| _1 = init_declarator_list _2 = COMMA _3 = init_declarator
    { ()}
303 304

init_declarator:
305 306 307 308
| _1 = declarator
    { ()}
| _1 = declarator _2 = EQUAL _3 = c_initializer
    { ()}
309 310

storage_class_specifier:
311 312 313 314 315 316 317 318 319 320
| _1 = TYPEDEF
    { ()}
| _1 = EXTERN
    { ()}
| _1 = STATIC
    { ()}
| _1 = AUTO
    { ()}
| _1 = REGISTER
    { ()}
321 322

type_specifier:
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
| _1 = VOID
    { ()}
| _1 = CHAR
    { ()}
| _1 = SHORT
    { ()}
| _1 = INT
    { ()}
| _1 = LONG
    { ()}
| _1 = FLOAT
    { ()}
| _1 = DOUBLE
    { ()}
| _1 = SIGNED
    { ()}
| _1 = UNSIGNED
    { ()}
| _1 = struct_or_union_specifier
    { ()}
| _1 = enum_specifier
    { ()}
| _1 = TYPE_NAME
    { ()}
347 348

struct_or_union_specifier:
349 350 351 352 353 354
| _1 = struct_or_union _2 = IDENTIFIER _3 = LBRACE _4 = struct_declaration_list _5 = RBRACE
    { ()}
| _1 = struct_or_union _2 = LBRACE _3 = struct_declaration_list _4 = RBRACE
    { ()}
| _1 = struct_or_union _2 = IDENTIFIER
    { ()}
355 356

struct_or_union:
357 358 359 360
| _1 = STRUCT
    { ()}
| _1 = UNION
    { ()}
361 362

struct_declaration_list:
363 364 365 366
| _1 = struct_declaration
    { ()}
| _1 = struct_declaration_list _2 = struct_declaration
    { ()}
367 368

struct_declaration:
369 370
| _1 = specifier_qualifier_list _2 = struct_declarator_list _3 = SEMICOLON
    { ()}
371 372

specifier_qualifier_list:
373 374 375 376 377 378 379 380
| _1 = type_specifier _2 = specifier_qualifier_list
    { ()}
| _1 = type_specifier
    { ()}
| _1 = type_qualifier _2 = specifier_qualifier_list
    { ()}
| _1 = type_qualifier
    { ()}
381 382

struct_declarator_list:
383 384 385 386
| _1 = struct_declarator
    { ()}
| _1 = struct_declarator_list _2 = COMMA _3 = struct_declarator
    { ()}
387 388

struct_declarator:
389 390 391 392 393 394
| _1 = declarator
    { ()}
| _1 = COLON _2 = constant_expression
    { ()}
| _1 = declarator _2 = COLON _3 = constant_expression
    { ()}
395 396

enum_specifier:
397 398 399 400 401 402
| _1 = ENUM _2 = LBRACE _3 = enumerator_list _4 = RBRACE
    { ()}
| _1 = ENUM _2 = IDENTIFIER _3 = LBRACE _4 = enumerator_list _5 = RBRACE
    { ()}
| _1 = ENUM _2 = IDENTIFIER
    { ()}
403 404

enumerator_list:
405 406 407 408
| _1 = enumerator
    { ()}
| _1 = enumerator_list _2 = COMMA _3 = enumerator
    { ()}
409 410

enumerator:
411 412 413 414
| _1 = IDENTIFIER
    { ()}
| _1 = IDENTIFIER _2 = EQUAL _3 = constant_expression
    { ()}
415 416

type_qualifier:
417 418 419 420
| _1 = CONST
    { ()}
| _1 = VOLATILE
    { ()}
421 422

declarator:
423 424 425 426
| _1 = pointer _2 = direct_declarator
    { ()}
| _1 = direct_declarator
    { ()}
427 428

direct_declarator:
429 430 431 432 433 434 435 436 437 438 439 440 441 442
| _1 = IDENTIFIER
    { ()}
| _1 = LPAREN _2 = declarator _3 = RPAREN
    { ()}
| _1 = direct_declarator _2 = LBRACK _3 = constant_expression _4 = RBRACK
    { ()}
| _1 = direct_declarator _2 = LBRACK _3 = RBRACK
    { ()}
| _1 = direct_declarator _2 = LPAREN _3 = parameter_type_list _4 = RPAREN
    { ()}
| _1 = direct_declarator _2 = LPAREN _3 = identifier_list _4 = RPAREN
    { ()}
| _1 = direct_declarator _2 = LPAREN _3 = RPAREN
    { ()}
443 444

pointer:
445 446 447 448 449 450 451 452
| _1 = STAR
    { ()}
| _1 = STAR _2 = type_qualifier_list
    { ()}
| _1 = STAR _2 = pointer
    { ()}
| _1 = STAR _2 = type_qualifier_list _3 = pointer
    { ()}
453 454

type_qualifier_list:
455 456 457 458
| _1 = type_qualifier
    { ()}
| _1 = type_qualifier_list _2 = type_qualifier
    { ()}
459 460

parameter_type_list:
461 462 463 464
| _1 = parameter_list
    { ()}
| _1 = parameter_list _2 = COMMA _3 = ELLIPSIS
    { ()}
465 466

parameter_list:
467 468 469 470
| _1 = parameter_declaration
    { ()}
| _1 = parameter_list _2 = COMMA _3 = parameter_declaration
    { ()}
471 472

parameter_declaration:
473 474 475 476 477 478
| _1 = declaration_specifiers _2 = declarator
    { ()}
| _1 = declaration_specifiers _2 = abstract_declarator
    { ()}
| _1 = declaration_specifiers
    { ()}
479 480

identifier_list:
481 482 483 484
| _1 = IDENTIFIER
    { ()}
| _1 = identifier_list _2 = COMMA _3 = IDENTIFIER
    { ()}
485 486

type_name:
487 488 489 490
| _1 = specifier_qualifier_list
    { ()}
| _1 = specifier_qualifier_list _2 = abstract_declarator
    { ()}
491 492

abstract_declarator:
493 494 495 496 497 498
| _1 = pointer
    { ()}
| _1 = direct_abstract_declarator
    { ()}
| _1 = pointer _2 = direct_abstract_declarator
    { ()}
499 500

direct_abstract_declarator:
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
| _1 = LPAREN _2 = abstract_declarator _3 = RPAREN
    { ()}
| _1 = LBRACK _2 = RBRACK
    { ()}
| _1 = LBRACK _2 = constant_expression _3 = RBRACK
    { ()}
| _1 = direct_abstract_declarator _2 = LBRACK _3 = RBRACK
    { ()}
| _1 = direct_abstract_declarator _2 = LBRACK _3 = constant_expression _4 = RBRACK
    { ()}
| _1 = LPAREN _2 = RPAREN
    { ()}
| _1 = LPAREN _2 = parameter_type_list _3 = RPAREN
    { ()}
| _1 = direct_abstract_declarator _2 = LPAREN _3 = RPAREN
    { ()}
| _1 = direct_abstract_declarator _2 = LPAREN _3 = parameter_type_list _4 = RPAREN
    { ()}
519 520

c_initializer:
521 522 523 524 525 526
| _1 = assignment_expression
    { ()}
| _1 = LBRACE _2 = c_initializer_list _3 = RBRACE
    { ()}
| _1 = LBRACE _2 = c_initializer_list _3 = COMMA _4 = RBRACE
    { ()}
527 528

c_initializer_list:
529 530 531 532
| _1 = c_initializer
    { ()}
| _1 = c_initializer_list _2 = COMMA _3 = c_initializer
    { ()}
533 534

statement:
535 536 537 538 539 540 541 542 543 544 545 546
| _1 = labeled_statement
    { ()}
| _1 = compound_statement
    { ()}
| _1 = expression_statement
    { ()}
| _1 = selection_statement
    { ()}
| _1 = iteration_statement
    { ()}
| _1 = jump_statement
    { ()}
547 548

labeled_statement:
549 550 551 552 553 554
| _1 = IDENTIFIER _2 = COLON _3 = statement
    { ()}
| _1 = CASE _2 = constant_expression _3 = COLON _4 = statement
    { ()}
| _1 = DEFAULT _2 = COLON _3 = statement
    { ()}
555 556

compound_statement:
557 558 559 560 561 562 563 564
| _1 = LBRACE _2 = RBRACE
    { ()}
| _1 = LBRACE _2 = statement_list _3 = RBRACE
    { ()}
| _1 = LBRACE _2 = declaration_list _3 = RBRACE
    { ()}
| _1 = LBRACE _2 = declaration_list _3 = statement_list _4 = RBRACE
    { ()}
565 566

declaration_list:
567 568 569 570
| _1 = declaration
    { ()}
| _1 = declaration_list _2 = declaration
    { ()}
571 572

statement_list:
573 574 575 576
| _1 = statement
    { ()}
| _1 = statement_list _2 = statement
    { ()}
577 578

expression_statement:
579 580 581 582
| _1 = SEMICOLON
    { ()}
| _1 = expression _2 = SEMICOLON
    { ()}
583 584

selection_statement:
585 586 587 588 589 590
| _1 = IF _2 = LPAREN _3 = expression _4 = RPAREN _5 = statement
    { ()}
| _1 = IF _2 = LPAREN _3 = expression _4 = RPAREN _5 = statement _6 = ELSE _7 = statement
    { ()}
| _1 = SWITCH _2 = LPAREN _3 = expression _4 = RPAREN _5 = statement
    { ()}
591 592

iteration_statement:
593 594 595 596 597 598 599 600
| _1 = WHILE _2 = LPAREN _3 = expression _4 = RPAREN _5 = statement
    { ()}
| _1 = DO _2 = statement _3 = WHILE _4 = LPAREN _5 = expression _6 = RPAREN _7 = SEMICOLON
    { ()}
| _1 = FOR _2 = LPAREN _3 = expression_statement _4 = expression_statement _5 = RPAREN _6 = statement
    { ()}
| _1 = FOR _2 = LPAREN _3 = expression_statement _4 = expression_statement _5 = expression _6 = RPAREN _7 = statement
    { ()}
601 602

jump_statement:
603 604 605 606 607 608 609 610 611 612
| _1 = GOTO _2 = IDENTIFIER _3 = SEMICOLON
    { ()}
| _1 = CONTINUE _2 = SEMICOLON
    { ()}
| _1 = BREAK _2 = SEMICOLON
    { ()}
| _1 = RETURN _2 = SEMICOLON
    { ()}
| _1 = RETURN _2 = expression _3 = SEMICOLON
    { ()}
613 614

translation_unit:
615 616 617 618
| _1 = external_declaration
    { ()}
| _1 = translation_unit _2 = external_declaration
    { ()}
619 620

external_declaration:
621 622 623 624
| _1 = function_definition
    { ()}
| _1 = declaration
    { ()}
625 626

function_definition:
627 628 629 630 631 632 633 634
| _1 = declaration_specifiers _2 = declarator _3 = declaration_list _4 = compound_statement
    { ()}
| _1 = declaration_specifiers _2 = declarator _3 = compound_statement
    { ()}
| _1 = declarator _2 = declaration_list _3 = compound_statement
    { ()}
| _1 = declarator _2 = compound_statement
    { ()}
635 636 637 638 639

%%