Changes in src/Parser/parser.yy [de62360d:68cd1ce]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (96 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rde62360d r68cd1ce 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 22 15:19:44201513 // Update Count : 10 8212 // Last Modified On : Sat Jun 13 07:21:45 2015 13 // Update Count : 1048 14 14 // 15 15 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. 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. 25 26 26 27 // The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for: … … 28 29 // 1. designation with '=' (use ':' instead) 29 30 // 30 // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar also has31 // two levels of extensions. The first extensions cover most of the GCC C extensions, except for:31 // Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This 32 // grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions, except for: 32 33 // 33 34 // 1. nested functions … … 36 37 // 4. attributes not allowed in parenthesis of declarator 37 38 // 38 // All of the syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall39 // (CFA), which fixes several of C's outstanding problems and extends C with many modern language concepts. All of the40 // syntactic extensions for CFA C are marked with the comment "CFA". As noted above, there is one unreconcileable41 // parsing problem between C99 and CFA with respect to designators; this is discussed in detail before the "designation"42 // grammar rule.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 language 41 // 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 is 43 // discussed in detail before the "designation" grammar rule. 43 44 44 45 %{ … … 249 250 //************************* Namespace Management ******************************** 250 251 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. 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. 277 280 278 281 push: … … 291 294 292 295 constant: 293 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 296 // ENUMERATIONconstant is not included here; it is treated as a variable with type 297 // "enumeration constant". 294 298 INTEGERconstant { $$ = new ConstantNode( ConstantNode::Integer, $1 ); } 295 299 | FLOATINGconstant { $$ = new ConstantNode( ConstantNode::Float, $1 ); } … … 326 330 primary_expression: 327 331 IDENTIFIER // typedef name cannot be used as a variable name 328 { $$ = new VarRefNode( $1); }332 { $$ = new VarRefNode($1); } 329 333 | zero_one 330 { $$ = new VarRefNode( $1); }334 { $$ = new VarRefNode($1); } 331 335 | constant 332 336 { $$ = $1; } … … 336 340 { $$ = $2; } 337 341 | '(' compound_statement ')' // GCC, lambda expression 338 { $$ = new ValofExprNode( $2); }342 { $$ = new ValofExprNode($2); } 339 343 ; 340 344 … … 342 346 primary_expression 343 347 | postfix_expression '[' push assignment_expression pop ']' 344 // CFA, comma_expression disallowed in the context because it results in a commom user error: subscripting a345 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be346 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, whichis347 // equivalent to the old x[i,j].348 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4); }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 backwards 350 // compatible, there seems to be little advantage to this feature and many disadvantages. It is 351 // possible to write x[(i,j)] in CFA, which is equivalent to the old x[i,j]. 352 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Index), $1, $4); } 349 353 | postfix_expression '(' argument_expression_list ')' 350 { $$ = new CompositeExprNode( $1, $3); }354 { $$ = new CompositeExprNode($1, $3); } 351 355 | postfix_expression '.' no_attr_identifier 352 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3)); }356 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), $1, new VarRefNode($3)); } 353 357 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 354 358 | postfix_expression ARROW no_attr_identifier 355 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3)); }359 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), $1, new VarRefNode($3)); } 356 360 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 357 361 | postfix_expression ICR 358 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1); }362 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::IncrPost), $1); } 359 363 | postfix_expression DECR 360 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1); }364 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::DecrPost), $1); } 361 365 // GCC has priority: cast_expression 362 366 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 … … 367 371 argument_expression 368 372 | argument_expression_list ',' argument_expression 369 { $$ = (ExpressionNode *)( $1->set_link( $3)); }373 { $$ = (ExpressionNode *)($1->set_link($3)); } 370 374 ; 371 375 … … 375 379 | assignment_expression 376 380 | no_attr_identifier ':' assignment_expression 377 { $$ = $3->set_asArgName( $1); }378 // Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there is insufficient379 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used380 // with an appropriate semantic check.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 the 384 // tuple form must be used with an appropriate semantic check. 381 385 | '[' push assignment_expression pop ']' ':' assignment_expression 382 { $$ = $7->set_asArgName( $3); }386 { $$ = $7->set_asArgName($3); } 383 387 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 384 388 { $$ = $9->set_asArgName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } … … 394 398 { $$ = new VarRefNode( $1 ); } 395 399 | no_attr_identifier '.' field 396 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3); }400 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $3); } 397 401 | no_attr_identifier '.' '[' push field_list pop ']' 398 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5); }402 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::FieldSel), new VarRefNode( $1 ), $5); } 399 403 | no_attr_identifier ARROW field 400 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3); }404 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $3); } 401 405 | no_attr_identifier ARROW '[' push field_list pop ']' 402 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5); }406 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PFieldSel), new VarRefNode( $1 ), $5); } 403 407 ; 404 408 … … 406 410 postfix_expression 407 411 | ICR unary_expression 408 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2); }412 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Incr), $2); } 409 413 | DECR unary_expression 410 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2); }414 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Decr), $2); } 411 415 | EXTENSION cast_expression // GCC 412 416 { $$ = $2; } 413 417 | unary_operator cast_expression 414 { $$ = new CompositeExprNode( $1, $2); }418 { $$ = new CompositeExprNode($1, $2); } 415 419 | '!' cast_expression 416 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neg ), $2); }420 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Neg), $2); } 417 421 | '*' cast_expression // CFA 418 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PointTo ), $2); }422 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::PointTo), $2); } 419 423 // '*' is is separated from unary_operator because of shift/reduce conflict in: 420 424 // { * X; } // dereference X … … 422 426 // '&' must be moved here if C++ reference variables are supported. 423 427 | SIZEOF unary_expression 424 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2); }428 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::SizeOf), $2); } 425 429 | SIZEOF '(' type_name_no_function ')' 426 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3)); }430 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::SizeOf), new TypeValueNode($3)); } 427 431 | ATTR_IDENTIFIER 428 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1)); }432 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Attr), new VarRefNode($1)); } 429 433 | ATTR_IDENTIFIER '(' type_name ')' 430 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3)); }434 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Attr), new VarRefNode($1), new TypeValueNode($3)); } 431 435 | ATTR_IDENTIFIER '(' argument_expression ')' 432 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3); }436 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Attr), new VarRefNode($1), $3); } 433 437 | ALIGNOF unary_expression // GCC, variable alignment 434 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2); }438 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::AlignOf), $2); } 435 439 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 436 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3)); }440 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::AlignOf), new TypeValueNode($3)); } 437 441 | ANDAND no_attr_identifier // GCC, address of label 438 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true)); }442 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LabelAddress), new VarRefNode($2, true)); } 439 443 ; 440 444 441 445 unary_operator: 442 '&' { $$ = new OperatorNode( OperatorNode::AddressOf); }443 | '+' { $$ = new OperatorNode( OperatorNode::UnPlus); }444 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus); }445 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg); }446 '&' { $$ = new OperatorNode(OperatorNode::AddressOf); } 447 | '+' { $$ = new OperatorNode(OperatorNode::UnPlus); } 448 | '-' { $$ = new OperatorNode(OperatorNode::UnMinus); } 449 | '~' { $$ = new OperatorNode(OperatorNode::BitNeg); } 446 450 ; 447 451 … … 449 453 unary_expression 450 454 | '(' type_name_no_function ')' cast_expression 451 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4); }455 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); } 452 456 | '(' type_name_no_function ')' tuple 453 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4); }457 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Cast), new TypeValueNode($2), $4); } 454 458 ; 455 459 … … 457 461 cast_expression 458 462 | multiplicative_expression '*' cast_expression 459 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3); }463 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mul),$1,$3); } 460 464 | multiplicative_expression '/' cast_expression 461 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3); }465 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Div),$1,$3); } 462 466 | multiplicative_expression '%' cast_expression 463 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3); }467 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Mod),$1,$3); } 464 468 ; 465 469 … … 467 471 multiplicative_expression 468 472 | additive_expression '+' multiplicative_expression 469 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3); }473 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Plus),$1,$3); } 470 474 | additive_expression '-' multiplicative_expression 471 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3); }475 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Minus),$1,$3); } 472 476 ; 473 477 … … 475 479 additive_expression 476 480 | shift_expression LS additive_expression 477 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3); }481 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LShift),$1,$3); } 478 482 | shift_expression RS additive_expression 479 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3); }483 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::RShift),$1,$3); } 480 484 ; 481 485 … … 483 487 shift_expression 484 488 | relational_expression '<' shift_expression 485 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3); }489 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LThan),$1,$3); } 486 490 | relational_expression '>' shift_expression 487 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3); }491 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::GThan),$1,$3); } 488 492 | relational_expression LE shift_expression 489 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3); }493 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::LEThan),$1,$3); } 490 494 | relational_expression GE shift_expression 491 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3); }495 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::GEThan),$1,$3); } 492 496 ; 493 497 … … 495 499 relational_expression 496 500 | equality_expression EQ relational_expression 497 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3); }501 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Eq), $1, $3); } 498 502 | equality_expression NE relational_expression 499 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3); }503 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Neq), $1, $3); } 500 504 ; 501 505 … … 503 507 equality_expression 504 508 | AND_expression '&' equality_expression 505 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3); }509 { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::BitAnd), $1, $3); } 506 510 ; 507 511 … … 509 513 AND_expression 510 514 | exclusive_OR_expression '^' AND_expression 511 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3); }515 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Xor), $1, $3); } 512 516 ; 513 517 … … 515 519 exclusive_OR_expression 516 520 | inclusive_OR_expression '|' exclusive_OR_expression 517 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3); }521 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::BitOr), $1, $3); } 518 522 ; 519 523 … … 521 525 inclusive_OR_expression 522 526 | logical_AND_expression ANDAND inclusive_OR_expression 523 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3); }527 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::And), $1, $3); } 524 528 ; 525 529 … … 527 531 logical_AND_expression 528 532 | logical_OR_expression OROR logical_AND_expression 529 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3); }533 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Or), $1, $3); } 530 534 ; 531 535 … … 533 537 logical_OR_expression 534 538 | logical_OR_expression '?' comma_expression ':' conditional_expression 535 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); }539 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Cond), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); } 536 540 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 537 { $$=new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4); }541 { $$=new CompositeExprNode(new OperatorNode(OperatorNode::NCond),$1,$4); } 538 542 | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression 539 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); }543 { $$ = new CompositeExprNode( new OperatorNode(OperatorNode::Cond), (ExpressionNode *)mkList( (*$1, *$3, *$5) ) ); } 540 544 ; 541 545 … … 548 552 conditional_expression 549 553 | unary_expression '=' assignment_expression 550 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3); }554 { $$ =new CompositeExprNode(new OperatorNode(OperatorNode::Assign), $1, $3); } 551 555 | unary_expression assignment_operator assignment_expression 552 { $$ =new CompositeExprNode( $2, $1, $3); }556 { $$ =new CompositeExprNode($2, $1, $3); } 553 557 | tuple assignment_opt // CFA, tuple expression 554 { $$ = ( $2 == 0) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); }558 { $$ = ($2 == 0) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); } 555 559 ; 556 560 … … 562 566 563 567 tuple: // CFA, tuple 564 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with565 // co mma_expression in new_identifier_parameter_array and new_abstract_array568 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce 569 // conflict with comma_expression in new_identifier_parameter_array and new_abstract_array 566 570 '[' push pop ']' 567 571 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); } … … 581 585 582 586 assignment_operator: 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); }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); } 593 597 ; 594 598 595 599 comma_expression: 596 600 assignment_expression 597 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3); }598 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3); }601 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list($3); } 602 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Comma),$1,$3); } 599 603 ; 600 604 … … 620 624 labeled_statement: 621 625 no_attr_identifier ':' attribute_list_opt statement 622 { $$ = $4->add_label( $1);}626 { $$ = $4->add_label($1);} 623 627 ; 624 628 … … 627 631 { $$ = new CompoundStmtNode( (StatementNode *)0 ); } 628 632 | '{' 629 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also630 // requires its own scope633 // Two scopes are necessary because the block itself has a scope, but every declaration within the 634 // block also requires its own scope 631 635 push push 632 636 label_declaration_opt // GCC, local labels … … 638 642 block_item 639 643 | block_item_list push block_item 640 { if ( $1 != 0 ) { $1->set_link( $3); $$ = $1; } }644 { if ($1 != 0) { $1->set_link($3); $$ = $1; } } 641 645 ; 642 646 … … 654 658 statement 655 659 | statement_list statement 656 { if ( $1 != 0 ) { $1->set_link( $2); $$ = $1; } }660 { if ($1 != 0) { $1->set_link($2); $$ = $1; } } 657 661 ; 658 662 659 663 expression_statement: 660 664 comma_expression_opt ';' 661 { $$ = new StatementNode( StatementNode::Exp, $1, 0); }665 { $$ = new StatementNode(StatementNode::Exp, $1, 0); } 662 666 ; 663 667 … … 665 669 IF '(' comma_expression ')' statement %prec THEN 666 670 // explicitly deal with the shift/reduce conflict on if/else 667 { $$ = new StatementNode( StatementNode::If, $3, $5); }671 { $$ = new StatementNode(StatementNode::If, $3, $5); } 668 672 | IF '(' comma_expression ')' statement ELSE statement 669 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7)) ); }673 { $$ = new StatementNode(StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7)) ); } 670 674 | SWITCH '(' comma_expression ')' case_clause // CFA 671 { $$ = new StatementNode( StatementNode::Switch, $3, $5); }675 { $$ = new StatementNode(StatementNode::Switch, $3, $5); } 672 676 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 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. 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. 677 682 | CHOOSE '(' comma_expression ')' case_clause // CFA 678 { $$ = new StatementNode( StatementNode::Choose, $3, $5); }683 { $$ = new StatementNode(StatementNode::Choose, $3, $5); } 679 684 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 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 case684 // c lause allows a list of values and subranges.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 // case clause allows a list of values and subranges. 685 690 686 691 case_value: // CFA 687 692 constant_expression { $$ = $1; } 688 693 | constant_expression ELLIPSIS constant_expression // GCC, subrange 689 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3); }694 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range),$1,$3); } 690 695 | subrange // CFA, subrange 691 696 ; … … 694 699 case_value 695 700 | case_value_list ',' case_value 696 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3) ); }701 { $$ = new CompositeExprNode(new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents($1))->set_link($3) ); } 697 702 ; 698 703 699 704 case_label: // CFA 700 CASE case_value_list ':' { $$ = new StatementNode( StatementNode::Case, $2, 0); }701 | DEFAULT ':' { $$ = new StatementNode( StatementNode::Default); }705 CASE case_value_list ':' { $$ = new StatementNode(StatementNode::Case, $2, 0); } 706 | DEFAULT ':' { $$ = new StatementNode(StatementNode::Default); } 702 707 // A semantic check is required to ensure only one default clause per switch/choose statement. 703 708 ; … … 705 710 case_label_list: // CFA 706 711 case_label 707 | case_label_list case_label { $$ = (StatementNode *)( $1->set_link( $2)); }712 | case_label_list case_label { $$ = (StatementNode *)($1->set_link($2)); } 708 713 ; 709 714 710 715 case_clause: // CFA 711 case_label_list statement { $$ = $1->append_last_case( $2); }716 case_label_list statement { $$ = $1->append_last_case($2); } 712 717 ; 713 718 … … 720 725 switch_clause_list: // CFA 721 726 case_label_list statement_list 722 { $$ = $1->append_last_case( $2); }727 { $$ = $1->append_last_case($2); } 723 728 | switch_clause_list case_label_list statement_list 724 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3))); }729 { $$ = (StatementNode *)($1->set_link($2->append_last_case($3))); } 725 730 ; 726 731 … … 733 738 choose_clause_list: // CFA 734 739 case_label_list fall_through 735 { $$ = $1->append_last_case( $2); }740 { $$ = $1->append_last_case($2); } 736 741 | case_label_list statement_list fall_through_opt 737 { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3 ))); }742 { $$ = $1->append_last_case((StatementNode *)mkList((*$2,*$3))); } 738 743 | choose_clause_list case_label_list fall_through 739 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3))); }744 { $$ = (StatementNode *)($1->set_link($2->append_last_case($3))); } 740 745 | choose_clause_list case_label_list statement_list fall_through_opt 741 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case((StatementNode *)mkList((*$3,*$4))))); }746 { $$ = (StatementNode *)($1->set_link($2->append_last_case((StatementNode *)mkList((*$3,*$4))))); } 742 747 ; 743 748 … … 749 754 750 755 fall_through: // CFA 751 FALLTHRU { $$ = new StatementNode( StatementNode::Fallthru, 0, 0); }752 | FALLTHRU ';' { $$ = new StatementNode( StatementNode::Fallthru, 0, 0); }756 FALLTHRU { $$ = new StatementNode(StatementNode::Fallthru, 0, 0); } 757 | FALLTHRU ';' { $$ = new StatementNode(StatementNode::Fallthru, 0, 0); } 753 758 ; 754 759 755 760 iteration_statement: 756 761 WHILE '(' comma_expression ')' statement 757 { $$ = new StatementNode( StatementNode::While, $3, $5); }762 { $$ = new StatementNode(StatementNode::While, $3, $5); } 758 763 | DO statement WHILE '(' comma_expression ')' ';' 759 { $$ = new StatementNode( StatementNode::Do, $5, $2); }764 { $$ = new StatementNode(StatementNode::Do, $5, $2); } 760 765 | FOR '(' push for_control_expression ')' statement 761 { $$ = new StatementNode( StatementNode::For, $4, $6); }766 { $$ = new StatementNode(StatementNode::For, $4, $6); } 762 767 ; 763 768 764 769 for_control_expression: 765 770 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 766 { $$ = new ForCtlExprNode( $1, $4, $6); }771 { $$ = new ForCtlExprNode($1, $4, $6); } 767 772 | declaration comma_expression_opt ';' comma_expression_opt // C99 768 { $$ = new ForCtlExprNode( $1, $2, $4); }773 { $$ = new ForCtlExprNode($1, $2, $4); } 769 774 ; 770 775 771 776 jump_statement: 772 777 GOTO no_attr_identifier ';' 773 { $$ = new StatementNode( StatementNode::Goto, $2); }778 { $$ = new StatementNode(StatementNode::Goto, $2); } 774 779 | GOTO '*' comma_expression ';' // GCC, computed goto 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); }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); } 778 783 | CONTINUE ';' 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 ); } 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); } 781 787 | CONTINUE no_attr_identifier ';' // CFA, multi-level continue 782 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and783 // the target of the transfer appears only at the start of an iteration statement.784 { $$ = new StatementNode( StatementNode::Continue, $2); }788 // A semantic check is required to ensure this statement appears only in the body of an iteration 789 // statement, and the target of the transfer appears only at the start of an iteration statement. 790 { $$ = new StatementNode(StatementNode::Continue, $2); } 785 791 | BREAK ';' 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 ); } 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); } 788 795 | BREAK no_attr_identifier ';' // CFA, multi-level exit 789 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and790 // the target of the transfer appears only at the start of an iteration statement.791 { $$ = new StatementNode( StatementNode::Break, $2 ); }796 // A semantic check is required to ensure this statement appears only in the body of an iteration 797 // statement, and the target of the transfer appears only at the start of an iteration statement. 798 { $$ = new StatementNode(StatementNode::Break, $2 ); } 792 799 | RETURN comma_expression_opt ';' 793 { $$ = new StatementNode( StatementNode::Return, $2, 0); }800 { $$ = new StatementNode(StatementNode::Return, $2, 0); } 794 801 | THROW assignment_expression ';' 795 { $$ = new StatementNode( StatementNode::Throw, $2, 0); }802 { $$ = new StatementNode(StatementNode::Throw, $2, 0); } 796 803 | THROW ';' 797 { $$ = new StatementNode( StatementNode::Throw, 0, 0); }804 { $$ = new StatementNode(StatementNode::Throw, 0, 0); } 798 805 ; 799 806 800 807 exception_statement: 801 808 TRY compound_statement handler_list 802 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); }809 { $$ = new StatementNode(StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); } 803 810 | TRY compound_statement finally_clause 804 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); }811 { $$ = new StatementNode(StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); } 805 812 | TRY compound_statement handler_list finally_clause 806 813 { 807 $3->set_link( $4);808 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3))));814 $3->set_link($4); 815 $$ = new StatementNode(StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3)))); 809 816 } 810 817 ; … … 813 820 // There must be at least one catch clause 814 821 handler_clause 815 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 822 // ISO/IEC 9899:1999 Section 15.3(6) If present, a "..." handler shall be the last handler for its try 823 // block. 816 824 | CATCH '(' ELLIPSIS ')' compound_statement 817 825 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } … … 822 830 handler_clause: 823 831 CATCH '(' push push exception_declaration pop ')' compound_statement pop 824 { $$ = StatementNode::newCatchStmt( $5, $8); }832 { $$ = StatementNode::newCatchStmt($5, $8); } 825 833 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 826 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9) ); }834 { $$ = $1->set_link( StatementNode::newCatchStmt($6, $9) ); } 827 835 ; 828 836 … … 830 838 FINALLY compound_statement 831 839 { 832 $$ = new StatementNode( StatementNode::Finally, 0, $2);840 $$ = new StatementNode(StatementNode::Finally, 0, $2); 833 841 std::cout << "Just created a finally node" << std::endl; 834 842 } … … 859 867 asm_statement: 860 868 ASM type_qualifier_list_opt '(' constant_expression ')' ';' 861 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }869 { $$ = new StatementNode(StatementNode::Asm, 0, 0); } 862 870 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ')' ';' // remaining GCC 863 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }871 { $$ = new StatementNode(StatementNode::Asm, 0, 0); } 864 872 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ')' ';' 865 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }873 { $$ = new StatementNode(StatementNode::Asm, 0, 0); } 866 874 | ASM type_qualifier_list_opt '(' constant_expression ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list ')' ';' 867 { $$ = new StatementNode( StatementNode::Asm, 0, 0); }875 { $$ = new StatementNode(StatementNode::Asm, 0, 0); } 868 876 ; 869 877 … … 933 941 ; 934 942 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. 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. 941 950 // 942 951 // CFA C … … 959 968 } 960 969 | declaration_qualifier_list new_variable_specifier initializer_opt 961 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude962 // them as a type_qualifier cannot appear in that context.970 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to 971 // preclude them as a type_qualifier cannot appear in that context. 963 972 { 964 973 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 973 982 974 983 new_variable_specifier: // CFA 975 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static976 // storage-class984 // A semantic check is required to ensure asm_name only appears on declarations with implicit or 985 // explicit static storage-class 977 986 new_abstract_declarator_no_tuple identifier_or_typedef_name asm_name_opt 978 987 { … … 1023 1032 '[' push pop ']' identifier '(' push new_parameter_type_list_opt pop ')' 1024 1033 { 1025 typedefTable.setNextIdentifier( *( $5) );1034 typedefTable.setNextIdentifier( *($5) ); 1026 1035 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1027 1036 } 1028 1037 | '[' push pop ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')' 1029 1038 { 1030 typedefTable.setNextIdentifier( *( $5) );1039 typedefTable.setNextIdentifier( *($5) ); 1031 1040 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1032 1041 } … … 1036 1045 // '[' ']' type_specifier 1037 1046 // 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. 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. 1040 1050 | new_abstract_tuple identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')' 1041 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator). 1051 // To obtain LR(1), this rule must be factored out from function return type (see 1052 // new_abstract_declarator). 1042 1053 { 1043 1054 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); … … 1053 1064 { $$ = DeclarationNode::newTuple( $3 ); } 1054 1065 | '[' push new_parameter_list pop ',' push new_abstract_parameter_list pop ']' 1055 // To obtain LR(1 ), the last new_abstract_parameter_list is added into this flattened rule to lookahead to the1056 // ']'.1066 // To obtain LR(1), the last new_abstract_parameter_list is added into this flattened rule to 1067 // lookahead to the ']'. 1057 1068 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1058 1069 ; … … 1061 1072 TYPEDEF new_variable_specifier 1062 1073 { 1063 typedefTable.addToEnclosingScope( TypedefTable::TD );1074 typedefTable.addToEnclosingScope( TypedefTable::TD); 1064 1075 $$ = $2->addTypedef(); 1065 1076 } 1066 1077 | TYPEDEF new_function_specifier 1067 1078 { 1068 typedefTable.addToEnclosingScope( TypedefTable::TD );1079 typedefTable.addToEnclosingScope( TypedefTable::TD); 1069 1080 $$ = $2->addTypedef(); 1070 1081 } 1071 1082 | new_typedef_declaration pop ',' push no_attr_identifier 1072 1083 { 1073 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );1084 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD); 1074 1085 $$ = $1->appendList( $1->cloneType( $5 ) ); 1075 1086 } 1076 1087 ; 1077 1088 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. 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. 1080 1092 1081 1093 typedef_declaration: 1082 1094 TYPEDEF type_specifier declarator 1083 1095 { 1084 typedefTable.addToEnclosingScope( TypedefTable::TD );1096 typedefTable.addToEnclosingScope( TypedefTable::TD); 1085 1097 $$ = $3->addType( $2 )->addTypedef(); 1086 1098 } 1087 1099 | typedef_declaration pop ',' push declarator 1088 1100 { 1089 typedefTable.addToEnclosingScope( TypedefTable::TD );1101 typedefTable.addToEnclosingScope( TypedefTable::TD); 1090 1102 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1091 1103 } 1092 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )1093 { 1094 typedefTable.addToEnclosingScope( TypedefTable::TD );1104 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2) 1105 { 1106 typedefTable.addToEnclosingScope( TypedefTable::TD); 1095 1107 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1096 1108 } 1097 1109 | type_specifier TYPEDEF declarator 1098 1110 { 1099 typedefTable.addToEnclosingScope( TypedefTable::TD );1111 typedefTable.addToEnclosingScope( TypedefTable::TD); 1100 1112 $$ = $3->addType( $1 )->addTypedef(); 1101 1113 } 1102 1114 | type_specifier TYPEDEF type_qualifier_list declarator 1103 1115 { 1104 typedefTable.addToEnclosingScope( TypedefTable::TD );1105 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1);1116 typedefTable.addToEnclosingScope( TypedefTable::TD); 1117 $$ = $4->addQualifiers($1)->addTypedef()->addType($1); 1106 1118 } 1107 1119 ; … … 1110 1122 TYPEDEF no_attr_identifier '=' assignment_expression 1111 1123 { 1112 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD);1124 typedefTable.addToEnclosingScope(*($2), TypedefTable::TD); 1113 1125 $$ = DeclarationNode::newName( 0 ); // XXX 1114 1126 } 1115 1127 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1116 1128 { 1117 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD);1129 typedefTable.addToEnclosingScope(*($5), TypedefTable::TD); 1118 1130 $$ = DeclarationNode::newName( 0 ); // XXX 1119 1131 } … … 1128 1140 1129 1141 declaring_list: 1130 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static1131 // storage-class1142 // A semantic check is required to ensure asm_name only appears on declarations with implicit or 1143 // explicit static storage-class 1132 1144 declaration_specifier declarator asm_name_opt initializer_opt 1133 1145 { 1134 1146 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1135 $$ = ( $2->addType( $1 ))->addInitializer( $4);1147 $$ = ($2->addType( $1 ))->addInitializer($4); 1136 1148 } 1137 1149 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1138 1150 { 1139 1151 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1140 $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer( $6) ) );1152 $$ = $1->appendList( $1->cloneBaseType( $4->addInitializer($6) ) ); 1141 1153 } 1142 1154 ; … … 1163 1175 1164 1176 type_qualifier_list: 1165 // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of declaration. 1177 // A semantic check is necessary to ensure a type qualifier is appropriate for the kind of 1178 // declaration. 1166 1179 // 1167 // ISO/IEC 9899:1999 Section 6.7.3(4 ) : If the same qualifier appears more than once in the same1168 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it1169 // appeared only once.1180 // ISO/IEC 9899:1999 Section 6.7.3(4) : If the same qualifier appears more than once in the same 1181 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as 1182 // if it appeared only once. 1170 1183 type_qualifier 1171 1184 | type_qualifier_list type_qualifier … … 1203 1216 declaration_qualifier_list: 1204 1217 storage_class_list 1205 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2 )1218 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2) 1206 1219 { $$ = $1->addQualifiers( $2 ); } 1207 1220 | declaration_qualifier_list type_qualifier_list storage_class_list … … 1210 1223 1211 1224 storage_class_list: 1212 // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration and that1213 // only one of each is specified, except for inline, which can appear with the others.1225 // A semantic check is necessary to ensure a storage class is appropriate for the kind of declaration 1226 // and that only one of each is specified, except for inline, which can appear with the others. 1214 1227 // 1215 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration1216 // specifiers in a declaration.1228 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the 1229 // declaration specifiers in a declaration. 1217 1230 storage_class 1218 1231 | storage_class_list storage_class … … 1368 1381 | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1369 1382 { $$ = DeclarationNode::newAggregate( $1, 0, $4, $8, $11 ); } 1370 | aggregate_key TYPEGENname '(' type_name_list ')' // CFA1371 {}1372 1383 | aggregate_key '(' push type_name_list pop ')' no_attr_identifier_or_typedef_name // CFA 1373 1384 // push and pop are only to prevent S/R conflicts … … 1490 1501 1491 1502 new_parameter_list: // CFA 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 ']'. 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 ']'. 1494 1506 new_parameter_declaration 1495 1507 | new_abstract_parameter_list pop ',' push new_parameter_declaration … … 1528 1540 ; 1529 1541 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. 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. 1532 1545 1533 1546 new_parameter_declaration: // CFA, new & old style parameter declaration … … 1557 1570 { 1558 1571 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1559 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3) );1572 $$ = $2->addType( $1 )->addInitializer( new InitializerNode($3) ); 1560 1573 } 1561 1574 | declaration_specifier typedef_parameter_redeclarator assignment_opt 1562 1575 { 1563 1576 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1564 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3) );1577 $$ = $2->addType( $1 )->addInitializer( new InitializerNode($3) ); 1565 1578 } 1566 1579 ; … … 1573 1586 1574 1587 // ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a 1575 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on1576 // identifiers. The ANSI-style parameter-list can redefine a typedef name.1588 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is 1589 // based only on identifiers. The ANSI-style parameter-list can redefine a typedef name. 1577 1590 1578 1591 identifier_list: // K&R-style parameter list => no types … … 1598 1611 no_attr_identifier 1599 1612 | TYPEDEFname 1600 //| TYPEGENname1613 | TYPEGENname 1601 1614 ; 1602 1615 … … 1623 1636 1624 1637 initializer: 1625 assignment_expression { $$ = new InitializerNode( $1); }1626 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode( $2, true); }1638 assignment_expression { $$ = new InitializerNode($1); } 1639 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode($2, true); } 1627 1640 ; 1628 1641 … … 1630 1643 initializer 1631 1644 | designation initializer { $$ = $2->set_designators( $1 ); } 1632 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link( $3) ); }1645 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link($3) ); } 1633 1646 | initializer_list ',' designation initializer 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 of1638 // '=' to separator the designator from the initializer value, as in: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: 1639 1652 // 1640 1653 // int x[10] = { [1] = 3 }; 1641 1654 // 1642 // The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment. To disambiguate this case, CFA1643 // c hanges the syntax from "=" to ":" as the separator between the designator and initializer. GCC does uses ":" for1644 // field selection. The optional use of the "=" in GCC, or in this case ":", cannot be supported either due to1645 // s hift/reduce conflicts1655 // The string "[1] = 3" can be parsed as a designator assignment or a tuple assignment. To disambiguate this 1656 // case, CFA changes the syntax from "=" to ":" as the separator between the designator and initializer. GCC 1657 // does uses ":" for field selection. The optional use of the "=" in GCC, or in this case ":", cannot be 1658 // supported either due to shift/reduce conflicts 1646 1659 1647 1660 designation: … … 1653 1666 designator_list: // C99 1654 1667 designator 1655 | designator_list designator { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1656 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); } 1668 | designator_list designator { $$ = (ExpressionNode *)($1->set_link( $2 )); } 1657 1669 ; 1658 1670 … … 1661 1673 { $$ = new VarRefNode( $2 ); } 1662 1674 | '[' push assignment_expression pop ']' // C99, single array element 1663 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1675 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with 1676 // tuple. 1664 1677 { $$ = $3; } 1665 1678 | '[' push subrange pop ']' // CFA, multiple array elements 1666 1679 { $$ = $3; } 1667 1680 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1668 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5); }1681 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $3, $5); } 1669 1682 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1670 1683 { $$ = $4; } 1671 1684 ; 1672 1685 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: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: 1675 1688 // 1676 1689 // Overloading: function, data, and operator identifiers may be overloaded. 1677 1690 // 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. 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. 1684 1698 // 1685 1699 // Specifications and Assertions: Specifications are collections of declarations parameterized by one or more 1686 // types. They serve many of the purposes of abstract classes, and specification hierarchies resemble subclass1687 // hierarchies. Unlike classes, they can define relationships between types. Assertions declare that a type or1688 // t ypes provide the operations declared by a specification. Assertions are normally used to declare requirements1689 // on type arguments of polymorphic functions.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 declare 1702 // that a type or types provide the operations declared by a specification. Assertions are normally used 1703 // to declare requirements on type arguments of polymorphic functions. 1690 1704 1691 1705 typegen_declaration_specifier: // CFA … … 1716 1730 type_parameter: // CFA 1717 1731 type_class no_attr_identifier_or_typedef_name 1718 { typedefTable.addToEnclosingScope(*( $2 ), TypedefTable::TD); }1732 { typedefTable.addToEnclosingScope(*($2), TypedefTable::TD); } 1719 1733 assertion_list_opt 1720 1734 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); } … … 1741 1755 '|' no_attr_identifier_or_typedef_name '(' type_name_list ')' 1742 1756 { 1743 typedefTable.openContext( *( $2) );1757 typedefTable.openContext( *($2) ); 1744 1758 $$ = DeclarationNode::newContextUse( $2, $4 ); 1745 1759 } … … 1755 1769 | assignment_expression 1756 1770 | type_name_list ',' type_name 1757 { $$ = (ExpressionNode *)( $1->set_link(new TypeValueNode( $3 ))); }1771 { $$ = (ExpressionNode *)($1->set_link(new TypeValueNode( $3 ))); } 1758 1772 | type_name_list ',' assignment_expression 1759 { $$ = (ExpressionNode *)( $1->set_link( $3)); }1773 { $$ = (ExpressionNode *)($1->set_link($3)); } 1760 1774 ; 1761 1775 … … 1779 1793 no_attr_identifier_or_typedef_name 1780 1794 { 1781 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD);1795 typedefTable.addToEnclosingScope(*($1), TypedefTable::TD); 1782 1796 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 1783 1797 } 1784 1798 | no_01_identifier_or_typedef_name '(' push type_parameter_list pop ')' 1785 1799 { 1786 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG);1800 typedefTable.addToEnclosingScope(*($1), TypedefTable::TG); 1787 1801 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 1788 1802 } … … 1792 1806 CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' '}' 1793 1807 { 1794 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );1808 typedefTable.addToEnclosingScope(*($2), TypedefTable::ID ); 1795 1809 $$ = DeclarationNode::newContext( $2, $5, 0 ); 1796 1810 } 1797 1811 | CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' 1798 1812 { 1799 typedefTable.enterContext( * $2);1813 typedefTable.enterContext( *($2) ); 1800 1814 typedefTable.enterScope(); 1801 1815 } … … 1803 1817 { 1804 1818 typedefTable.leaveContext(); 1805 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );1819 typedefTable.addToEnclosingScope(*($2), TypedefTable::ID ); 1806 1820 $$ = DeclarationNode::newContext( $2, $5, $10 ); 1807 1821 } … … 1832 1846 | new_context_declaring_list pop ',' push identifier_or_typedef_name 1833 1847 { 1834 typedefTable.addToEnclosingScope2( * $5, TypedefTable::ID );1848 typedefTable.addToEnclosingScope2( *($5), TypedefTable::ID ); 1835 1849 $$ = $1->appendList( $1->cloneType( $5 ) ); 1836 1850 } … … 1868 1882 external_definition 1869 1883 | external_definition_list push external_definition 1870 { $$ = ( $1 != NULL ) ? $1->appendList( $3 ) : $3; }1884 { $$ = ($1 != NULL ) ? $1->appendList( $3 ) : $3; } 1871 1885 ; 1872 1886 … … 1900 1914 function_definition 1901 1915 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) 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) 1906 1921 | function_declarator compound_statement 1907 1922 { … … 1987 2002 subrange: 1988 2003 constant_expression '~' constant_expression // CFA, integer subrange 1989 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3); }2004 { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::Range), $1, $3); } 1990 2005 ; 1991 2006 … … 2028 2043 2029 2044 // ============================================================================ 2030 // The following sections are a series of grammar patterns used to parse declarators. Multiple patterns are necessary2031 // because the type of an identifier in wrapped around the identifier in the same form as its usage in an expression, as2032 // in :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 usage 2047 // in an expression, as in: 2033 2048 // 2034 2049 // int (*f())[10] { ... }; 2035 2050 // ... (*f())[3] += 1; // definition mimics usage 2036 2051 // 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. 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. 2039 2055 // ============================================================================ 2040 2056 2041 2057 // ---------------------------------------------------------------------------- 2042 // The set of valid declarators before a compound statement for defining a function is less than the set of declarators2043 // to define a variable or function prototype, e.g.:2058 // The set of valid declarators before a compound statement for defining a function is less than the set of 2059 // declarators to define a variable or function prototype, e.g.: 2044 2060 // 2045 2061 // valid declaration invalid definition … … 2050 2066 // int (*f)(int); int (*f)(int) {} 2051 2067 // 2052 // To preclude this syntactic anomaly requires separating the grammar rules for variable and function declarators, hence2053 // variable_declarator and function_declarator.2068 // To preclude this syntactic anomaly requires separating the grammar rules for variable and function 2069 // declarators, hence variable_declarator and function_declarator. 2054 2070 // ---------------------------------------------------------------------------- 2055 2071 2056 // This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern precludes2057 // declaring an array of functions versus a pointer to an array of functions.2072 // This pattern parses a declaration of a variable that is not redefining a typedef name. The pattern 2073 // precludes declaring an array of functions versus a pointer to an array of functions. 2058 2074 2059 2075 variable_declarator: … … 2067 2083 identifier 2068 2084 { 2069 typedefTable.setNextIdentifier( * $1);2085 typedefTable.setNextIdentifier( *($1) ); 2070 2086 $$ = DeclarationNode::newName( $1 ); 2071 2087 } … … 2101 2117 ; 2102 2118 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 requires2105 // fu rther separation of variable and function declarators in typedef_redeclarator. The pattern precludes returning2106 // arrays and functions versus pointers to arrays and functions.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 nested 2121 // functions requires further separation of variable and function declarators in typedef_redeclarator. The 2122 // pattern precludes returning arrays and functions versus pointers to arrays and functions. 2107 2123 2108 2124 function_declarator: … … 2139 2155 ; 2140 2156 2141 // This pattern parses an old-style K&R function declarator (OBSOLESCENT, see 4) that is not redefining a typedef name2142 // (see function_declarator for additional comments). The pattern precludes returning arrays and functions versus2143 // pointers to arrays and functions.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 and 2159 // functions versus pointers to arrays and functions. 2144 2160 2145 2161 old_function_declarator: … … 2183 2199 // } 2184 2200 // 2185 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays2186 // and functions versus pointers to arrays and functions.2201 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2202 // returning arrays and functions versus pointers to arrays and functions. 2187 2203 2188 2204 typedef_redeclarator: … … 2196 2212 TYPEDEFname 2197 2213 { 2198 typedefTable.setNextIdentifier( *( $1) );2214 typedefTable.setNextIdentifier( *($1) ); 2199 2215 $$ = DeclarationNode::newName( $1 ); 2200 2216 } … … 2232 2248 ; 2233 2249 2234 // This pattern parses a declaration for a parameter variable or function prototype that is not redefining a typedef2235 // name and allows the C99 array options, which can only appear in a parameter list. The pattern precludes declaring an2236 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to2237 // a rrays and functions.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 pattern 2252 // precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays 2253 // and functions versus pointers to arrays and functions. 2238 2254 2239 2255 identifier_parameter_declarator: … … 2273 2289 ; 2274 2290 2275 // This pattern parses a declaration for a parameter variable or function prototype that is redefining a typedef name,2276 // e.g.:2291 // This pattern parses a declaration for a parameter variable or function prototype that is redefining a 2292 // typedef name, e.g.: 2277 2293 // 2278 2294 // typedef int foo; 2279 2295 // int f( int foo ); // redefine typedef name in new scope 2280 2296 // 2281 // and allows the C99 array options, which can only appear in a parameter list. In addition, the pattern handles the2282 // special meaning of parenthesis around a typedef name:2297 // and allows the C99 array options, which can only appear in a parameter list. In addition, the pattern 2298 // handles the special meaning of parenthesis around a typedef name: 2283 2299 // 2284 2300 // ISO/IEC 9899:1999 Section 6.7.5.3(11) : "In a parameter declaration, a single typedef name in … … 2294 2310 // int g( int g1( T g2( int p ) ) ); // see identifier_parameter_declarator 2295 2311 // 2296 // In essence, a '(' immediately to the left of typedef name, T, is interpreted as starting a parameter type list, and2297 // not as redundant parentheses around a redeclaration of T. Finally, the pattern also precludes declaring an array of2298 // functions versus a pointer to an array of functions, and returning arrays and functions versus pointers toarrays and2299 // functions .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 precludes 2314 // declaring an array of functions versus a pointer to an array of functions, and returning arrays and 2315 // functions versus pointers to arrays and functions. 2300 2316 2301 2317 typedef_parameter_redeclarator: … … 2309 2325 TYPEDEFname 2310 2326 { 2311 typedefTable.setNextIdentifier( * $1);2327 typedefTable.setNextIdentifier( *($1) ); 2312 2328 $$ = DeclarationNode::newName( $1 ); 2313 2329 } … … 2337 2353 ; 2338 2354 2339 // This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no identifier to2340 // which the type applies, e.g.:2355 // This pattern parses a declaration of an abstract variable or function prototype, i.e., there is no 2356 // identifier to which the type applies, e.g.: 2341 2357 // 2342 2358 // sizeof( int ); 2343 2359 // sizeof( int [10] ); 2344 2360 // 2345 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays2346 // and functions versus pointers to arrays and functions.2361 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2362 // returning arrays and functions versus pointers to arrays and functions. 2347 2363 2348 2364 abstract_declarator: … … 2410 2426 // int f( int (int) ); // abstract function-prototype parameter; no parameter name specified 2411 2427 // 2412 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays2413 // and functions versus pointers to arrays and functions.2428 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2429 // returning arrays and functions versus pointers to arrays and functions. 2414 2430 2415 2431 abstract_parameter_declarator: … … 2461 2477 // The declaration of an array parameter has additional syntax over arrays in normal variable declarations: 2462 2478 // 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." 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." 2465 2482 2466 2483 array_parameter_1st_dimension: … … 2481 2498 ; 2482 2499 2483 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type applies,2484 // e.g.:2500 // This pattern parses a declaration of an abstract variable, i.e., there is no identifier to which the type 2501 // applies, e.g.: 2485 2502 // 2486 2503 // sizeof( int ); // abstract variable; no identifier name specified 2487 2504 // 2488 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays2489 // and functions versus pointers to arrays and functions.2505 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and 2506 // returning arrays and functions versus pointers to arrays and functions. 2490 2507 2491 2508 variable_abstract_declarator: … … 2525 2542 ; 2526 2543 2527 // This pattern parses a new-style declaration for a parameter variable or function prototype that is either an2528 // identifier or typedef name and allows the C99 array options, which can only appear in a parameter list.2544 // This pattern parses a new-style declaration for a parameter variable or function prototype that is either 2545 // an identifier or typedef name and allows the C99 array options, which can only appear in a parameter list. 2529 2546 2530 2547 new_identifier_parameter_declarator_tuple: // CFA … … 2556 2573 2557 2574 new_identifier_parameter_array: // CFA 2558 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to2559 // shift/reduce conflict with new-style empty (void) function return type.2575 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due 2576 // to shift/reduce conflict with new-style empty (void) function return type. 2560 2577 '[' push pop ']' type_specifier 2561 2578 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } … … 2594 2611 ; 2595 2612 2596 // This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is no2597 // identifier to which the type applies, e.g.:2613 // This pattern parses a new-style declaration of an abstract variable or function prototype, i.e., there is 2614 // no identifier to which the type applies, e.g.: 2598 2615 // 2599 2616 // [int] f( int ); // abstract variable parameter; no parameter name specified … … 2611 2628 // 2612 2629 // Therefore, it is necessary to look at the token after identifier_or_typedef_name to know when to reduce 2613 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary2614 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are2615 // duplicated when appearing with new_function_specifier.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, and 2632 // tuple declarations are duplicated when appearing with new_function_specifier. 2616 2633 2617 2634 new_abstract_declarator_tuple: // CFA … … 2643 2660 2644 2661 new_abstract_array: // CFA 2645 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with2646 // empty (void) function return type.2662 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce 2663 // conflict with empty (void) function return type. 2647 2664 '[' push pop ']' type_specifier 2648 2665 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } … … 2673 2690 ; 2674 2691 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." 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." 2680 2698 // 2681 2699 // 3) ISO/IEC 9899:1999 Section 6.11.6(1) : "The use of function declarators with empty parentheses (not 2682 2700 // prototype-format parameter type declarators) is an obsolescent feature." 2683 2701 // 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. 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. 2686 2705 2687 2706 //************************* MISCELLANEOUS ******************************** … … 2711 2730 2712 2731 // Local Variables: // 2732 // tab-width: 4 // 2713 2733 // mode: c++ // 2714 // tab-width: 4 //2715 2734 // compile-command: "make install" // 2716 2735 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.