Changes in src/Parser/parser.yy [9706554:51e076e]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r9706554 r51e076e 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 5 11:42:23201613 // Update Count : 17 4912 // Last Modified On : Fri Aug 5 08:15:57 2016 13 // Update Count : 1721 14 14 // 15 15 … … 130 130 %type<constant> constant 131 131 %type<en> tuple tuple_expression_list 132 %type<op> ptrref_operator unary_operator assignment_operator 132 %type<op> ptrref_operator 133 %type<en> unary_operator assignment_operator 133 134 %type<en> primary_expression postfix_expression unary_expression 134 135 %type<en> cast_expression multiplicative_expression additive_expression shift_expression … … 355 356 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 356 357 // equivalent to the old x[i,j]. 357 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Index, $1, $4 ) ); }358 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Index, $1, $4 ) ); } 358 359 | postfix_expression '(' argument_expression_list ')' 359 { $$ = new CompositeExprNode 2( build_func( $1, $3 )); }360 { $$ = new CompositeExprNode( $1, $3 ); } 360 361 // ambiguity with .0 so space required after field-selection, e.g. 361 362 // struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1; … … 367 368 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 368 369 | postfix_expression ICR 369 { $$ = new CompositeExprNode2( build_ unary_ptr( OperatorNode::IncrPost, $1 ) ); }370 { $$ = new CompositeExprNode2( build_opr1( OperatorNode::IncrPost, $1 ) ); } 370 371 | postfix_expression DECR 371 { $$ = new CompositeExprNode2( build_ unary_ptr( OperatorNode::DecrPost, $1 ) ); }372 { $$ = new CompositeExprNode2( build_opr1( OperatorNode::DecrPost, $1 ) ); } 372 373 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99 373 374 { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); } 374 375 | postfix_expression '{' argument_expression_list '}' // CFA 375 376 { 376 Token fn; 377 fn.str = new std::string( "?{}" ); // location undefined 378 $$ = new CompositeExprNode2( build_func( new VarRefNode( fn ), (ExpressionNode *)( $1 )->set_link( $3 ) ) ); 377 Token fn; fn.str = new std::string( "?{}" ); // location undefined 378 $$ = new CompositeExprNode( new VarRefNode( fn ), (ExpressionNode *)( $1 )->set_link( $3 ) ); 379 379 } 380 380 ; … … 398 398 { $$ = $7->set_argName( $3 ); } 399 399 | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression 400 { $$ = $9->set_argName( new CompositeExprNode 2( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) )); }400 { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); } 401 401 ; 402 402 … … 435 435 // { * int X; } // CFA declaration of pointer to int 436 436 | ptrref_operator cast_expression // CFA 437 { 438 switch ( $1 ) { 439 case OperatorNode::AddressOf: 440 $$ = new CompositeExprNode2( build_addressOf( $2 ) ); 441 break; 442 case OperatorNode::PointTo: 443 $$ = new CompositeExprNode2( build_unary_val( $1, $2 ) ); 444 break; 445 default: 446 assert( false ); 447 } 448 } 437 { $$ = $1 == OperatorNode::AddressOf ? (ExpressionNode*) new CompositeExprNode2( build_addressOf( $2 ) ) 438 : (ExpressionNode*)new CompositeExprNode( new OperatorNode ( $1 ), $2 ); } 449 439 | unary_operator cast_expression 450 { $$ = new CompositeExprNode2( build_unary_val( $1, $2 )); }440 { $$ = new CompositeExprNode( $1, $2 ); } 451 441 | ICR unary_expression 452 { $$ = new CompositeExprNode2( build_ unary_ptr( OperatorNode::Incr, $2 ) ); }442 { $$ = new CompositeExprNode2( build_opr1( OperatorNode::Incr, $2 ) ); } 453 443 | DECR unary_expression 454 { $$ = new CompositeExprNode2( build_ unary_ptr( OperatorNode::Decr, $2 ) ); }444 { $$ = new CompositeExprNode2( build_opr1( OperatorNode::Decr, $2 ) ); } 455 445 | SIZEOF unary_expression 456 446 { $$ = new CompositeExprNode2( build_sizeOf( $2 ) ); } … … 460 450 { $$ = new CompositeExprNode2( build_offsetOf( new TypeValueNode( $3 ), new VarRefNode( $5 ) ) ); } 461 451 | ATTR_IDENTIFIER 462 { $$ = new CompositeExprNode 2( build_attr( new VarRefNode( $1 )) ); }452 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ) ); } 463 453 | ATTR_IDENTIFIER '(' type_name ')' 464 { $$ = new CompositeExprNode 2( build_attr( new VarRefNode( $1 ), new TypeValueNode( $3 )) ); }454 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 ) ); } 465 455 | ATTR_IDENTIFIER '(' argument_expression ')' 466 { $$ = new CompositeExprNode 2( build_attr( new VarRefNode( $1 ), $3 )); }456 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); } 467 457 | ALIGNOF unary_expression // GCC, variable alignment 468 458 { $$ = new CompositeExprNode2( build_alignOf( $2 ) ); } … … 477 467 | '&' { $$ = OperatorNode::AddressOf; } 478 468 // GCC, address of label must be handled by semantic check for ref,ref,label 479 //| ANDAND { $$ = OperatorNode::And; }469 | ANDAND { $$ = OperatorNode::And; } 480 470 ; 481 471 482 472 unary_operator: 483 '+' { $$ = OperatorNode::UnPlus; }484 | '-' { $$ = OperatorNode::UnMinus; }485 | '!' { $$ = OperatorNode::Neg; }486 | '~' { $$ = OperatorNode::BitNeg; }473 '+' { $$ = new OperatorNode( OperatorNode::UnPlus ); } 474 | '-' { $$ = new OperatorNode( OperatorNode::UnMinus ); } 475 | '!' { $$ = new OperatorNode( OperatorNode::Neg ); } 476 | '~' { $$ = new OperatorNode( OperatorNode::BitNeg ); } 487 477 ; 488 478 … … 498 488 cast_expression 499 489 | multiplicative_expression '*' cast_expression 500 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Mul, $1, $3 ) ); }490 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Mul, $1, $3 ) ); } 501 491 | multiplicative_expression '/' cast_expression 502 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Div, $1, $3 ) ); }492 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Div, $1, $3 ) ); } 503 493 | multiplicative_expression '%' cast_expression 504 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Mod, $1, $3 ) ); }494 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Mod, $1, $3 ) ); } 505 495 ; 506 496 … … 508 498 multiplicative_expression 509 499 | additive_expression '+' multiplicative_expression 510 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Plus, $1, $3 ) ); }500 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Plus, $1, $3 ) ); } 511 501 | additive_expression '-' multiplicative_expression 512 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Minus, $1, $3 ) ); }502 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Minus, $1, $3 ) ); } 513 503 ; 514 504 … … 516 506 additive_expression 517 507 | shift_expression LS additive_expression 518 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::LShift, $1, $3 ) ); }508 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LShift, $1, $3 ) ); } 519 509 | shift_expression RS additive_expression 520 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::RShift, $1, $3 ) ); }510 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::RShift, $1, $3 ) ); } 521 511 ; 522 512 … … 524 514 shift_expression 525 515 | relational_expression '<' shift_expression 526 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::LThan, $1, $3 ) ); }516 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LThan, $1, $3 ) ); } 527 517 | relational_expression '>' shift_expression 528 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::GThan, $1, $3 ) ); }518 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::GThan, $1, $3 ) ); } 529 519 | relational_expression LE shift_expression 530 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::LEThan, $1, $3 ) ); }520 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LEThan, $1, $3 ) ); } 531 521 | relational_expression GE shift_expression 532 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::GEThan, $1, $3 ) ); }522 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::GEThan, $1, $3 ) ); } 533 523 ; 534 524 … … 536 526 relational_expression 537 527 | equality_expression EQ relational_expression 538 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Eq, $1, $3 ) ); }528 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Eq, $1, $3 ) ); } 539 529 | equality_expression NE relational_expression 540 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Neq, $1, $3 ) ); }530 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Neq, $1, $3 ) ); } 541 531 ; 542 532 … … 544 534 equality_expression 545 535 | AND_expression '&' equality_expression 546 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::BitAnd, $1, $3 ) ); }536 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::BitAnd, $1, $3 ) ); } 547 537 ; 548 538 … … 550 540 AND_expression 551 541 | exclusive_OR_expression '^' AND_expression 552 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Xor, $1, $3 ) ); }542 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Xor, $1, $3 ) ); } 553 543 ; 554 544 … … 556 546 exclusive_OR_expression 557 547 | inclusive_OR_expression '|' exclusive_OR_expression 558 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::BitOr, $1, $3 ) ); }548 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::BitOr, $1, $3 ) ); } 559 549 ; 560 550 … … 576 566 { $$ = new CompositeExprNode2( build_cond( $1, $3, $5 ) ); } 577 567 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 578 { $$ = new CompositeExprNode 2( build_cond( $1, $1, $4 )); }568 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); } 579 569 | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression 580 570 { $$ = new CompositeExprNode2( build_cond( $1, $3, $5 ) ); } … … 588 578 // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples 589 579 conditional_expression 580 | unary_expression '=' assignment_expression 581 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); } 590 582 | unary_expression assignment_operator assignment_expression 591 { $$ = new CompositeExprNode 2( build_binary_ptr( $2, $1, $3 )); }583 { $$ = new CompositeExprNode( $2, $1, $3 ); } 592 584 | tuple assignment_opt // CFA, tuple expression 593 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode 2( build_binary_ptr( OperatorNode::Assign, $1, $2 )); }585 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); } 594 586 ; 595 587 … … 600 592 ; 601 593 602 assignment_operator:603 '=' { $$ = OperatorNode::Assign; }604 | MULTassign { $$ = OperatorNode::MulAssn; }605 | DIVassign { $$ = OperatorNode::DivAssn; }606 | MODassign { $$ = OperatorNode::ModAssn; }607 | PLUSassign { $$ = OperatorNode::PlusAssn; }608 | MINUSassign { $$ = OperatorNode::MinusAssn; }609 | LSassign { $$ = OperatorNode::LSAssn; }610 | RSassign { $$ = OperatorNode::RSAssn; }611 | ANDassign { $$ = OperatorNode::AndAssn; }612 | ERassign { $$ = OperatorNode::ERAssn; }613 | ORassign { $$ = OperatorNode::OrAssn; }614 ;615 616 594 tuple: // CFA, tuple 617 595 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with 618 596 // comma_expression in new_identifier_parameter_array and new_abstract_array 619 597 '[' ']' 620 { $$ = new CompositeExprNode 2( build_tuple() ); }598 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); } 621 599 | '[' push assignment_expression pop ']' 622 { $$ = new CompositeExprNode 2( build_tuple( $3 )); }600 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3 ); } 623 601 | '[' push ',' tuple_expression_list pop ']' 624 { $$ = new CompositeExprNode 2( build_tuple( (ExpressionNode *)(new NullExprNode)->set_link( $4 )) ); }602 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ); } 625 603 | '[' push assignment_expression ',' tuple_expression_list pop ']' 626 { $$ = new CompositeExprNode 2( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ); }604 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); } 627 605 ; 628 606 … … 633 611 ; 634 612 613 assignment_operator: 614 MULTassign { $$ = new OperatorNode( OperatorNode::MulAssn ); } 615 | DIVassign { $$ = new OperatorNode( OperatorNode::DivAssn ); } 616 | MODassign { $$ = new OperatorNode( OperatorNode::ModAssn ); } 617 | PLUSassign { $$ = new OperatorNode( OperatorNode::PlusAssn ); } 618 | MINUSassign { $$ = new OperatorNode( OperatorNode::MinusAssn ); } 619 | LSassign { $$ = new OperatorNode( OperatorNode::LSAssn ); } 620 | RSassign { $$ = new OperatorNode( OperatorNode::RSAssn ); } 621 | ANDassign { $$ = new OperatorNode( OperatorNode::AndAssn ); } 622 | ERassign { $$ = new OperatorNode( OperatorNode::ERAssn ); } 623 | ORassign { $$ = new OperatorNode( OperatorNode::OrAssn ); } 624 ; 625 635 626 comma_expression: 636 627 assignment_expression 637 | comma_expression ',' assignment_expression 628 | comma_expression ',' assignment_expression // { $$ = (ExpressionNode *)$1->add_to_list( $3 ); } 629 //{ $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Comma ), $1, $3 ); } 638 630 { $$ = new CompositeExprNode2( build_comma( $1, $3 ) ); } 639 631 ; … … 659 651 { 660 652 Token fn; fn.str = new std::string( "^?{}" ); // location undefined 661 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode2( build_func( new VarRefNode( fn ), (ExpressionNode *)( $2 )->set_link( $4 ) ) ), 0 ); 653 $$ = new StatementNode( StatementNode::Exp, new CompositeExprNode( new VarRefNode( fn ), 654 (ExpressionNode *)( $2 )->set_link( $4 ) ), 0 ); 662 655 } 663 656 ; … … 747 740 constant_expression { $$ = $1; } 748 741 | constant_expression ELLIPSIS constant_expression // GCC, subrange 749 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Range, $1, $3 ) ); }742 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Range, $1, $3 ) ); } 750 743 | subrange // CFA, subrange 751 744 ; … … 1788 1781 { $$ = new DesignatorNode( $3, true ); } 1789 1782 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 1790 { $$ = new DesignatorNode( new CompositeExprNode2( build_ binary_val( OperatorNode::Range, $3, $5 ) ), true ); }1783 { $$ = new DesignatorNode( new CompositeExprNode2( build_opr2( OperatorNode::Range, $3, $5 ) ), true ); } 1791 1784 | '.' '[' push field_list pop ']' // CFA, tuple field selector 1792 1785 { $$ = new DesignatorNode( $4 ); } … … 2117 2110 subrange: 2118 2111 constant_expression '~' constant_expression // CFA, integer subrange 2119 { $$ = new CompositeExprNode2( build_ binary_val( OperatorNode::Range, $1, $3 ) ); }2112 { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Range, $1, $3 ) ); } 2120 2113 ; 2121 2114
Note:
See TracChangeset
for help on using the changeset viewer.