Changes in src/Parser/parser.yy [68cd1ce:de62360d]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (96 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r68cd1ce rde62360d 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 13 07:21:45201513 // Update Count : 10 4812 // Last Modified On : Mon Jun 22 15:19:44 2015 13 // Update Count : 1082 14 14 // 15 15 16 // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on 17 // the C grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS. While 18 // parts have been copied, important changes have been made in all sections; these changes are sufficient to 19 // constitute a new grammar. In particular, this grammar attempts to be more syntactically precise, i.e., it 20 // parses less incorrect language syntax that must be subsequently rejected by semantic checks. Nevertheless, 21 // there are still several semantic checks required and many are noted in the grammar. Finally, the grammar is 22 // extended with GCC and CFA language extensions. 23 24 // Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got 25 // stuck with the grammar. 16 // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C 17 // grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS. While parts have been 18 // copied, important changes have been made in all sections; these changes are sufficient to constitute a new grammar. 19 // In particular, this grammar attempts to be more syntactically precise, i.e., it parses less incorrect language syntax 20 // that must be subsequently rejected by semantic checks. Nevertheless, there are still several semantic checks 21 // required and many are noted in the grammar. Finally, the grammar is extended with GCC and CFA language extensions. 22 23 // Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got stuck with 24 // the grammar. 26 25 27 26 // The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for: … … 29 28 // 1. designation with '=' (use ':' instead) 30 29 // 31 // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This 32 // grammar also hastwo levels of extensions. The first extensions cover most of the GCC C extensions, except for:30 // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has 31 // two levels of extensions. The first extensions cover most of the GCC C extensions, except for: 33 32 // 34 33 // 1. nested functions … … 37 36 // 4. attributes not allowed in parenthesis of declarator 38 37 // 39 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for 40 // Cforall (CFA), which fixes several of C's outstanding problems and extends C with many modern language41 // concepts. All of the syntactic extensions for CFA C are marked with the comment "CFA". As noted above,42 // there is one unreconcileable parsing problem between C99 and CFA with respect to designators; this is43 // discussed in detail before the "designation"grammar rule.38 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall 39 // (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the 40 // syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable 41 // parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation" 42 // grammar rule. 44 43 45 44 %{ … … 250 249 //************************* Namespace Management ******************************** 251 250 252 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal 253 // symbols "identifier" and "TYPEDEFname" that are lexically identical. While it is possible to write a 254 // purely context-free grammar, such a grammar would obscure the relationship between syntactic and semantic 255 // constructs. Hence, this grammar uses the ANSI style. 256 // 257 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, 258 // those introduced through "forall" qualifiers), and by introducing "type generators" -- parametrized types. 259 // This latter type name creates a third class of identifiers that must be distinguished by the scanner. 260 // 261 // Since the scanner cannot distinguish among the different classes of identifiers without some context 262 // information, it accesses a data structure (the TypedefTable) to allow classification of an identifier that 263 // it has just read. Semantic actions during the parser update this data structure when the class of 264 // identifiers change. 265 // 266 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its 267 // class in a local scope; it must revert to its original class at the end of the block. Since type names can 268 // be local to a particular declaration, each declaration is itself a scope. This requires distinguishing 269 // between type names that are local to the current declaration scope and those that persist past the end of 270 // the declaration (i.e., names defined in "typedef" or "type" declarations). 271 // 272 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and 273 // closing of scopes. Every push must have a matching pop, although it is regrettable the matching pairs do 274 // not always occur within the same rule. These non-terminals may appear in more contexts than strictly 275 // necessary from a semantic point of view. Unfortunately, these extra rules are necessary to prevent parsing 276 // conflicts -- the parser may not have enough context and look-ahead information to decide whether a new 277 // scope is necessary, so the effect of these extra rules is to open a new scope unconditionally. As the 278 // grammar evolves, it may be neccesary to add or move around "push" and "pop" nonterminals to resolve 279 // conflicts of this sort. 251 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols 252 // "identifier" and "TYPEDEFname" that are lexically identical. While it is possible to write a purely context-free 253 // grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. Hence, this 254 // grammar uses the ANSI style. 255 // 256 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those 257 // introduced through "forall" qualifiers), and by introducing "type generators" -- parametrized types. This latter 258 // type name creates a third class of identifiers that must be distinguished by the scanner. 259 // 260 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it 261 // accesses a data structure (the TypedefTable) to allow classification of an identifier that it has just read. 262 // Semantic actions during the parser update this data structure when the class of identifiers change. 263 // 264 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a 265 // local scope; it must revert to its original class at the end of the block. Since type names can be local to a 266 // particular declaration, each declaration is itself a scope. This requires distinguishing between type names that are 267 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in 268 // "typedef" or "type" declarations). 269 // 270 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of 271 // scopes. Every push must have a matching pop, although it is regrettable the matching pairs do not always occur 272 // within the same rule. These non-terminals may appear in more contexts than strictly necessary from a semantic point 273 // of view. Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have 274 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra 275 // rules is to open a new scope unconditionally. As the grammar evolves, it may be neccesary to add or move around 276 // "push" and "pop" nonterminals to resolve conflicts of this sort. 280 277 281 278 push: … … 294 291 295 292 constant: 296 // ENUMERATIONconstant is not included here; it is treated as a variable with type 297 // "enumeration constant". 293 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 298 294 INTEGERconstant { $$ = new ConstantNode( ConstantNode::Integer, $1 ); } 299 295 | FLOATINGconstant { $$ = new ConstantNode( ConstantNode::Float, $1 ); } … … 330 326 primary_expression: 331 327 IDENTIFIER // typedef name cannot be used as a variable name 332 { $$ = new VarRefNode( $1); }328 { $$ = new VarRefNode( $1 ); } 333 329 | zero_one 334 { $$ = new VarRefNode( $1); }330 { $$ = new VarRefNode( $1 ); } 335 331 | constant 336 332 { $$ = $1; } … … 340 336 { $$ = $2; } 341 337 | '(' compound_statement ')' // GCC, lambda expression 342 { $$ = new ValofExprNode( $2); }338 { $$ = new ValofExprNode( $2 ); } 343 339 ; 344 340 … … 346 342 primary_expression 347 343 | postfix_expression '[' push assignment_expression pop ']' 348 // CFA, comma_expression disallowed in the context because it results in a commom user error: 349 // subscripting a matrix with x[i,j] instead of x[i][j]. While this change is not backwards350 // compatible, there seems to be little advantage to this feature and many disadvantages. Itis351 // possible to write x[(i,j)] in CFA, which isequivalent to the old x[i,j].352 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Index), $1, $4); }344 // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a 345 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 346 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 347 // equivalent to the old x[i,j]. 348 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4 ); } 353 349 | postfix_expression '(' argument_expression_list ')' 354 { $$ = new CompositeExprNode( $1, $3); }350 { $$ = new CompositeExprNode( $1, $3 ); } 355 351 | postfix_expression '.' no_attr_identifier 356 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::FieldSel), $1, new VarRefNode($3)); }352 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3 )); } 357 353 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 358 354 | postfix_expression ARROW no_attr_identifier 359 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::PFieldSel), $1, new VarRefNode($3)); }355 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3 )); } 360 356 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 361 357 | postfix_expression ICR 362 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::IncrPost), $1); }358 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1 ); } 363 359 | postfix_expression DECR 364 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::DecrPost), $1); }360 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); } 365 361 // GCC has priority: cast_expression 366 362 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 … … 371 367 argument_expression 372 368 | argument_expression_list ',' argument_expression 373 { $$ = (ExpressionNode *)( $1->set_link($3)); }369 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 374 370 ; 375 371 … … 379 375 | assignment_expression 380 376 | no_attr_identifier ':' assignment_expression 381 { $$ = $3->set_asArgName( $1); }382 // Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there is 383 // insufficient look ahead to distinguish between this list of parameter names and a tuple, so the384 // tuple form must be usedwith an appropriate semantic check.377 { $$ = $3->set_asArgName( $1 ); } 378 // Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there is insufficient 379 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used 380 // with an appropriate semantic check. 385 381 | '[' push assignment_expression pop ']' ':' assignment_expression 386 { $$ = $7->set_asArgName( $3); }382 { $$ = $7->set_asArgName( $3 ); } 387 383 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 388 384 { $$ = $9->set_asArgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } … … 398 394 { $$ = new VarRefNode( $1 ); } 399 395 | no_attr_identifier '.' field 400 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); }396 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3 ); } 401 397 | no_attr_identifier '.' '[' push field_list pop ']' 402 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); }398 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5 ); } 403 399 | no_attr_identifier ARROW field 404 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); }400 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3 ); } 405 401 | no_attr_identifier ARROW '[' push field_list pop ']' 406 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); }402 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5 ); } 407 403 ; 408 404 … … 410 406 postfix_expression 411 407 | ICR unary_expression 412 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Incr), $2); }408 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } 413 409 | DECR unary_expression 414 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Decr), $2); }410 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); } 415 411 | EXTENSION cast_expression // GCC 416 412 { $$ = $2; } 417 413 | unary_operator cast_expression 418 { $$ = new CompositeExprNode( $1, $2); }414 { $$ = new CompositeExprNode( $1, $2 ); } 419 415 | '!' cast_expression 420 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Neg), $2); }416 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2 ); } 421 417 | '*' cast_expression // CFA 422 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::PointTo), $2); }418 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2 ); } 423 419 // '*' is is separated from unary_operator because of shift/reduce conflict in: 424 420 // { * X; } // dereference X … … 426 422 // '&' must be moved here if C++ reference variables are supported. 427 423 | SIZEOF unary_expression 428 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::SizeOf), $2); }424 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); } 429 425 | SIZEOF '(' type_name_no_function ')' 430 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::SizeOf), new TypeValueNode($3)); }426 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); } 431 427 | ATTR_IDENTIFIER 432 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Attr), new VarRefNode($1)); }428 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); } 433 429 | ATTR_IDENTIFIER '(' type_name ')' 434 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Attr), new VarRefNode($1), new TypeValueNode($3)); }430 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 )); } 435 431 | ATTR_IDENTIFIER '(' argument_expression ')' 436 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Attr), new VarRefNode($1), $3); }432 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); } 437 433 | ALIGNOF unary_expression // GCC, variable alignment 438 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::AlignOf), $2); }434 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2 ); } 439 435 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 440 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::AlignOf), new TypeValueNode($3)); }436 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 )); } 441 437 | ANDAND no_attr_identifier // GCC, address of label 442 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::LabelAddress), new VarRefNode($2, true)); }438 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true )); } 443 439 ; 444 440 445 441 unary_operator: 446 '&' { $$ = new OperatorNode( OperatorNode::AddressOf); }447 | '+' { $$ = new OperatorNode( OperatorNode::UnPlus); }448 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus); }449 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg); }442 '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); } 443 | '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 444 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); } 445 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); } 450 446 ; 451 447 … … 453 449 unary_expression 454 450 | '(' type_name_no_function ')' cast_expression 455 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); }451 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); } 456 452 | '(' type_name_no_function ')' tuple 457 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); }453 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); } 458 454 ; 459 455 … … 461 457 cast_expression 462 458 | multiplicative_expression '*' cast_expression 463 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Mul),$1,$3); }459 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3 ); } 464 460 | multiplicative_expression '/' cast_expression 465 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Div),$1,$3); }461 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3 ); } 466 462 | multiplicative_expression '%' cast_expression 467 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Mod),$1,$3); }463 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3 ); } 468 464 ; 469 465 … … 471 467 multiplicative_expression 472 468 | additive_expression '+' multiplicative_expression 473 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Plus),$1,$3); }469 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3 ); } 474 470 | additive_expression '-' multiplicative_expression 475 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Minus),$1,$3); }471 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3 ); } 476 472 ; 477 473 … … 479 475 additive_expression 480 476 | shift_expression LS additive_expression 481 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::LShift),$1,$3); }477 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3 ); } 482 478 | shift_expression RS additive_expression 483 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::RShift),$1,$3); }479 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3 ); } 484 480 ; 485 481 … … 487 483 shift_expression 488 484 | relational_expression '<' shift_expression 489 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::LThan),$1,$3); }485 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3 ); } 490 486 | relational_expression '>' shift_expression 491 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::GThan),$1,$3); }487 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3 ); } 492 488 | relational_expression LE shift_expression 493 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::LEThan),$1,$3); }489 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3 ); } 494 490 | relational_expression GE shift_expression 495 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::GEThan),$1,$3); }491 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3 ); } 496 492 ; 497 493 … … 499 495 relational_expression 500 496 | equality_expression EQ relational_expression 501 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Eq), $1, $3); }497 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3 ); } 502 498 | equality_expression NE relational_expression 503 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Neq), $1, $3); }499 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3 ); } 504 500 ; 505 501 … … 507 503 equality_expression 508 504 | AND_expression '&' equality_expression 509 { $$ =new CompositeExprNode( new OperatorNode(OperatorNode::BitAnd), $1, $3); }505 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3 ); } 510 506 ; 511 507 … … 513 509 AND_expression 514 510 | exclusive_OR_expression '^' AND_expression 515 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Xor), $1, $3); }511 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3 ); } 516 512 ; 517 513 … … 519 515 exclusive_OR_expression 520 516 | inclusive_OR_expression '|' exclusive_OR_expression 521 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::BitOr), $1, $3); }517 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3 ); } 522 518 ; 523 519 … … 525 521 inclusive_OR_expression 526 522 | logical_AND_expression ANDAND inclusive_OR_expression 527 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::And), $1, $3); }523 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3 ); } 528 524 ; 529 525 … … 531 527 logical_AND_expression 532 528 | logical_OR_expression OROR logical_AND_expression 533 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Or), $1, $3); }529 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3 ); } 534 530 ; 535 531 … … 537 533 logical_OR_expression 538 534 | logical_OR_expression '?' comma_expression ':' conditional_expression 539 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); }535 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); } 540 536 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 541 { $$=new CompositeExprNode( new OperatorNode(OperatorNode::NCond),$1,$4); }537 { $$=new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); } 542 538 | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression 543 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); }539 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); } 544 540 ; 545 541 … … 552 548 conditional_expression 553 549 | unary_expression '=' assignment_expression 554 { $$ =new CompositeExprNode( new OperatorNode(OperatorNode::Assign), $1, $3); }550 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); } 555 551 | unary_expression assignment_operator assignment_expression 556 { $$ =new CompositeExprNode( $2, $1, $3); }552 { $$ =new CompositeExprNode( $2, $1, $3 ); } 557 553 | tuple assignment_opt // CFA, tuple expression 558 { $$ = ( $2 == 0) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); }554 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); } 559 555 ; 560 556 … … 566 562 567 563 tuple: // CFA, tuple 568 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce 569 // co nflict with comma_expression in new_identifier_parameter_array and new_abstract_array564 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with 565 // comma_expression in new_identifier_parameter_array and new_abstract_array 570 566 '[' push pop ']' 571 567 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); } … … 585 581 586 582 assignment_operator: 587 MULTassign { $$ = new OperatorNode( OperatorNode::MulAssn); }588 | DIVassign { $$ = new OperatorNode( OperatorNode::DivAssn); }589 | MODassign { $$ = new OperatorNode( OperatorNode::ModAssn); }590 | PLUSassign { $$ = new OperatorNode( OperatorNode::PlusAssn); }591 | MINUSassign { $$ = new OperatorNode( OperatorNode::MinusAssn); }592 | LSassign { $$ = new OperatorNode( OperatorNode::LSAssn); }593 | RSassign { $$ = new OperatorNode( OperatorNode::RSAssn); }594 | ANDassign { $$ = new OperatorNode( OperatorNode::AndAssn); }595 | ERassign { $$ = new OperatorNode( OperatorNode::ERAssn); }596 | ORassign { $$ = new OperatorNode( OperatorNode::OrAssn); }583 MULTassign { $$ = new OperatorNode( OperatorNode::MulAssn ); } 584 | DIVassign { $$ = new OperatorNode( OperatorNode::DivAssn ); } 585 | MODassign { $$ = new OperatorNode( OperatorNode::ModAssn ); } 586 | PLUSassign { $$ = new OperatorNode( OperatorNode::PlusAssn ); } 587 | MINUSassign { $$ = new OperatorNode( OperatorNode::MinusAssn ); } 588 | LSassign { $$ = new OperatorNode( OperatorNode::LSAssn ); } 589 | RSassign { $$ = new OperatorNode( OperatorNode::RSAssn ); } 590 | ANDassign { $$ = new OperatorNode( OperatorNode::AndAssn ); } 591 | ERassign { $$ = new OperatorNode( OperatorNode::ERAssn ); } 592 | ORassign { $$ = new OperatorNode( OperatorNode::OrAssn ); } 597 593 ; 598 594 599 595 comma_expression: 600 596 assignment_expression 601 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3); }602 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Comma),$1,$3); }597 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); } 598 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3 ); } 603 599 ; 604 600 … … 624 620 labeled_statement: 625 621 no_attr_identifier ':' attribute_list_opt statement 626 { $$ = $4->add_label( $1);}622 { $$ = $4->add_label( $1 );} 627 623 ; 628 624 … … 631 627 { $$ = new CompoundStmtNode( (StatementNode *)0 ); } 632 628 | '{' 633 // Two scopes are necessary because the block itself has a scope, but every declaration within the 634 // block alsorequires its own scope629 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also 630 // requires its own scope 635 631 push push 636 632 label_declaration_opt // GCC, local labels … … 642 638 block_item 643 639 | block_item_list push block_item 644 { if ( $1 != 0) { $1->set_link($3); $$ = $1; } }640 { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } } 645 641 ; 646 642 … … 658 654 statement 659 655 | statement_list statement 660 { if ( $1 != 0) { $1->set_link($2); $$ = $1; } }656 { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } } 661 657 ; 662 658 663 659 expression_statement: 664 660 comma_expression_opt ';' 665 { $$ = new StatementNode( StatementNode::Exp, $1, 0); }661 { $$ = new StatementNode( StatementNode::Exp, $1, 0 ); } 666 662 ; 667 663 … … 669 665 IF '(' comma_expression ')' statement %prec THEN 670 666 // explicitly deal with the shift/reduce conflict on if/else 671 { $$ = new StatementNode( StatementNode::If, $3, $5); }667 { $$ = new StatementNode( StatementNode::If, $3, $5 ); } 672 668 | IF '(' comma_expression ')' statement ELSE statement 673 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7)) ); }669 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7 )) ); } 674 670 | SWITCH '(' comma_expression ')' case_clause // CFA 675 { $$ = new StatementNode( StatementNode::Switch, $3, $5); }671 { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); } 676 672 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 677 { $$ = new StatementNode(StatementNode::Switch, $3, $8); /* xxx */ } 678 // The semantics of the declaration list is changed to include any associated initialization, which is 679 // performed *before* the transfer to the appropriate case clause. Statements after the initial 680 // declaration list can never be executed, and therefore, are removed from the grammar even though C 681 // allows it. 673 { $$ = new StatementNode( StatementNode::Switch, $3, $8 ); /* xxx */ } 674 // The semantics of the declaration list is changed to include any associated initialization, which is performed 675 // *before* the transfer to the appropriate case clause. Statements after the initial declaration list can 676 // never be executed, and therefore, are removed from the grammar even though C allows it. 682 677 | CHOOSE '(' comma_expression ')' case_clause // CFA 683 { $$ = new StatementNode( StatementNode::Choose, $3, $5); }678 { $$ = new StatementNode( StatementNode::Choose, $3, $5 ); } 684 679 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 685 { $$ = new StatementNode( StatementNode::Choose, $3, $8); }686 ; 687 688 // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a 689 // c ase clause allows a list of values and subranges.680 { $$ = new StatementNode( StatementNode::Choose, $3, $8 ); } 681 ; 682 683 // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case 684 // clause allows a list of values and subranges. 690 685 691 686 case_value: // CFA 692 687 constant_expression { $$ = $1; } 693 688 | constant_expression ELLIPSIS constant_expression // GCC, subrange 694 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Range),$1,$3); }689 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); } 695 690 | subrange // CFA, subrange 696 691 ; … … 699 694 case_value 700 695 | case_value_list ',' case_value 701 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents($1))->set_link($3) ); }696 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3 ) ); } 702 697 ; 703 698 704 699 case_label: // CFA 705 CASE case_value_list ':' { $$ = new StatementNode( StatementNode::Case, $2, 0); }706 | DEFAULT ':' { $$ = new StatementNode( StatementNode::Default); }700 CASE case_value_list ':' { $$ = new StatementNode( StatementNode::Case, $2, 0 ); } 701 | DEFAULT ':' { $$ = new StatementNode( StatementNode::Default ); } 707 702 // A semantic check is required to ensure only one default clause per switch/choose statement. 708 703 ; … … 710 705 case_label_list: // CFA 711 706 case_label 712 | case_label_list case_label { $$ = (StatementNode *)( $1->set_link($2)); }707 | case_label_list case_label { $$ = (StatementNode *)( $1->set_link( $2 )); } 713 708 ; 714 709 715 710 case_clause: // CFA 716 case_label_list statement { $$ = $1->append_last_case( $2); }711 case_label_list statement { $$ = $1->append_last_case( $2 ); } 717 712 ; 718 713 … … 725 720 switch_clause_list: // CFA 726 721 case_label_list statement_list 727 { $$ = $1->append_last_case( $2); }722 { $$ = $1->append_last_case( $2 ); } 728 723 | switch_clause_list case_label_list statement_list 729 { $$ = (StatementNode *)( $1->set_link($2->append_last_case($3))); }724 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); } 730 725 ; 731 726 … … 738 733 choose_clause_list: // CFA 739 734 case_label_list fall_through 740 { $$ = $1->append_last_case( $2); }735 { $$ = $1->append_last_case( $2 ); } 741 736 | case_label_list statement_list fall_through_opt 742 { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3 ))); }737 { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3 ))); } 743 738 | choose_clause_list case_label_list fall_through 744 { $$ = (StatementNode *)( $1->set_link($2->append_last_case($3))); }739 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); } 745 740 | choose_clause_list case_label_list statement_list fall_through_opt 746 { $$ = (StatementNode *)( $1->set_link($2->append_last_case((StatementNode *)mkList((*$3,*$4))))); }741 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case((StatementNode *)mkList((*$3,*$4 ))))); } 747 742 ; 748 743 … … 754 749 755 750 fall_through: // CFA 756 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru, 0, 0); }757 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru, 0, 0); }751 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); } 752 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru, 0, 0 ); } 758 753 ; 759 754 760 755 iteration_statement: 761 756 WHILE '(' comma_expression ')' statement 762 { $$ = new StatementNode( StatementNode::While, $3, $5); }757 { $$ = new StatementNode( StatementNode::While, $3, $5 ); } 763 758 | DO statement WHILE '(' comma_expression ')' ';' 764 { $$ = new StatementNode( StatementNode::Do, $5, $2); }759 { $$ = new StatementNode( StatementNode::Do, $5, $2 ); } 765 760 | FOR '(' push for_control_expression ')' statement 766 { $$ = new StatementNode( StatementNode::For, $4, $6); }761 { $$ = new StatementNode( StatementNode::For, $4, $6 ); } 767 762 ; 768 763 769 764 for_control_expression: 770 765 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 771 { $$ = new ForCtlExprNode( $1, $4, $6); }766 { $$ = new ForCtlExprNode( $1, $4, $6 ); } 772 767 | declaration comma_expression_opt ';' comma_expression_opt // C99 773 { $$ = new ForCtlExprNode( $1, $2, $4); }768 { $$ = new ForCtlExprNode( $1, $2, $4 ); } 774 769 ; 775 770 776 771 jump_statement: 777 772 GOTO no_attr_identifier ';' 778 { $$ = new StatementNode( StatementNode::Goto, $2); }773 { $$ = new StatementNode( StatementNode::Goto, $2 ); } 779 774 | GOTO '*' comma_expression ';' // GCC, computed goto 780 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => 781 // goto *(i+3);whereas normal operator precedence yields goto (*i)+3;782 { $$ = new StatementNode( StatementNode::Goto, $3); }775 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3 ); 776 // whereas normal operator precedence yields goto (*i)+3; 777 { $$ = new StatementNode( StatementNode::Goto, $3 ); } 783 778 | CONTINUE ';' 784 // A semantic check is required to ensure this statement appears only in the body of an iteration 785 // statement. 786 { $$ = new StatementNode(StatementNode::Continue, 0, 0); } 779 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 780 { $$ = new StatementNode( StatementNode::Continue, 0, 0 ); } 787 781 | CONTINUE no_attr_identifier ';' // CFA, multi-level continue 788 // A semantic check is required to ensure this statement appears only in the body of an iteration 789 // statement, andthe target of the transfer appears only at the start of an iteration statement.790 { $$ = new StatementNode( StatementNode::Continue, $2); }782 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 783 // the target of the transfer appears only at the start of an iteration statement. 784 { $$ = new StatementNode( StatementNode::Continue, $2 ); } 791 785 | BREAK ';' 792 // A semantic check is required to ensure this statement appears only in the body of an iteration 793 // statement. 794 { $$ = new StatementNode(StatementNode::Break, 0, 0); } 786 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 787 { $$ = new StatementNode( StatementNode::Break, 0, 0 ); } 795 788 | BREAK no_attr_identifier ';' // CFA, multi-level exit 796 // A semantic check is required to ensure this statement appears only in the body of an iteration 797 // statement, andthe target of the transfer appears only at the start of an iteration statement.798 { $$ = new StatementNode( StatementNode::Break, $2 ); }789 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 790 // the target of the transfer appears only at the start of an iteration statement. 791 { $$ = new StatementNode( StatementNode::Break, $2 ); } 799 792 | RETURN comma_expression_opt ';' 800 { $$ = new StatementNode( StatementNode::Return, $2, 0); }793 { $$ = new StatementNode( StatementNode::Return, $2, 0 ); } 801 794 | THROW assignment_expression ';' 802 { $$ = new StatementNode( StatementNode::Throw, $2, 0); }795 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 803 796 | THROW ';' 804 { $$ = new StatementNode( StatementNode::Throw, 0, 0); }797 { $$ = new StatementNode( StatementNode::Throw, 0, 0 ); } 805 798 ; 806 799 807 800 exception_statement: 808 801 TRY compound_statement handler_list 809 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); }802 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 810 803 | TRY compound_statement finally_clause 811 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); }804 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 812 805 | TRY compound_statement handler_list finally_clause 813 806 { 814 $3->set_link( $4);815 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3))));807 $3->set_link( $4 ); 808 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); 816 809 } 817 810 ; … … 820 813 // There must be at least one catch clause 821 814 handler_clause 822 // ISO/IEC 9899:1999 Section 15.3(6) If present, a "..." handler shall be the last handler for its try 823 // block. 815 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 824 816 | CATCH '(' ELLIPSIS ')' compound_statement 825 817 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } … … 830 822 handler_clause: 831 823 CATCH '(' push push exception_declaration pop ')' compound_statement pop 832 { $$ = StatementNode::newCatchStmt( $5, $8); }824 { $$ = StatementNode::newCatchStmt( $5, $8 ); } 833 825 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 834 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9) ); }826 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); } 835 827 ; 836 828 … … 838 830 FINALLY compound_statement 839 831 { 840 $$ = new StatementNode( StatementNode::Finally, 0, $2);832 $$ = new StatementNode( StatementNode::Finally, 0, $2 ); 841 833 std::cout << "Just created a finally node" << std::endl; 842 834 } … … 867 859 asm_statement: 868 860 ASM type_qualifier_list_opt '(' constant_expression ')' ';' 869 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }861 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 870 862 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ')' ';' // remaining GCC 871 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }863 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 872 864 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ')' ';' 873 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }865 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 874 866 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list ')' ';' 875 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }867 { $$ = new StatementNode( StatementNode::Asm, 0, 0 ); } 876 868 ; 877 869 … … 941 933 ; 942 934 943 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and 944 // function declarations. CFA declarations use the same declaration tokens as in C; however, CFA places 945 // declaration modifiers to the left of the base type, while C declarations place modifiers to the right of 946 // the base type. CFA declaration modifiers are interpreted from left to right and the entire type 947 // specification is distributed across all variables in the declaration list (as in Pascal). ANSI C and the 948 // new CFA declarations may appear together in the same program block, but cannot be mixed within a specific 949 // declaration. 935 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function 936 // declarations. CFA declarations use the same declaration tokens as in C; however, CFA places declaration modifiers to 937 // the left of the base type, while C declarations place modifiers to the right of the base type. CFA declaration 938 // modifiers are interpreted from left to right and the entire type specification is distributed across all variables in 939 // the declaration list (as in Pascal). ANSI C and the new CFA declarations may appear together in the same program 940 // block, but cannot be mixed within a specific declaration. 950 941 // 951 942 // CFA C … … 968 959 } 969 960 | declaration_qualifier_list new_variable_specifier initializer_opt 970 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to 971 // precludethem as a type_qualifier cannot appear in that context.961 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 962 // them as a type_qualifier cannot appear in that context. 972 963 { 973 964 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 982 973 983 974 new_variable_specifier: // CFA 984 // A semantic check is required to ensure asm_name only appears on declarations with implicit or 985 // explicit staticstorage-class975 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 976 // storage-class 986 977 new_abstract_declarator_no_tuple identifier_or_typedef_name asm_name_opt 987 978 { … … 1032 1023 '[' push pop ']' identifier '(' push new_parameter_type_list_opt pop ')' 1033 1024 { 1034 typedefTable.setNextIdentifier( *( $5) );1025 typedefTable.setNextIdentifier( *( $5 ) ); 1035 1026 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1036 1027 } 1037 1028 | '[' push pop ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')' 1038 1029 { 1039 typedefTable.setNextIdentifier( *( $5) );1030 typedefTable.setNextIdentifier( *( $5 ) ); 1040 1031 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1041 1032 } … … 1045 1036 // '[' ']' type_specifier 1046 1037 // 1047 // type_specifier can resolve to just TYPEDEFname (e.g. typedef int T; int f( T );). Therefore this 1048 // must be flattened to allow lookahead to the '(' without having to reduce 1049 // identifier_or_typedef_name. 1038 // type_specifier can resolve to just TYPEDEFname (e.g. typedef int T; int f( T );). Therefore this must be 1039 // flattened to allow lookahead to the '(' without having to reduce identifier_or_typedef_name. 1050 1040 | new_abstract_tuple identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')' 1051 // To obtain LR(1), this rule must be factored out from function return type (see 1052 // new_abstract_declarator). 1041 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator). 1053 1042 { 1054 1043 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); … … 1064 1053 { $$ = DeclarationNode::newTuple( $3 ); } 1065 1054 | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']' 1066 // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to1067 // lookahead to the']'.1055 // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the 1056 // ']'. 1068 1057 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1069 1058 ; … … 1072 1061 TYPEDEF new_variable_specifier 1073 1062 { 1074 typedefTable.addToEnclosingScope( TypedefTable::TD );1063 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1075 1064 $$ = $2->addTypedef(); 1076 1065 } 1077 1066 | TYPEDEF new_function_specifier 1078 1067 { 1079 typedefTable.addToEnclosingScope( TypedefTable::TD );1068 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1080 1069 $$ = $2->addTypedef(); 1081 1070 } 1082 1071 | new_typedef_declaration pop ',' push no_attr_identifier 1083 1072 { 1084 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );1073 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1085 1074 $$ = $1->appendList( $1->cloneType( $5 ) ); 1086 1075 } 1087 1076 ; 1088 1077 1089 // Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is 1090 // factored out as a separate form of declaration, which syntactically precludes storage-class specifiers and 1091 // initialization. 1078 // Traditionally typedef is part of storage-class specifier for syntactic convenience only. Here, it is factored out as 1079 // a separate form of declaration, which syntactically precludes storage-class specifiers and initialization. 1092 1080 1093 1081 typedef_declaration: 1094 1082 TYPEDEF type_specifier declarator 1095 1083 { 1096 typedefTable.addToEnclosingScope( TypedefTable::TD );1084 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1097 1085 $$ = $3->addType( $2 )->addTypedef(); 1098 1086 } 1099 1087 | typedef_declaration pop ',' push declarator 1100 1088 { 1101 typedefTable.addToEnclosingScope( TypedefTable::TD );1089 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1102 1090 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1103 1091 } 1104 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )1105 { 1106 typedefTable.addToEnclosingScope( TypedefTable::TD );1092 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1093 { 1094 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1107 1095 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1108 1096 } 1109 1097 | type_specifier TYPEDEF declarator 1110 1098 { 1111 typedefTable.addToEnclosingScope( TypedefTable::TD );1099 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1112 1100 $$ = $3->addType( $1 )->addTypedef(); 1113 1101 } 1114 1102 | type_specifier TYPEDEF type_qualifier_list declarator 1115 1103 { 1116 typedefTable.addToEnclosingScope( TypedefTable::TD );1117 $$ = $4->addQualifiers( $1)->addTypedef()->addType($1);1104 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1105 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1118 1106 } 1119 1107 ; … … 1122 1110 TYPEDEF no_attr_identifier '=' assignment_expression 1123 1111 { 1124 typedefTable.addToEnclosingScope( *($2), TypedefTable::TD);1112 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); 1125 1113 $$ = DeclarationNode::newName( 0 ); // XXX 1126 1114 } 1127 1115 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1128 1116 { 1129 typedefTable.addToEnclosingScope( *($5), TypedefTable::TD);1117 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1130 1118 $$ = DeclarationNode::newName( 0 ); // XXX 1131 1119 } … … 1140 1128 1141 1129 declaring_list: 1142 // A semantic check is required to ensure asm_name only appears on declarations with implicit or 1143 // explicit staticstorage-class1130 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1131 // storage-class 1144 1132 declaration_specifier declarator asm_name_opt initializer_opt 1145 1133 { 1146 1134 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1147 $$ = ( $2->addType( $1 ))->addInitializer($4);1135 $$ = ( $2->addType( $1 ))->addInitializer( $4 ); 1148 1136 } 1149 1137 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1150 1138 { 1151 1139 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1152 $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer( $6) ) );1140 $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer( $6 ) ) ); 1153 1141 } 1154 1142 ; … … 1175 1163 1176 1164 type_qualifier_list: 1177 // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of 1178 // declaration. 1165 // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration. 1179 1166 // 1180 // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same1181 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as 1182 // if itappeared only once.1167 // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same 1168 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it 1169 // appeared only once. 1183 1170 type_qualifier 1184 1171 | type_qualifier_list type_qualifier … … 1216 1203 declaration_qualifier_list: 1217 1204 storage_class_list 1218 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2 )1205 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2 ) 1219 1206 { $$ = $1->addQualifiers( $2 ); } 1220 1207 | declaration_qualifier_list type_qualifier_list storage_class_list … … 1223 1210 1224 1211 storage_class_list: 1225 // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration 1226 // and thatonly one of each is specified, except for inline, which can appear with the others.1212 // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that 1213 // only one of each is specified, except for inline, which can appear with the others. 1227 1214 // 1228 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the 1229 // declarationspecifiers in a declaration.1215 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration 1216 // specifiers in a declaration. 1230 1217 storage_class 1231 1218 | storage_class_list storage_class … … 1381 1368 | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1382 1369 { $$ = DeclarationNode::newAggregate( $1, 0, $4, $8, $11 ); } 1370 | aggregate_key TYPEGENname '(' type_name_list ')' // CFA 1371 {} 1383 1372 | aggregate_key '(' push type_name_list pop ')' no_attr_identifier_or_typedef_name // CFA 1384 1373 // push and pop are only to prevent S/R conflicts … … 1501 1490 1502 1491 new_parameter_list: // CFA 1503 // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last 1504 // new_abstract_parameter_list is factored out from new_parameter_list, flattening the rules to get 1505 // lookahead to the ']'. 1492 // To obtain LR(1) between new_parameter_list and new_abstract_tuple, the last new_abstract_parameter_list is 1493 // factored out from new_parameter_list, flattening the rules to get lookahead to the ']'. 1506 1494 new_parameter_declaration 1507 1495 | new_abstract_parameter_list pop ',' push new_parameter_declaration … … 1540 1528 ; 1541 1529 1542 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different 1543 // semantics for typedef name by using typedef_parameter_redeclarator instead of typedef_redeclarator, and 1544 // function prototypes. 1530 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics 1531 // for typedef name by using typedef_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. 1545 1532 1546 1533 new_parameter_declaration: // CFA, new & old style parameter declaration … … 1570 1557 { 1571 1558 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1572 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3) );1559 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); 1573 1560 } 1574 1561 | declaration_specifier typedef_parameter_redeclarator assignment_opt 1575 1562 { 1576 1563 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1577 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3) );1564 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); 1578 1565 } 1579 1566 ; … … 1586 1573 1587 1574 // ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a 1588 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is 1589 // based only onidentifiers. The ANSI-style parameter-list can redefine a typedef name.1575 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on 1576 // identifiers. The ANSI-style parameter-list can redefine a typedef name. 1590 1577 1591 1578 identifier_list: // K&R-style parameter list => no types … … 1611 1598 no_attr_identifier 1612 1599 | TYPEDEFname 1613 | TYPEGENname1600 // | TYPEGENname 1614 1601 ; 1615 1602 … … 1636 1623 1637 1624 initializer: 1638 assignment_expression { $$ = new InitializerNode( $1); }1639 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode( $2, true); }1625 assignment_expression { $$ = new InitializerNode( $1 ); } 1626 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode( $2, true ); } 1640 1627 ; 1641 1628 … … 1643 1630 initializer 1644 1631 | designation initializer { $$ = $2->set_designators( $1 ); } 1645 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link( $3) ); }1632 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link( $3 ) ); } 1646 1633 | initializer_list ',' designation initializer 1647 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3) ) ); }1648 ; 1649 1650 // There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is 1651 // use of'=' to separator the designator from the initializer value, as in:1634 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); } 1635 ; 1636 1637 // There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem is use of 1638 // '=' to separator the designator from the initializer value, as in: 1652 1639 // 1653 1640 // int x[10] = { [1] = 3 }; 1654 1641 // 1655 // The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment. To disambiguate this 1656 // c ase, CFA changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC1657 // does uses ":" for field selection. The optional use of the "=" in GCC, or in this case ":", cannot be1658 // s upported either due to shift/reduce conflicts1642 // The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment. To disambiguate this case, CFA 1643 // changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for 1644 // field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to 1645 // shift/reduce conflicts 1659 1646 1660 1647 designation: … … 1666 1653 designator_list: // C99 1667 1654 designator 1668 | designator_list designator { $$ = (ExpressionNode *)($1->set_link( $2 )); } 1655 | designator_list designator { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1656 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); } 1669 1657 ; 1670 1658 … … 1673 1661 { $$ = new VarRefNode( $2 ); } 1674 1662 | '[' push assignment_expression pop ']' // C99, single array element 1675 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with 1676 // tuple. 1663 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1677 1664 { $$ = $3; } 1678 1665 | '[' push subrange pop ']' // CFA, multiple array elements 1679 1666 { $$ = $3; } 1680 1667 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1681 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Range), $3, $5); }1668 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ); } 1682 1669 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1683 1670 { $$ = $4; } 1684 1671 ; 1685 1672 1686 // The CFA type system is based on parametric polymorphism, the ability to declare functions with type 1687 // parameters,rather than an object-oriented type system. This required four groups of extensions:1673 // The CFA type system is based on parametric polymorphism, the ability to declare functions with type parameters, 1674 // rather than an object-oriented type system. This required four groups of extensions: 1688 1675 // 1689 1676 // Overloading: function, data, and operator identifiers may be overloaded. 1690 1677 // 1691 // Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used 1692 // for object and incomplete types, and "ftype" is used for function types. Type declarations with 1693 // initializers provide definitions of new types. Type declarations with storage class "extern" provide 1694 // opaque types. 1695 // 1696 // Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at 1697 // the call site. A polymorphic function is not a template; it is a function, with an address and a type. 1678 // Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object 1679 // and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide 1680 // definitions of new types. Type declarations with storage class "extern" provide opaque types. 1681 // 1682 // Polymorphic functions: A forall clause declares a type parameter. The corresponding argument is inferred at the call 1683 // site. A polymorphic function is not a template; it is a function, with an address and a type. 1698 1684 // 1699 1685 // Specifications and Assertions: Specifications are collections of declarations parameterized by one or more 1700 // types. They serve many of the purposes of abstract classes, and specification hierarchies resemble 1701 // subclass hierarchies. Unlike classes, they can define relationships between types. Assertions declare1702 // t hat a type or types provide the operations declared by a specification. Assertions are normally used1703 // to declare requirementson type arguments of polymorphic functions.1686 // types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass 1687 // hierarchies. Unlike classes, they can define relationships between types. Assertions declare that a type or 1688 // types provide the operations declared by a specification. Assertions are normally used to declare requirements 1689 // on type arguments of polymorphic functions. 1704 1690 1705 1691 typegen_declaration_specifier: // CFA … … 1730 1716 type_parameter: // CFA 1731 1717 type_class no_attr_identifier_or_typedef_name 1732 { typedefTable.addToEnclosingScope(*( $2), TypedefTable::TD); }1718 { typedefTable.addToEnclosingScope(*( $2 ), TypedefTable::TD ); } 1733 1719 assertion_list_opt 1734 1720 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); } … … 1755 1741 '|' no_attr_identifier_or_typedef_name '(' type_name_list ')' 1756 1742 { 1757 typedefTable.openContext( *( $2) );1743 typedefTable.openContext( *( $2 ) ); 1758 1744 $$ = DeclarationNode::newContextUse( $2, $4 ); 1759 1745 } … … 1769 1755 | assignment_expression 1770 1756 | type_name_list ',' type_name 1771 { $$ = (ExpressionNode *)( $1->set_link(new TypeValueNode( $3 ))); }1757 { $$ = (ExpressionNode *)( $1->set_link( new TypeValueNode( $3 ))); } 1772 1758 | type_name_list ',' assignment_expression 1773 { $$ = (ExpressionNode *)( $1->set_link($3)); }1759 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 1774 1760 ; 1775 1761 … … 1793 1779 no_attr_identifier_or_typedef_name 1794 1780 { 1795 typedefTable.addToEnclosingScope( *($1), TypedefTable::TD);1781 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD ); 1796 1782 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 1797 1783 } 1798 1784 | no_01_identifier_or_typedef_name '(' push type_parameter_list pop ')' 1799 1785 { 1800 typedefTable.addToEnclosingScope( *($1), TypedefTable::TG);1786 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); 1801 1787 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 1802 1788 } … … 1806 1792 CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' '}' 1807 1793 { 1808 typedefTable.addToEnclosingScope( *($2), TypedefTable::ID );1794 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 1809 1795 $$ = DeclarationNode::newContext( $2, $5, 0 ); 1810 1796 } 1811 1797 | CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' 1812 1798 { 1813 typedefTable.enterContext( * ($2));1799 typedefTable.enterContext( *$2 ); 1814 1800 typedefTable.enterScope(); 1815 1801 } … … 1817 1803 { 1818 1804 typedefTable.leaveContext(); 1819 typedefTable.addToEnclosingScope( *($2), TypedefTable::ID );1805 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 1820 1806 $$ = DeclarationNode::newContext( $2, $5, $10 ); 1821 1807 } … … 1846 1832 | new_context_declaring_list pop ',' push identifier_or_typedef_name 1847 1833 { 1848 typedefTable.addToEnclosingScope2( * ($5), TypedefTable::ID );1834 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); 1849 1835 $$ = $1->appendList( $1->cloneType( $5 ) ); 1850 1836 } … … 1882 1868 external_definition 1883 1869 | external_definition_list push external_definition 1884 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }1870 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; } 1885 1871 ; 1886 1872 … … 1914 1900 function_definition 1915 1901 1916 // These rules are a concession to the "implicit int" type_specifier because there is a significant 1917 // amount of code with functions missing a type-specifier on the return type. Parsing is possible 1918 // because function_definition does not appear in the context of an expression (nested functions would 1919 // preclude this concession). A function prototype declaration must still have a type_specifier. 1920 // OBSOLESCENT (see 1) 1902 // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of 1903 // code with functions missing a type-specifier on the return type. Parsing is possible because 1904 // function_definition does not appear in the context of an expression (nested functions would preclude this 1905 // concession). A function prototype declaration must still have a type_specifier. OBSOLESCENT (see 1) 1921 1906 | function_declarator compound_statement 1922 1907 { … … 2002 1987 subrange: 2003 1988 constant_expression '~' constant_expression // CFA, integer subrange 2004 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Range), $1, $3); }1989 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); } 2005 1990 ; 2006 1991 … … 2043 2028 2044 2029 // ============================================================================ 2045 // The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are 2046 // necessary because the type of an identifier in wrapped around the identifier in the same form as its usage2047 // in an expression, as in:2030 // The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary 2031 // because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as 2032 // in: 2048 2033 // 2049 2034 // int (*f())[10] { ... }; 2050 2035 // ... (*f())[3] += 1; // definition mimics usage 2051 2036 // 2052 // Because these patterns are highly recursive, changes at a lower level in the recursion require copying some 2053 // or all of the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a 2054 // particular context. 2037 // Because these patterns are highly recursive, changes at a lower level in the recursion require copying some or all of 2038 // the pattern. Each of these patterns has some subtle variation to ensure correct syntax in a particular context. 2055 2039 // ============================================================================ 2056 2040 2057 2041 // ---------------------------------------------------------------------------- 2058 // The set of valid declarators before a compound statement for defining a function is less than the set of 2059 // declaratorsto define a variable or function prototype, e.g.:2042 // The set of valid declarators before a compound statement for defining a function is less than the set of declarators 2043 // to define a variable or function prototype, e.g.: 2060 2044 // 2061 2045 // valid declaration invalid definition … … 2066 2050 // int (*f)(int); int (*f)(int) {} 2067 2051 // 2068 // To preclude this syntactic anomaly requires separating the grammar rules for variable and function 2069 // declarators, hencevariable_declarator and function_declarator.2052 // To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence 2053 // variable_declarator and function_declarator. 2070 2054 // ---------------------------------------------------------------------------- 2071 2055 2072 // This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern 2073 // precludesdeclaring an array of functions versus a pointer to an array of functions.2056 // This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes 2057 // declaring an array of functions versus a pointer to an array of functions. 2074 2058 2075 2059 variable_declarator: … … 2083 2067 identifier 2084 2068 { 2085 typedefTable.setNextIdentifier( * ($1));2069 typedefTable.setNextIdentifier( *$1 ); 2086 2070 $$ = DeclarationNode::newName( $1 ); 2087 2071 } … … 2117 2101 ; 2118 2102 2119 // This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot 2120 // be nested, there is no context where a function definition can redefine a typedef name. To allow nested2121 // fu nctions requires further separation of variable and function declarators in typedef_redeclarator. The2122 // pattern precludes returningarrays and functions versus pointers to arrays and functions.2103 // This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested, 2104 // there is no context where a function definition can redefine a typedef name. To allow nested functions requires 2105 // further separation of variable and function declarators in typedef_redeclarator. The pattern precludes returning 2106 // arrays and functions versus pointers to arrays and functions. 2123 2107 2124 2108 function_declarator: … … 2155 2139 ; 2156 2140 2157 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a 2158 // typedef name (see function_declarator for additional comments). The pattern precludes returning arrays and2159 // functions versuspointers to arrays and functions.2141 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name 2142 // (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus 2143 // pointers to arrays and functions. 2160 2144 2161 2145 old_function_declarator: … … 2199 2183 // } 2200 2184 // 2201 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2202 // returning arraysand functions versus pointers to arrays and functions.2185 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2186 // and functions versus pointers to arrays and functions. 2203 2187 2204 2188 typedef_redeclarator: … … 2212 2196 TYPEDEFname 2213 2197 { 2214 typedefTable.setNextIdentifier( *( $1) );2198 typedefTable.setNextIdentifier( *( $1 ) ); 2215 2199 $$ = DeclarationNode::newName( $1 ); 2216 2200 } … … 2248 2232 ; 2249 2233 2250 // This pattern parses a declaration for a parameter variable or function prototype that is not redefining a 2251 // typedef name and allows the C99 array options, which can only appear in a parameter list. The pattern2252 // precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays2253 // a nd functions versus pointers to arrays and functions.2234 // This pattern parses a declaration for a parameter variable or function prototype that is not redefining a typedef 2235 // name and allows the C99 array options, which can only appear in a parameter list. The pattern precludes declaring an 2236 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to 2237 // arrays and functions. 2254 2238 2255 2239 identifier_parameter_declarator: … … 2289 2273 ; 2290 2274 2291 // This pattern parses a declaration for a parameter variable or function prototype that is redefining a 2292 // typedef name,e.g.:2275 // This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name, 2276 // e.g.: 2293 2277 // 2294 2278 // typedef int foo; 2295 2279 // int f( int foo ); // redefine typedef name in new scope 2296 2280 // 2297 // and allows the C99 array options, which can only appear in a parameter list. In addition, the pattern 2298 // handles thespecial meaning of parenthesis around a typedef name:2281 // and allows the C99 array options, which can only appear in a parameter list. In addition, the pattern handles the 2282 // special meaning of parenthesis around a typedef name: 2299 2283 // 2300 2284 // ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in … … 2310 2294 // int g( int g1( T g2( int p ) ) ); // see identifier_parameter_declarator 2311 2295 // 2312 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type 2313 // list, and not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes2314 // declaring an array of functions versus a pointer to an array of functions, and returningarrays and2315 // functions versus pointers to arrays and functions.2296 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and 2297 // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of 2298 // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to arrays and 2299 // functions. 2316 2300 2317 2301 typedef_parameter_redeclarator: … … 2325 2309 TYPEDEFname 2326 2310 { 2327 typedefTable.setNextIdentifier( * ($1));2311 typedefTable.setNextIdentifier( *$1 ); 2328 2312 $$ = DeclarationNode::newName( $1 ); 2329 2313 } … … 2353 2337 ; 2354 2338 2355 // This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no 2356 // identifier towhich the type applies, e.g.:2339 // This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to 2340 // which the type applies, e.g.: 2357 2341 // 2358 2342 // sizeof( int ); 2359 2343 // sizeof( int [10] ); 2360 2344 // 2361 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2362 // returning arraysand functions versus pointers to arrays and functions.2345 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2346 // and functions versus pointers to arrays and functions. 2363 2347 2364 2348 abstract_declarator: … … 2426 2410 // int f( int (int) ); // abstract function-prototype parameter; no parameter name specified 2427 2411 // 2428 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2429 // returning arraysand functions versus pointers to arrays and functions.2412 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2413 // and functions versus pointers to arrays and functions. 2430 2414 2431 2415 abstract_parameter_declarator: … … 2477 2461 // The declaration of an array parameter has additional syntax over arrays in normal variable declarations: 2478 2462 // 2479 // ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall 2480 // appear only in a declaration of a function parameter with an array type, and then only in the 2481 // outermost array type derivation." 2463 // ISO/IEC 9899:1999 Section 6.7.5.2(1) : "The optional type qualifiers and the keyword static shall appear only in 2464 // a declaration of a function parameter with an array type, and then only in the outermost array type derivation." 2482 2465 2483 2466 array_parameter_1st_dimension: … … 2498 2481 ; 2499 2482 2500 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type 2501 // applies,e.g.:2483 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies, 2484 // e.g.: 2502 2485 // 2503 2486 // sizeof( int ); // abstract variable; no identifier name specified 2504 2487 // 2505 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2506 // returning arraysand functions versus pointers to arrays and functions.2488 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2489 // and functions versus pointers to arrays and functions. 2507 2490 2508 2491 variable_abstract_declarator: … … 2542 2525 ; 2543 2526 2544 // This pattern parses a new-style declaration for a parameter variable or function prototype that is either 2545 // anidentifier or typedef name and allows the C99 array options, which can only appear in a parameter list.2527 // This pattern parses a new-style declaration for a parameter variable or function prototype that is either an 2528 // identifier or typedef name and allows the C99 array options, which can only appear in a parameter list. 2546 2529 2547 2530 new_identifier_parameter_declarator_tuple: // CFA … … 2573 2556 2574 2557 new_identifier_parameter_array: // CFA 2575 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due 2576 // toshift/reduce conflict with new-style empty (void) function return type.2558 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to 2559 // shift/reduce conflict with new-style empty (void) function return type. 2577 2560 '[' push pop ']' type_specifier 2578 2561 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } … … 2611 2594 ; 2612 2595 2613 // This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is 2614 // noidentifier to which the type applies, e.g.:2596 // This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no 2597 // identifier to which the type applies, e.g.: 2615 2598 // 2616 2599 // [int] f( int ); // abstract variable parameter; no parameter name specified … … 2628 2611 // 2629 2612 // Therefore, it is necessary to look at the token after identifier_or_typedef_name to know when to reduce 2630 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the 2631 // necessary lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and2632 // tuple declarations areduplicated when appearing with new_function_specifier.2613 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary 2614 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are 2615 // duplicated when appearing with new_function_specifier. 2633 2616 2634 2617 new_abstract_declarator_tuple: // CFA … … 2660 2643 2661 2644 new_abstract_array: // CFA 2662 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce 2663 // conflict withempty (void) function return type.2645 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with 2646 // empty (void) function return type. 2664 2647 '[' push pop ']' type_specifier 2665 2648 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } … … 2690 2673 ; 2691 2674 2692 // 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration 2693 // specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and 2694 // type name." 2695 // 2696 // 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the 2697 // beginning of the declaration specifiers in a declaration is an obsolescent feature." 2675 // 1) ISO/IEC 9899:1999 Section 6.7.2(2) : "At least one type specifier shall be given in the declaration specifiers in 2676 // each declaration, and in the specifier-qualifier list in each structure declaration and type name." 2677 // 2678 // 2) ISO/IEC 9899:1999 Section 6.11.5(1) : "The placement of a storage-class specifier other than at the beginning of 2679 // the declaration specifiers in a declaration is an obsolescent feature." 2698 2680 // 2699 2681 // 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not 2700 2682 // prototype-format parameter type declarators) is an obsolescent feature." 2701 2683 // 2702 // 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter 2703 // identifier and declaration lists (not prototype-format parameter type and identifier declarators) is an 2704 // obsolescent feature. 2684 // 4) ISO/IEC 9899:1999 Section 6.11.7(1) : "The use of function definitions with separate parameter identifier and 2685 // declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature. 2705 2686 2706 2687 //************************* MISCELLANEOUS ******************************** … … 2730 2711 2731 2712 // Local Variables: // 2713 // mode: c++ // 2732 2714 // tab-width: 4 // 2733 // mode: c++ //2734 2715 // compile-command: "make install" // 2735 2716 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.