Changes in src/Parser/parser.yy [e82aa9df:5d125e4]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
re82aa9df r5d125e4 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 15:18:19201613 // Update Count : 1 89112 // Last Modified On : Tue Jul 12 20:52:53 2016 13 // Update Count : 1661 14 14 // 15 15 … … 60 60 std::stack< LinkageSpec::Type > linkageStack; 61 61 TypedefTable typedefTable; 62 63 void appendStr( std::string &to, std::string *from ) {64 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.65 to.insert( to.length() - 1, from->substr( 1, from->length() - 2 ) );66 } // appendStr67 62 %} 68 63 … … 121 116 DeclarationNode::TypeClass tclass; 122 117 StatementNode *sn; 123 ConstantExpr *constant; 124 ForCtl *fctl; 118 ConstantNode *constant; 125 119 LabelNode *label; 126 120 InitializerNode *in; 127 OperKinds op;128 121 bool flag; 129 122 } … … 134 127 135 128 // expressions 136 %type< en> constant129 %type<constant> constant 137 130 %type<en> tuple tuple_expression_list 138 %type< op> ptrref_operator unary_operator assignment_operator131 %type<en> ptrref_operator unary_operator assignment_operator 139 132 %type<en> primary_expression postfix_expression unary_expression 140 133 %type<en> cast_expression multiplicative_expression additive_expression shift_expression … … 143 136 %type<en> constant_expression assignment_expression assignment_expression_opt 144 137 %type<en> comma_expression comma_expression_opt 145 %type<en> argument_expression_list argument_expression assignment_opt 146 %type<fctl> for_control_expression 138 %type<en> argument_expression_list argument_expression for_control_expression assignment_opt 147 139 %type<en> subrange 148 140 %type<en> asm_operands_opt asm_operands_list asm_operand 149 141 %type<label> label_list 150 %type< en> asm_clobbers_list_opt142 %type<constant> asm_clobbers_list_opt 151 143 %type<flag> asm_volatile_opt 152 144 … … 158 150 %type<sn> block_item_list block_item 159 151 %type<sn> case_clause 160 %type<en> case_value 161 %type<sn> case_ value_list case_label case_label_list152 %type<en> case_value case_value_list 153 %type<sn> case_label case_label_list 162 154 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 163 %type< sn> handler_list handler_clause finally_clause155 %type<pn> handler_list handler_clause finally_clause 164 156 165 157 // declarations … … 311 303 constant: 312 304 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 313 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 )); }314 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 )); }315 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 )); }305 INTEGERconstant { $$ = makeConstant( ConstantNode::Integer, $1 ); } 306 | FLOATINGconstant { $$ = makeConstant( ConstantNode::Float, $1 ); } 307 | CHARACTERconstant { $$ = makeConstant( ConstantNode::Character, $1 ); } 316 308 ; 317 309 … … 338 330 339 331 string_literal_list: // juxtaposed strings are concatenated 340 STRINGliteral { $$ = build_constantStr( *$1 ); } 341 | string_literal_list STRINGliteral 342 { 343 appendStr( $1->get_constant()->get_value(), $2 ); 344 delete $2; // allocated by lexer 345 $$ = $1; 346 } 332 STRINGliteral { $$ = makeConstantStr( ConstantNode::String, $1 ); } 333 | string_literal_list STRINGliteral { $$ = $1->appendstr( $2 ); } 347 334 ; 348 335 … … 351 338 primary_expression: 352 339 IDENTIFIER // typedef name cannot be used as a variable name 353 { $$ = new ExpressionNode( build_varref( $1 )); }340 { $$ = new VarRefNode( $1 ); } 354 341 | zero_one 355 { $$ = new ExpressionNode( build_varref( $1 )); }342 { $$ = new VarRefNode( $1 ); } 356 343 | '(' comma_expression ')' 357 344 { $$ = $2; } 358 345 | '(' compound_statement ')' // GCC, lambda expression 359 { $$ = new ExpressionNode( build_valexpr( $2 )); }346 { $$ = new ValofExprNode( $2 ); } 360 347 ; 361 348 … … 367 354 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 368 355 // equivalent to the old x[i,j]. 369 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 )); }356 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Index ), $1, $4 ); } 370 357 | postfix_expression '(' argument_expression_list ')' 371 { $$ = new ExpressionNode( build_func( $1, $3 )); }358 { $$ = new CompositeExprNode( $1, $3 ); } 372 359 // ambiguity with .0 so space required after field-selection, e.g. 373 360 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 374 361 | postfix_expression '.' no_attr_identifier 375 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) )); }362 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), $1, new VarRefNode( $3 )); } 376 363 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 377 364 | postfix_expression ARROW no_attr_identifier 378 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) )); }365 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), $1, new VarRefNode( $3 )); } 379 366 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 380 367 | postfix_expression ICR 381 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 )); }368 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::IncrPost ), $1 ); } 382 369 | postfix_expression DECR 383 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 )); }370 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::DecrPost ), $1 ); } 384 371 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 385 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true )) ); }372 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); } 386 373 | postfix_expression '{' argument_expression_list '}' // CFA 387 374 { 388 Token fn; 389 fn.str = new std::string( "?{}" ); // location undefined 390 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ); 375 Token fn; fn.str = new std::string( "?{}" ); // location undefined 376 $$ = new CompositeExprNode( new VarRefNode( fn ), (ExpressionNode *)( $1 )->set_link( $3 ) ); 391 377 } 392 378 ; … … 395 381 argument_expression 396 382 | argument_expression_list ',' argument_expression 397 { $$ = (ExpressionNode *)( $1->set_l ast( $3 )); }383 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 398 384 ; 399 385 … … 402 388 { $$ = 0; } // use default argument 403 389 | assignment_expression 390 | no_attr_identifier ':' assignment_expression 391 { $$ = $3->set_argName( $1 ); } 392 // Only a list of no_attr_identifier_or_type_name is allowed in this context. However, there is insufficient 393 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used 394 // with an appropriate semantic check. 395 | '[' push assignment_expression pop ']' ':' assignment_expression 396 { $$ = $7->set_argName( $3 ); } 397 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 398 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } 404 399 ; 405 400 406 401 field_list: // CFA, tuple field selector 407 402 field 408 | field_list ',' field { $$ = (ExpressionNode *)$1->set_l ast( $3 ); }403 | field_list ',' field { $$ = (ExpressionNode *)$1->set_link( $3 ); } 409 404 ; 410 405 411 406 field: // CFA, tuple field selector 412 407 no_attr_identifier 413 { $$ = new ExpressionNode( build_varref( $1 )); }408 { $$ = new VarRefNode( $1 ); } 414 409 // ambiguity with .0 so space required after field-selection, e.g. 415 410 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; 416 411 | no_attr_identifier '.' field 417 { $$ = new ExpressionNode( build_fieldSel( $3, build_varref( $1 ) )); }412 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $3 ); } 418 413 | no_attr_identifier '.' '[' push field_list pop ']' 419 { $$ = new ExpressionNode( build_fieldSel( $5, build_varref( $1 ) )); }414 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::FieldSel ), new VarRefNode( $1 ), $5 ); } 420 415 | no_attr_identifier ARROW field 421 { $$ = new ExpressionNode( build_pfieldSel( $3, build_varref( $1 ) )); }416 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $3 ); } 422 417 | no_attr_identifier ARROW '[' push field_list pop ']' 423 { $$ = new ExpressionNode( build_pfieldSel( $5, build_varref( $1 ) )); }418 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::PFieldSel ), new VarRefNode( $1 ), $5 ); } 424 419 ; 425 420 … … 431 426 { $$ = $1; } 432 427 | string_literal_list 433 { $$ = new ExpressionNode( $1 ); }428 { $$ = $1; } 434 429 | EXTENSION cast_expression // GCC 435 430 { $$ = $2->set_extension( true ); } 431 | ptrref_operator cast_expression // CFA 432 { $$ = new CompositeExprNode( $1, $2 ); } 436 433 // '*' ('&') is separated from unary_operator because of shift/reduce conflict in: 437 434 // { * X; } // dereference X 438 435 // { * int X; } // CFA declaration of pointer to int 439 | ptrref_operator cast_expression // CFA440 {441 switch ( $1 ) {442 case OperKinds::AddressOf:443 $$ = new ExpressionNode( build_addressOf( $2 ) );444 break;445 case OperKinds::PointTo:446 $$ = new ExpressionNode( build_unary_val( $1, $2 ) );447 break;448 default:449 assert( false );450 }451 }452 436 | unary_operator cast_expression 453 { $$ = new ExpressionNode( build_unary_val( $1, $2 )); }437 { $$ = new CompositeExprNode( $1, $2 ); } 454 438 | ICR unary_expression 455 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Incr, $2 )); }439 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Incr ), $2 ); } 456 440 | DECR unary_expression 457 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 )); }441 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Decr ), $2 ); } 458 442 | SIZEOF unary_expression 459 { $$ = new ExpressionNode( build_sizeOfexpr( $2 )); }443 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), $2 ); } 460 444 | SIZEOF '(' type_name_no_function ')' 461 { $$ = new ExpressionNode( build_sizeOftype( $3 ) ); } 445 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::SizeOf ), new TypeValueNode( $3 )); } 446 | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')' 447 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::OffsetOf ), new TypeValueNode( $3 ), new VarRefNode( $5 )); } 448 | ATTR_IDENTIFIER 449 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 )); } 450 | ATTR_IDENTIFIER '(' type_name ')' 451 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 )); } 452 | ATTR_IDENTIFIER '(' argument_expression ')' 453 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); } 462 454 | ALIGNOF unary_expression // GCC, variable alignment 463 { $$ = new ExpressionNode( build_alignOfexpr( $2 )); }455 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), $2 ); } 464 456 | ALIGNOF '(' type_name_no_function ')' // GCC, type alignment 465 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); } 466 | OFFSETOF '(' type_name_no_function ',' no_attr_identifier ')' 467 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref( $5 ) ) ); } 468 | ATTR_IDENTIFIER 469 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), nullptr ) ); } 470 | ATTR_IDENTIFIER '(' argument_expression ')' 471 { $$ = new ExpressionNode( build_attrexpr( build_varref( $1 ), $3 ) ); } 472 | ATTR_IDENTIFIER '(' type_name ')' 473 { $$ = new ExpressionNode( build_attrtype( build_varref( $1 ), $3 ) ); } 457 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::AlignOf ), new TypeValueNode( $3 ) ); } 474 458 // | ANDAND IDENTIFIER // GCC, address of label 475 // { $$ = new ExpressionNode( new OperatorNode( OperKinds::LabelAddress ), new ExpressionNode( build_varref( $2, true ) ); }459 // { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LabelAddress ), new VarRefNode( $2, true ) ); } 476 460 ; 477 461 478 462 ptrref_operator: 479 '*' { $$ = OperKinds::PointTo; }480 | '&' { $$ = OperKinds::AddressOf; }463 '*' { $$ = new OperatorNode( OperatorNode::PointTo ); } 464 | '&' { $$ = new OperatorNode( OperatorNode::AddressOf ); } 481 465 // GCC, address of label must be handled by semantic check for ref,ref,label 482 // | ANDAND { $$ = OperKinds::And; }466 | ANDAND { $$ = new OperatorNode( OperatorNode::And ); } 483 467 ; 484 468 485 469 unary_operator: 486 '+' { $$ = OperKinds::UnPlus; }487 | '-' { $$ = OperKinds::UnMinus; }488 | '!' { $$ = OperKinds::Neg; }489 | '~' { $$ = OperKinds::BitNeg; }470 '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 471 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); } 472 | '!' { $$ = new OperatorNode( OperatorNode::Neg ); } 473 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); } 490 474 ; 491 475 … … 493 477 unary_expression 494 478 | '(' type_name_no_function ')' cast_expression 495 { $$ = new ExpressionNode( build_cast( $2, $4 )); }479 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); } 496 480 | '(' type_name_no_function ')' tuple 497 { $$ = new ExpressionNode( build_cast( $2, $4 )); }481 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cast ), new TypeValueNode( $2 ), $4 ); } 498 482 ; 499 483 … … 501 485 cast_expression 502 486 | multiplicative_expression '*' cast_expression 503 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 )); }487 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mul ), $1, $3 ); } 504 488 | multiplicative_expression '/' cast_expression 505 { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 )); }489 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Div ), $1, $3 ); } 506 490 | multiplicative_expression '%' cast_expression 507 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 )); }491 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Mod ), $1, $3 ); } 508 492 ; 509 493 … … 511 495 multiplicative_expression 512 496 | additive_expression '+' multiplicative_expression 513 { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 )); }497 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Plus ), $1, $3 ); } 514 498 | additive_expression '-' multiplicative_expression 515 { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 )); }499 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Minus ), $1, $3 ); } 516 500 ; 517 501 … … 519 503 additive_expression 520 504 | shift_expression LS additive_expression 521 { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 )); }505 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LShift ), $1, $3 ); } 522 506 | shift_expression RS additive_expression 523 { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 )); }507 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::RShift ), $1, $3 ); } 524 508 ; 525 509 … … 527 511 shift_expression 528 512 | relational_expression '<' shift_expression 529 { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 )); }513 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LThan ), $1, $3 ); } 530 514 | relational_expression '>' shift_expression 531 { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 )); }515 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GThan ), $1, $3 ); } 532 516 | relational_expression LE shift_expression 533 { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 )); }517 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::LEThan ), $1, $3 ); } 534 518 | relational_expression GE shift_expression 535 { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 )); }519 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::GEThan ), $1, $3 ); } 536 520 ; 537 521 … … 539 523 relational_expression 540 524 | equality_expression EQ relational_expression 541 { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 )); }525 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Eq ), $1, $3 ); } 542 526 | equality_expression NE relational_expression 543 { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 )); }527 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Neq ), $1, $3 ); } 544 528 ; 545 529 … … 547 531 equality_expression 548 532 | AND_expression '&' equality_expression 549 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 )); }533 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::BitAnd ), $1, $3 ); } 550 534 ; 551 535 … … 553 537 AND_expression 554 538 | exclusive_OR_expression '^' AND_expression 555 { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 )); }539 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Xor ), $1, $3 ); } 556 540 ; 557 541 … … 559 543 exclusive_OR_expression 560 544 | inclusive_OR_expression '|' exclusive_OR_expression 561 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 )); }545 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::BitOr ), $1, $3 ); } 562 546 ; 563 547 … … 565 549 inclusive_OR_expression 566 550 | logical_AND_expression ANDAND inclusive_OR_expression 567 { $$ = new ExpressionNode( build_and_or( $1, $3, true )); }551 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::And ), $1, $3 ); } 568 552 ; 569 553 … … 571 555 logical_AND_expression 572 556 | logical_OR_expression OROR logical_AND_expression 573 { $$ = new ExpressionNode( build_and_or( $1, $3, false )); }557 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Or ), $1, $3 ); } 574 558 ; 575 559 … … 577 561 logical_OR_expression 578 562 | logical_OR_expression '?' comma_expression ':' conditional_expression 579 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } 580 // FIX ME: this hack computes $1 twice 563 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); } 581 564 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 582 { $$ = new ExpressionNode( build_cond( $1, $1, $4 )); }565 { $$=new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); } 583 566 | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression 584 { $$ = new ExpressionNode( build_cond( $1, $3, $5) ); }567 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Cond ), (ExpressionNode *)mkList( (*$1, *$3, *$5 ) ) ); } 585 568 ; 586 569 … … 592 575 // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples 593 576 conditional_expression 577 | unary_expression '=' assignment_expression 578 { $$ =new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); } 594 579 | unary_expression assignment_operator assignment_expression 595 { $$ = new ExpressionNode( build_binary_ptr( $2, $1, $3 )); }580 { $$ =new CompositeExprNode( $2, $1, $3 ); } 596 581 | tuple assignment_opt // CFA, tuple expression 597 { $$ = ( $2 == 0 ) ? $1 : new ExpressionNode( build_binary_ptr( OperKinds::Assign, $1, $2 )); }582 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); } 598 583 ; 599 584 600 585 assignment_expression_opt: 601 586 // empty 602 { $$ = n ullptr; }587 { $$ = new NullExprNode; } 603 588 | assignment_expression 604 ;605 606 assignment_operator:607 '=' { $$ = OperKinds::Assign; }608 | MULTassign { $$ = OperKinds::MulAssn; }609 | DIVassign { $$ = OperKinds::DivAssn; }610 | MODassign { $$ = OperKinds::ModAssn; }611 | PLUSassign { $$ = OperKinds::PlusAssn; }612 | MINUSassign { $$ = OperKinds::MinusAssn; }613 | LSassign { $$ = OperKinds::LSAssn; }614 | RSassign { $$ = OperKinds::RSAssn; }615 | ANDassign { $$ = OperKinds::AndAssn; }616 | ERassign { $$ = OperKinds::ERAssn; }617 | ORassign { $$ = OperKinds::OrAssn; }618 589 ; 619 590 … … 622 593 // comma_expression in new_identifier_parameter_array and new_abstract_array 623 594 '[' ']' 624 { $$ = new ExpressionNode( build_tuple() ); }595 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); } 625 596 | '[' push assignment_expression pop ']' 626 { $$ = new ExpressionNode( build_tuple( $3 )); }597 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3 ); } 627 598 | '[' push ',' tuple_expression_list pop ']' 628 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 )) ); }599 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ); } 629 600 | '[' push assignment_expression ',' tuple_expression_list pop ']' 630 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }601 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); } 631 602 ; 632 603 … … 634 605 assignment_expression_opt 635 606 | tuple_expression_list ',' assignment_expression_opt 636 { $$ = (ExpressionNode *)$1->set_last( $3 ); } 607 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 608 ; 609 610 assignment_operator: 611 MULTassign { $$ = new OperatorNode( OperatorNode::MulAssn ); } 612 | DIVassign { $$ = new OperatorNode( OperatorNode::DivAssn ); } 613 | MODassign { $$ = new OperatorNode( OperatorNode::ModAssn ); } 614 | PLUSassign { $$ = new OperatorNode( OperatorNode::PlusAssn ); } 615 | MINUSassign { $$ = new OperatorNode( OperatorNode::MinusAssn ); } 616 | LSassign { $$ = new OperatorNode( OperatorNode::LSAssn ); } 617 | RSassign { $$ = new OperatorNode( OperatorNode::RSAssn ); } 618 | ANDassign { $$ = new OperatorNode( OperatorNode::AndAssn ); } 619 | ERassign { $$ = new OperatorNode( OperatorNode::ERAssn ); } 620 | ORassign { $$ = new OperatorNode( OperatorNode::OrAssn ); } 637 621 ; 638 622 639 623 comma_expression: 640 624 assignment_expression 641 | comma_expression ',' assignment_expression 642 { $$ = new ExpressionNode( build_comma( $1, $3 )); }625 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); } 626 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3 ); } 643 627 ; 644 628 … … 662 646 | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA 663 647 { 664 Token fn; 665 fn.str = new std::string( "^?{}" ); // location undefined666 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ));648 Token fn; fn.str = new std::string( "^?{}" ); // location undefined 649 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ), 650 (ExpressionNode *)( $2 )->set_link( $4 ) ), 0 ); 667 651 } 668 652 ; … … 678 662 compound_statement: 679 663 '{' '}' 680 { $$ = new StatementNode( build_compound( (StatementNode *)0 )); }664 { $$ = new CompoundStmtNode( (StatementNode *)0 ); } 681 665 | '{' 682 666 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also … … 685 669 local_label_declaration_opt // GCC, local labels 686 670 block_item_list pop '}' // C99, intermix declarations and statements 687 { $$ = new StatementNode( build_compound( $5 )); }671 { $$ = new CompoundStmtNode( $5 ); } 688 672 ; 689 673 … … 691 675 block_item 692 676 | block_item_list push block_item 693 { if ( $1 != 0 ) { $1->set_l ast( $3 ); $$ = $1; } }677 { if ( $1 != 0 ) { $1->set_link( $3 ); $$ = $1; } } 694 678 ; 695 679 … … 699 683 | EXTENSION declaration // GCC 700 684 { // mark all fields in list 701 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ next() )685 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 702 686 iter->set_extension( true ); 703 687 $$ = new StatementNode( $2 ); … … 711 695 statement 712 696 | statement_list statement 713 { if ( $1 != 0 ) { $1->set_l ast( $2 ); $$ = $1; } }697 { if ( $1 != 0 ) { $1->set_link( $2 ); $$ = $1; } } 714 698 ; 715 699 716 700 expression_statement: 717 701 comma_expression_opt ';' 718 { $$ = new StatementNode( build_expr( $1 )); }702 { $$ = new StatementNode( StatementNode::Exp, $1, 0 ); } 719 703 ; 720 704 … … 722 706 IF '(' comma_expression ')' statement %prec THEN 723 707 // explicitly deal with the shift/reduce conflict on if/else 724 { $$ = new StatementNode( build_if( $3, $5, nullptr )); }708 { $$ = new StatementNode( StatementNode::If, $3, $5 ); } 725 709 | IF '(' comma_expression ')' statement ELSE statement 726 { $$ = new StatementNode( build_if( $3, $5, $7) ); }710 { $$ = new StatementNode( StatementNode::If, $3, (StatementNode *)mkList((*$5, *$7 )) ); } 727 711 | SWITCH '(' comma_expression ')' case_clause // CFA 728 { $$ = new StatementNode( build_switch( $3, $5 )); }712 { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); } 729 713 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 730 714 { 731 StatementNode *sw = new StatementNode( build_switch( $3, $8 ));715 StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 ); 732 716 // The semantics of the declaration list is changed to include associated initialization, which is performed 733 717 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound 734 718 // statement around the switch. Statements after the initial declaration list can never be executed, and 735 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 736 // statement. 737 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 719 // therefore, are removed from the grammar even though C allows it. Change also applies to choose statement. 720 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw; 738 721 } 739 722 | CHOOSE '(' comma_expression ')' case_clause // CFA 740 { $$ = new StatementNode( build_switch( $3, $5 )); }723 { $$ = new StatementNode( StatementNode::Switch, $3, $5 ); } 741 724 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 742 725 { 743 StatementNode *sw = new StatementNode( build_switch( $3, $8 ));744 $$ = $7 != 0 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw ))) ) : sw;726 StatementNode *sw = new StatementNode( StatementNode::Switch, $3, $8 ); 727 $$ = $7 != 0 ? new CompoundStmtNode( (StatementNode *)((new StatementNode( $7 ))->set_link( sw )) ) : sw; 745 728 } 746 729 ; … … 752 735 constant_expression { $$ = $1; } 753 736 | constant_expression ELLIPSIS constant_expression // GCC, subrange 754 { $$ = new ExpressionNode( build_range( $1, $3 )); }737 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); } 755 738 | subrange // CFA, subrange 756 739 ; 757 740 758 741 case_value_list: // CFA 759 case_value { $$ = new StatementNode( build_case( $1 ) ); }760 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5"761 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) )) ); }742 case_value 743 | case_value_list ',' case_value 744 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(tupleContents( $1 ))->set_link( $3 ) ); } 762 745 ; 763 746 764 747 case_label: // CFA 765 CASE case_value_list ':' { $$ = $2; }766 | DEFAULT ':' { $$ = new StatementNode( build_default()); }748 CASE case_value_list ':' { $$ = new StatementNode( StatementNode::Case, $2, 0 ); } 749 | DEFAULT ':' { $$ = new StatementNode( StatementNode::Default ); } 767 750 // A semantic check is required to ensure only one default clause per switch/choose statement. 768 751 ; … … 770 753 case_label_list: // CFA 771 754 case_label 772 | case_label_list case_label { $$ = (StatementNode *)( $1->set_l ast( $2 )); }755 | case_label_list case_label { $$ = (StatementNode *)( $1->set_link( $2 )); } 773 756 ; 774 757 775 758 case_clause: // CFA 776 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }759 case_label_list statement { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); } 777 760 ; 778 761 … … 785 768 switch_clause_list: // CFA 786 769 case_label_list statement_list 787 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }770 { $$ = $1->append_last_case( new CompoundStmtNode( $2 ) ); } 788 771 | switch_clause_list case_label_list statement_list 789 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( new StatementNode( build_compound( $3 )) ) ) ); }772 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( $3 ) ) ) ); } 790 773 ; 791 774 … … 800 783 { $$ = $1->append_last_case( $2 ); } 801 784 | case_label_list statement_list fall_through_opt 802 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last($3 ) ) ) ); }785 { $$ = $1->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$2, *$3 ) ) ) ); } 803 786 | choose_clause_list case_label_list fall_through 804 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( $3 ))); }787 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( $3 ))); } 805 788 | choose_clause_list case_label_list statement_list fall_through_opt 806 { $$ = (StatementNode *)( $1->set_l ast( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last($4 ) ) ) ) ) ); }789 { $$ = (StatementNode *)( $1->set_link( $2->append_last_case( new CompoundStmtNode( (StatementNode *)mkList( (*$3, *$4 ) ) ) ) ) ); } 807 790 ; 808 791 809 792 fall_through_opt: // CFA 810 793 // empty 811 { $$ = new StatementNode( build_branch( "", BranchStmt::Break ) ); }// insert implicit break794 { $$ = new StatementNode( StatementNode::Break ); } // insert implicit break 812 795 | fall_through 813 796 ; … … 822 805 iteration_statement: 823 806 WHILE '(' comma_expression ')' statement 824 { $$ = new StatementNode( build_while( $3, $5 )); }807 { $$ = new StatementNode( StatementNode::While, $3, $5 ); } 825 808 | DO statement WHILE '(' comma_expression ')' ';' 826 { $$ = new StatementNode( build_while( $5, $2 )); }809 { $$ = new StatementNode( StatementNode::Do, $5, $2 ); } 827 810 | FOR '(' push for_control_expression ')' statement 828 { $$ = new StatementNode( build_for( $4, $6 )); }811 { $$ = new StatementNode( StatementNode::For, $4, $6 ); } 829 812 ; 830 813 831 814 for_control_expression: 832 815 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 833 { $$ = new ForCtl ( $1, $4, $6 ); }816 { $$ = new ForCtlExprNode( $1, $4, $6 ); } 834 817 | declaration comma_expression_opt ';' comma_expression_opt // C99 835 { $$ = new ForCtl ( $1, $2, $4 ); }836 ;818 { $$ = new ForCtlExprNode( $1, $2, $4 ); } 819 ; 837 820 838 821 jump_statement: 839 822 GOTO IDENTIFIER ';' 840 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Goto )); }823 { $$ = new StatementNode( StatementNode::Goto, $2 ); } 841 824 | GOTO '*' comma_expression ';' // GCC, computed goto 842 825 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); 843 826 // whereas normal operator precedence yields goto (*i)+3; 844 { $$ = new StatementNode( build_computedgoto( $3 )); }827 { $$ = new StatementNode( StatementNode::Goto, $3 ); } 845 828 | CONTINUE ';' 846 829 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 847 { $$ = new StatementNode( build_branch( "", BranchStmt::Continue )); }830 { $$ = new StatementNode( StatementNode::Continue ); } 848 831 | CONTINUE IDENTIFIER ';' // CFA, multi-level continue 849 832 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 850 833 // the target of the transfer appears only at the start of an iteration statement. 851 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Continue ) ); delete $2; }834 { $$ = new StatementNode( StatementNode::Continue, $2 ); } 852 835 | BREAK ';' 853 836 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 854 { $$ = new StatementNode( build_branch( "", BranchStmt::Break )); }837 { $$ = new StatementNode( StatementNode::Break ); } 855 838 | BREAK IDENTIFIER ';' // CFA, multi-level exit 856 839 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 857 840 // the target of the transfer appears only at the start of an iteration statement. 858 { $$ = new StatementNode( build_branch( *$2, BranchStmt::Break ) ); delete $2; }841 { $$ = new StatementNode( StatementNode::Break, $2 ); } 859 842 | RETURN comma_expression_opt ';' 860 { $$ = new StatementNode( build_return( $2 ) ); } 861 | THROW assignment_expression_opt ';' // handles rethrow 862 { $$ = new StatementNode( build_throw( $2 ) ); } 863 | THROWRESUME assignment_expression_opt ';' // handles reresume 864 { $$ = new StatementNode( build_throw( $2 ) ); } 865 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 866 { $$ = new StatementNode( build_throw( $2 ) ); } 843 { $$ = new StatementNode( StatementNode::Return, $2, 0 ); } 844 | THROW assignment_expression_opt ';' 845 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 846 // | THROW ';' 847 // { $$ = new StatementNode( StatementNode::Throw ); } 848 | THROWRESUME assignment_expression_opt ';' 849 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 850 | THROWRESUME assignment_expression_opt AT assignment_expression ';' 851 { $$ = new StatementNode( StatementNode::Throw, $2, 0 ); } 852 // | THROWRESUME ';' 853 // { $$ = new StatementNode( StatementNode::Throw ); } 867 854 ; 868 855 869 856 exception_statement: 870 857 TRY compound_statement handler_list 871 { $$ = new StatementNode( build_try( $2, $3, 0 )); }858 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 872 859 | TRY compound_statement finally_clause 873 { $$ = new StatementNode( build_try( $2, 0, $3 )); }860 { $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); } 874 861 | TRY compound_statement handler_list finally_clause 875 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); } 862 { 863 $3->set_link( $4 ); 864 $$ = new StatementNode( StatementNode::Try, 0,(StatementNode *)(mkList((*$2,*$3 )))); 865 } 876 866 ; 877 867 878 868 handler_list: 869 // There must be at least one catch clause 879 870 handler_clause 880 871 // ISO/IEC 9899:1999 Section 15.3(6 ) If present, a "..." handler shall be the last handler for its try block. 881 872 | CATCH '(' ELLIPSIS ')' compound_statement 882 { $$ = new StatementNode( build_catch( 0, $5, true )); }873 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } 883 874 | handler_clause CATCH '(' ELLIPSIS ')' compound_statement 884 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true )) ); }875 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); } 885 876 | CATCHRESUME '(' ELLIPSIS ')' compound_statement 886 { $$ = new StatementNode( build_catch( 0, $5, true )); }877 { $$ = StatementNode::newCatchStmt( 0, $5, true ); } 887 878 | handler_clause CATCHRESUME '(' ELLIPSIS ')' compound_statement 888 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( 0, $6, true )) ); }879 { $$ = $1->set_link( StatementNode::newCatchStmt( 0, $6, true ) ); } 889 880 ; 890 881 891 882 handler_clause: 892 883 CATCH '(' push push exception_declaration pop ')' compound_statement pop 893 { $$ = new StatementNode( build_catch( $5, $8 )); }884 { $$ = StatementNode::newCatchStmt( $5, $8 ); } 894 885 | handler_clause CATCH '(' push push exception_declaration pop ')' compound_statement pop 895 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 )) ); }886 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); } 896 887 | CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 897 { $$ = new StatementNode( build_catch( $5, $8 )); }888 { $$ = StatementNode::newCatchStmt( $5, $8 ); } 898 889 | handler_clause CATCHRESUME '(' push push exception_declaration pop ')' compound_statement pop 899 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $6, $9 )) ); }890 { $$ = $1->set_link( StatementNode::newCatchStmt( $6, $9 ) ); } 900 891 ; 901 892 … … 903 894 FINALLY compound_statement 904 895 { 905 $$ = new StatementNode( build_finally( $2 ) ); 896 $$ = new StatementNode( StatementNode::Finally, 0, $2 ); 897 std::cout << "Just created a finally node" << std::endl; 906 898 } 907 899 ; … … 931 923 asm_statement: 932 924 ASM asm_volatile_opt '(' string_literal_list ')' ';' 933 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 )); }925 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, 0 ); } 934 926 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ')' ';' // remaining GCC 935 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 )); }927 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6 ); } 936 928 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ')' ';' 937 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 )); }929 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8 ); } 938 930 | ASM asm_volatile_opt '(' string_literal_list ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 939 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 )); }931 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $4, $6, $8, $10 ); } 940 932 | ASM asm_volatile_opt GOTO '(' string_literal_list ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 941 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 )); }933 { $$ = new AsmStmtNode( StatementNode::Asm, $2, $5, 0, $8, $10, $12 ); } 942 934 ; 943 935 … … 958 950 asm_operand 959 951 | asm_operands_list ',' asm_operand 960 { $$ = (ExpressionNode *)$1->set_l ast( $3 ); }952 { $$ = (ExpressionNode *)$1->set_link( $3 ); } 961 953 ; 962 954 963 955 asm_operand: // GCC 964 956 string_literal_list '(' constant_expression ')' 965 { $$ = new ExpressionNode( build_asmexpr( 0, $1, $3 )); }957 { $$ = new AsmExprNode( 0, $1, $3 ); } 966 958 | '[' constant_expression ']' string_literal_list '(' constant_expression ')' 967 { $$ = new ExpressionNode( build_asmexpr( $2, $4, $6 )); }959 { $$ = new AsmExprNode( $2, $4, $6 ); } 968 960 ; 969 961 … … 972 964 { $$ = 0; } // use default argument 973 965 | string_literal_list 974 { $$ = new ExpressionNode( $1 ); }966 { $$ = $1; } 975 967 | asm_clobbers_list_opt ',' string_literal_list 976 { $$ = ( ExpressionNode *)$1->set_last( new ExpressionNode( $3 )); }968 { $$ = (ConstantNode *)$1->set_link( $3 ); } 977 969 ; 978 970 979 971 label_list: 980 972 no_attr_identifier 981 { $$ = new LabelNode(); $$-> labels.push_back( *$1 ); }973 { $$ = new LabelNode(); $$->append_label( $1 ); } 982 974 | label_list ',' no_attr_identifier 983 { $$ = $1; $1-> labels.push_back( *$3 ); }975 { $$ = $1; $1->append_label( $3 ); } 984 976 ; 985 977 … … 1497 1489 | EXTENSION field_declaring_list ';' // GCC 1498 1490 { // mark all fields in list 1499 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ next() )1491 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 1500 1492 iter->set_extension( true ); 1501 1493 $$ = $2; … … 1743 1735 | initializer 1744 1736 | designation initializer { $$ = $2->set_designators( $1 ); } 1745 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_l ast( $3 ) ); }1737 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_link( $3 ) ); } 1746 1738 | initializer_list ',' designation initializer 1747 { $$ = (InitializerNode *)( $1->set_l ast( $4->set_designators( $3 ) ) ); }1739 { $$ = (InitializerNode *)( $1->set_link( $4->set_designators( $3 ) ) ); } 1748 1740 ; 1749 1741 … … 1761 1753 designator_list ':' // C99, CFA uses ":" instead of "=" 1762 1754 | no_attr_identifier_or_type_name ':' // GCC, field name 1763 { $$ = new ExpressionNode( build_varref( $1 )); }1755 { $$ = new VarRefNode( $1 ); } 1764 1756 ; 1765 1757 … … 1767 1759 designator 1768 1760 | designator_list designator 1769 { $$ = (ExpressionNode *)( $1->set_l ast( $2 )); }1770 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); }1761 { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1762 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); } 1771 1763 ; 1772 1764 1773 1765 designator: 1774 '.' no_attr_identifier_or_type_name // C99, field name 1775 { $$ = new ExpressionNode( build_varref( $2 ) ); } 1766 // lexer ambiguity: designator ".0" is floating-point constant or designator for name 0 only ".0" and ".1" 1767 // allowed => semantic check 1768 FLOATINGconstant 1769 { $$ = new DesignatorNode( new VarRefNode( $1 ) ); } 1770 | '.' no_attr_identifier_or_type_name // C99, field name 1771 { $$ = new DesignatorNode( new VarRefNode( $2 ) ); } 1776 1772 | '[' push assignment_expression pop ']' // C99, single array element 1777 1773 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 1778 { $$ = $3; }1774 { $$ = new DesignatorNode( $3, true ); } 1779 1775 | '[' push subrange pop ']' // CFA, multiple array elements 1780 { $$ = $3; }1776 { $$ = new DesignatorNode( $3, true ); } 1781 1777 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1782 { $$ = new ExpressionNode( build_range( $3, $5 )); }1778 { $$ = new DesignatorNode( new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $3, $5 ), true ); } 1783 1779 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1784 { $$ = $4; }1780 { $$ = new DesignatorNode( $4 ); } 1785 1781 ; 1786 1782 … … 1870 1866 type_name_list: // CFA 1871 1867 type_name 1872 { $$ = new ExpressionNode( build_typevalue( $1 )); }1868 { $$ = new TypeValueNode( $1 ); } 1873 1869 | assignment_expression 1874 1870 | type_name_list ',' type_name 1875 { $$ = (ExpressionNode *)( $1->set_l ast( new ExpressionNode( build_typevalue( $3 ) ) )); }1871 { $$ = (ExpressionNode *)( $1->set_link( new TypeValueNode( $3 ))); } 1876 1872 | type_name_list ',' assignment_expression 1877 { $$ = (ExpressionNode *)( $1->set_l ast( $3 )); }1873 { $$ = (ExpressionNode *)( $1->set_link( $3 )); } 1878 1874 ; 1879 1875 … … 2013 2009 | EXTENSION external_definition 2014 2010 { // mark all fields in list 2015 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_ next() )2011 for ( DeclarationNode *iter = $2; iter != NULL; iter = (DeclarationNode *)iter->get_link() ) 2016 2012 iter->set_extension( true ); 2017 2013 $$ = $2; … … 2109 2105 subrange: 2110 2106 constant_expression '~' constant_expression // CFA, integer subrange 2111 { $$ = new ExpressionNode( build_range( $1, $3 )); }2107 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Range ), $1, $3 ); } 2112 2108 ; 2113 2109
Note:
See TracChangeset
for help on using the changeset viewer.