Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r9706554 r51e076e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug  5 11:42:23 2016
    13 // Update Count     : 1749
     12// Last Modified On : Fri Aug  5 08:15:57 2016
     13// Update Count     : 1721
    1414//
    1515
     
    130130%type<constant> constant
    131131%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
    133134%type<en> primary_expression                    postfix_expression                      unary_expression
    134135%type<en> cast_expression                               multiplicative_expression       additive_expression                     shift_expression
     
    355356                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    356357                // 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 ) ); }
    358359        | postfix_expression '(' argument_expression_list ')'
    359                 { $$ = new CompositeExprNode2( build_func( $1, $3 ) ); }
     360                { $$ = new CompositeExprNode( $1, $3 ); }
    360361        // ambiguity with .0 so space required after field-selection, e.g.
    361362                //   struct S { int 0, 1; } s; s. 0 = 0; s. 1 = 1;
     
    367368        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
    368369        | postfix_expression ICR
    369                 { $$ = new CompositeExprNode2( build_unary_ptr( OperatorNode::IncrPost, $1 ) ); }
     370                { $$ = new CompositeExprNode2( build_opr1( OperatorNode::IncrPost, $1 ) ); }
    370371        | postfix_expression DECR
    371                 { $$ = new CompositeExprNode2( build_unary_ptr( OperatorNode::DecrPost, $1 ) ); }
     372                { $$ = new CompositeExprNode2( build_opr1( OperatorNode::DecrPost, $1 ) ); }
    372373        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99
    373374                { $$ = new CompoundLiteralNode( $2, new InitializerNode( $5, true ) ); }
    374375        | postfix_expression '{' argument_expression_list '}' // CFA
    375376                {
    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 ) );
    379379                }
    380380        ;
     
    398398                { $$ = $7->set_argName( $3 ); }
    399399        | '[' push assignment_expression ',' tuple_expression_list pop ']' ':' assignment_expression
    400                 { $$ = $9->set_argName( new CompositeExprNode2( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ) ); }
     400                { $$ = $9->set_argName( new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 )))); }
    401401        ;
    402402
     
    435435                //              { * int X; } // CFA declaration of pointer to int
    436436        | 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 ); }
    449439        | unary_operator cast_expression
    450                         { $$ = new CompositeExprNode2( build_unary_val( $1, $2 ) ); }
     440                { $$ = new CompositeExprNode( $1, $2 ); }
    451441        | ICR unary_expression
    452                 { $$ = new CompositeExprNode2( build_unary_ptr( OperatorNode::Incr, $2 ) ); }
     442                { $$ = new CompositeExprNode2( build_opr1( OperatorNode::Incr, $2 ) ); }
    453443        | DECR unary_expression
    454                 { $$ = new CompositeExprNode2( build_unary_ptr( OperatorNode::Decr, $2 ) ); }
     444                { $$ = new CompositeExprNode2( build_opr1( OperatorNode::Decr, $2 ) ); }
    455445        | SIZEOF unary_expression
    456446                { $$ = new CompositeExprNode2( build_sizeOf( $2 ) ); }
     
    460450                { $$ = new CompositeExprNode2( build_offsetOf( new TypeValueNode( $3 ), new VarRefNode( $5 ) ) ); }
    461451        | ATTR_IDENTIFIER
    462                 { $$ = new CompositeExprNode2( build_attr( new VarRefNode( $1 ) ) ); }
     452                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ) ); }
    463453        | ATTR_IDENTIFIER '(' type_name ')'
    464                 { $$ = new CompositeExprNode2( build_attr( new VarRefNode( $1 ), new TypeValueNode( $3 ) ) ); }
     454                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), new TypeValueNode( $3 ) ); }
    465455        | ATTR_IDENTIFIER '(' argument_expression ')'
    466                 { $$ = new CompositeExprNode2( build_attr( new VarRefNode( $1 ), $3 ) ); }
     456                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Attr ), new VarRefNode( $1 ), $3 ); }
    467457        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    468458                { $$ = new CompositeExprNode2( build_alignOf( $2 ) ); }
     
    477467        | '&'                                                                           { $$ = OperatorNode::AddressOf; }
    478468                // GCC, address of label must be handled by semantic check for ref,ref,label
    479 //      | ANDAND                                                                        { $$ = OperatorNode::And; }
     469        | ANDAND                                                                        { $$ = OperatorNode::And; }
    480470        ;
    481471
    482472unary_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 ); }
    487477        ;
    488478
     
    498488        cast_expression
    499489        | multiplicative_expression '*' cast_expression
    500                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Mul, $1, $3 ) ); }
     490                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Mul, $1, $3 ) ); }
    501491        | multiplicative_expression '/' cast_expression
    502                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Div, $1, $3 ) ); }
     492                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Div, $1, $3 ) ); }
    503493        | multiplicative_expression '%' cast_expression
    504                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Mod, $1, $3 ) ); }
     494                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Mod, $1, $3 ) ); }
    505495        ;
    506496
     
    508498        multiplicative_expression
    509499        | additive_expression '+' multiplicative_expression
    510                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Plus, $1, $3 ) ); }
     500                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Plus, $1, $3 ) ); }
    511501        | additive_expression '-' multiplicative_expression
    512                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Minus, $1, $3 ) ); }
     502                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Minus, $1, $3 ) ); }
    513503        ;
    514504
     
    516506        additive_expression
    517507        | shift_expression LS additive_expression
    518                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::LShift, $1, $3 ) ); }
     508                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LShift, $1, $3 ) ); }
    519509        | shift_expression RS additive_expression
    520                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::RShift, $1, $3 ) ); }
     510                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::RShift, $1, $3 ) ); }
    521511        ;
    522512
     
    524514        shift_expression
    525515        | relational_expression '<' shift_expression
    526                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::LThan, $1, $3 ) ); }
     516                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LThan, $1, $3 ) ); }
    527517        | relational_expression '>' shift_expression
    528                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::GThan, $1, $3 ) ); }
     518                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::GThan, $1, $3 ) ); }
    529519        | relational_expression LE shift_expression
    530                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::LEThan, $1, $3 ) ); }
     520                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::LEThan, $1, $3 ) ); }
    531521        | relational_expression GE shift_expression
    532                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::GEThan, $1, $3 ) ); }
     522                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::GEThan, $1, $3 ) ); }
    533523        ;
    534524
     
    536526        relational_expression
    537527        | equality_expression EQ relational_expression
    538                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Eq, $1, $3 ) ); }
     528                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Eq, $1, $3 ) ); }
    539529        | equality_expression NE relational_expression
    540                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Neq, $1, $3 ) ); }
     530                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Neq, $1, $3 ) ); }
    541531        ;
    542532
     
    544534        equality_expression
    545535        | AND_expression '&' equality_expression
    546                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::BitAnd, $1, $3 ) ); }
     536                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::BitAnd, $1, $3 ) ); }
    547537        ;
    548538
     
    550540        AND_expression
    551541        | exclusive_OR_expression '^' AND_expression
    552                 { $$ = new CompositeExprNode2( build_binary_val( OperatorNode::Xor, $1, $3 ) ); }
     542                { $$ = new CompositeExprNode2( build_opr2( OperatorNode::Xor, $1, $3 ) ); }
    553543        ;
    554544
     
    556546        exclusive_OR_expression
    557547        | 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 ) ); }
    559549        ;
    560550
     
    576566                { $$ = new CompositeExprNode2( build_cond( $1, $3, $5 ) ); }
    577567        | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand
    578                 { $$ = new CompositeExprNode2( build_cond( $1, $1, $4 ) ); }
     568                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::NCond ), $1, $4 ); }
    579569        | logical_OR_expression '?' comma_expression ':' tuple // CFA, tuple expression
    580570                { $$ = new CompositeExprNode2( build_cond( $1, $3, $5 ) ); }
     
    588578                // CFA, assignment is separated from assignment_operator to ensure no assignment operations for tuples
    589579        conditional_expression
     580        | unary_expression '=' assignment_expression
     581                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $3 ); }
    590582        | unary_expression assignment_operator assignment_expression
    591                 { $$ = new CompositeExprNode2( build_binary_ptr( $2, $1, $3 ) ); }
     583                { $$ = new CompositeExprNode( $2, $1, $3 ); }
    592584        | tuple assignment_opt                                                          // CFA, tuple expression
    593                 { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode2( build_binary_ptr( OperatorNode::Assign, $1, $2 ) ); }
     585                { $$ = ( $2 == 0 ) ? $1 : new CompositeExprNode( new OperatorNode( OperatorNode::Assign ), $1, $2 ); }
    594586        ;
    595587
     
    600592        ;
    601593
    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 
    616594tuple:                                                                                                  // CFA, tuple
    617595                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
    618596                // comma_expression in new_identifier_parameter_array and new_abstract_array
    619597        '[' ']'
    620                 { $$ = new CompositeExprNode2( build_tuple() ); }
     598                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); }
    621599        | '[' push assignment_expression pop ']'
    622                 { $$ = new CompositeExprNode2( build_tuple( $3 ) ); }
     600                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), $3 ); }
    623601        | '[' push ',' tuple_expression_list pop ']'
    624                 { $$ = new CompositeExprNode2( build_tuple( (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ) ); }
     602                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)(new NullExprNode)->set_link( $4 ) ); }
    625603        | '[' push assignment_expression ',' tuple_expression_list pop ']'
    626                 { $$ = new CompositeExprNode2( build_tuple( (ExpressionNode *)$3->set_link( $5 ) ) ); }
     604                { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ), (ExpressionNode *)$3->set_link( flattenCommas( $5 ) ) ); }
    627605        ;
    628606
     
    633611        ;
    634612
     613assignment_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
    635626comma_expression:
    636627        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 ); }
    638630                { $$ = new CompositeExprNode2( build_comma( $1, $3 ) ); }
    639631        ;
     
    659651                {
    660652                        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 );
    662655                }
    663656        ;
     
    747740        constant_expression                                                     { $$ = $1; }
    748741        | 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 ) ); }
    750743        | subrange                                                                                      // CFA, subrange
    751744        ;
     
    17881781                { $$ = new DesignatorNode( $3, true ); }
    17891782        | '[' 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 ); }
    17911784        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
    17921785                { $$ = new DesignatorNode( $4 ); }
     
    21172110subrange:
    21182111        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 ) ); }
    21202113        ;
    21212114
Note: See TracChangeset for help on using the changeset viewer.