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