Changes in / [94b1022a:ae32d96]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r94b1022a rae32d96  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 30 20:29:03 2018
    13 // Update Count     : 3432
     12// Last Modified On : Mon May 28 17:01:36 2018
     13// Update Count     : 3383
    1414//
    1515
     
    332332%type<decl> c_declaration static_assert
    333333%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    334 %type<decl> KR_parameter_list KR_parameter_list_opt
     334%type<decl> KR_declaration_list KR_declaration_list_opt
    335335
    336336%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    854854//      | '[' push assignment_expression pop ']'
    855855//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    856         '[' ',' tuple_expression_list ']'
    857                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    858         | '[' push assignment_expression pop ',' tuple_expression_list ']'
    859                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
     856        '[' push ',' tuple_expression_list pop ']'
     857                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
     858        | '[' push assignment_expression ',' tuple_expression_list pop ']'
     859                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    860860        ;
    861861
     
    909909        '{' '}'
    910910                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    911         | '{' push
     911        | '{'
     912                // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
     913                // requires its own scope.
     914          push push
    912915          local_label_declaration_opt                                           // GCC, local labels
    913916          statement_decl_list                                                           // C99, intermix declarations and statements
    914917          pop '}'
    915                 { $$ = new StatementNode( build_compound( $4 ) ); }
     918                { $$ = new StatementNode( build_compound( $5 ) ); }
    916919        ;
    917920
    918921statement_decl_list:                                                                    // C99
    919922        statement_decl
    920         | statement_decl_list statement_decl
    921                 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
     923        | statement_decl_list push statement_decl
     924                { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
    922925        ;
    923926
     
    937940                        $$ = new StatementNode( $2 );
    938941                }
    939         | statement
     942        | statement pop
    940943        ;
    941944
     
    952955
    953956selection_statement:
    954         IF '(' push if_control_expression ')' statement pop             %prec THEN
     957        IF '(' push if_control_expression ')' statement         %prec THEN
    955958                // explicitly deal with the shift/reduce conflict on if/else
    956959                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    957         | IF '(' push if_control_expression ')' statement ELSE statement pop
     960        | IF '(' push if_control_expression ')' statement ELSE statement
    958961                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
    959962        | SWITCH '(' comma_expression ')' case_clause
    960963                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    961         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     964        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    962965                {
    963966                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    971974        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    972975                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    973         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
     976        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
    974977                {
    975978                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    979982
    980983if_control_expression:
    981         comma_expression
     984        comma_expression pop
    982985                { $$ = new IfCtl( nullptr, $1 ); }
    983         | c_declaration                                                                         // no semi-colon
     986        | c_declaration pop                                                                     // no semi-colon
    984987                { $$ = new IfCtl( $1, nullptr ); }
    985         | cfa_declaration                                                                       // no semi-colon
     988        | cfa_declaration pop                                                           // no semi-colon
    986989                { $$ = new IfCtl( $1, nullptr ); }
    987990        | declaration comma_expression                                          // semi-colon separated
     
    10441047        | DO statement WHILE '(' comma_expression ')' ';'
    10451048                { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1046         | FOR '(' push for_control_expression ')' statement pop
     1049        | FOR '(' push for_control_expression ')' statement
    10471050                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10481051        ;
    10491052
    10501053for_control_expression:
    1051         comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
    1052                 { $$ = new ForCtl( $1, $3, $5 ); }
     1054        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
     1055                { $$ = new ForCtl( $1, $4, $6 ); }
    10531056        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10541057                { $$ = new ForCtl( $1, $2, $4 ); }
     
    12791282
    12801283declaration_list_opt:                                                                   // used at beginning of switch statement
     1284        pop     // empty
     1285                { $$ = nullptr; }
     1286        | declaration_list
     1287        ;
     1288
     1289declaration_list:
     1290        declaration
     1291        | declaration_list push declaration
     1292                { $$ = $1->appendList( $3 ); }
     1293        ;
     1294
     1295KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    12811296        // empty
    12821297                { $$ = nullptr; }
    1283         | declaration_list
    1284         ;
    1285 
    1286 declaration_list:
    1287         declaration
    1288         | declaration_list declaration
    1289                 { $$ = $1->appendList( $2 ); }
    1290         ;
    1291 
    1292 KR_parameter_list_opt:                                                          // used to declare parameter types in K&R style functions
    1293         // empty
    1294                 { $$ = nullptr; }
    1295         | KR_parameter_list
    1296         ;
    1297 
    1298 KR_parameter_list:
     1298        | KR_declaration_list
     1299        ;
     1300
     1301KR_declaration_list:
    12991302        push c_declaration pop ';'
    13001303                { $$ = $2; }
    1301         | KR_parameter_list push c_declaration pop ';'
     1304        | KR_declaration_list push c_declaration pop ';'
    13021305                { $$ = $1->appendList( $3 ); }
    13031306        ;
     
    13191322
    13201323declaration:                                                                                    // old & new style declarations
    1321         c_declaration ';'
    1322         | cfa_declaration ';'                                                           // CFA
     1324        c_declaration pop ';'
     1325        | cfa_declaration pop ';'                                                       // CFA
    13231326        | static_assert
    13241327        ;
     
    14281431        TYPEDEF cfa_variable_specifier
    14291432                {
    1430                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
     1433                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14311434                        $$ = $2->addTypedef();
    14321435                }
    14331436        | TYPEDEF cfa_function_specifier
    14341437                {
    1435                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
     1438                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
    14361439                        $$ = $2->addTypedef();
    14371440                }
    14381441        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14391442                {
    1440                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
     1443                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
    14411444                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14421445                }
     
    14491452        TYPEDEF type_specifier declarator
    14501453                {
    1451                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
     1454                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14521455                        $$ = $3->addType( $2 )->addTypedef();
    14531456                }
    14541457        | typedef_declaration pop ',' push declarator
    14551458                {
    1456                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
     1459                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
    14571460                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14581461                }
    14591462        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14601463                {
    1461                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
     1464                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14621465                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14631466                }
    14641467        | type_specifier TYPEDEF declarator
    14651468                {
    1466                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
     1469                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
    14671470                        $$ = $3->addType( $1 )->addTypedef();
    14681471                }
    14691472        | type_specifier TYPEDEF type_qualifier_list declarator
    14701473                {
    1471                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
     1474                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
    14721475                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14731476                }
     
    15961599
    15971600forall:
    1598         FORALL '(' type_parameter_list ')'                                      // CFA
    1599                 { $$ = DeclarationNode::newForall( $3 ); }
     1601        FORALL '(' push type_parameter_list pop ')'                                     // CFA
     1602                { $$ = DeclarationNode::newForall( $4 ); }
    16001603        ;
    16011604
     
    21892192type_parameter:                                                                                 // CFA
    21902193        type_class no_attr_identifier_or_type_name
    2191                 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
     2194                { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
    21922195          type_initializer_opt assertion_list_opt
    21932196                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22252228        | '|' '{' push trait_declaration_list pop '}'
    22262229                { $$ = $4; }
    2227         // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
    2228         //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2230        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2231                { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22292232        ;
    22302233
     
    22582261        no_attr_identifier_or_type_name
    22592262                {
    2260                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
     2263                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
    22612264                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22622265                }
    2263         | no_attr_identifier_or_type_name '(' type_parameter_list ')'
    2264                 {
    2265                         typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
    2266                         $$ = DeclarationNode::newTypeDecl( $1, $3 );
     2266        | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
     2267                {
     2268                        typedefTable.addToEnclosingScope( *$1, TYPEGENname );
     2269                        $$ = DeclarationNode::newTypeDecl( $1, $4 );
    22672270                }
    22682271        ;
    22692272
    22702273trait_specifier:                                                                                // CFA
    2271         TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
    2272                 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
    2273         | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
    2274                 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
     2274        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
     2275                { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
     2276        | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}'
     2277                { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
    22752278        ;
    22762279
     
    23102313
    23112314external_definition_list:
    2312         push external_definition pop
    2313                 { $$ = $2; }
     2315        external_definition
    23142316        | external_definition_list
    23152317                { forall = xxx; }
    2316           push external_definition pop
     2318          push external_definition
    23172319                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23182320        ;
     
    23362338                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23372339                }
    2338                         // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
    2339                         // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
    2340                         // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
    2341                         // trick works for nested extern "X"s, as each one undoes itself in the nesting.
    2342           '{' pop external_definition_list_opt push '}'
     2340          '{' external_definition_list_opt '}'
    23432341                {
    23442342                        linkage = linkageStack.top();
    23452343                        linkageStack.pop();
    2346                         $$ = $6;
     2344                        $$ = $5;
    23472345                }
    23482346        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     
    23532351        | type_qualifier_list
    23542352                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2355           '{' external_definition_list push '}'                  // CFA, namespace
    2356                 {
    2357                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2353          push '{' external_definition_list '}'                         // CFA, namespace
     2354                {
     2355                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23582356                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23592357                                        iter->addQualifiers( $1->clone() );
     
    23622360                        xxx = false;
    23632361                        delete $1;
    2364                         $$ = $4;
     2362                        $$ = $5;
    23652363                }
    23662364        | declaration_qualifier_list
    23672365                { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2368           '{' external_definition_list '}'                                       // CFA, namespace
    2369                 {
    2370                         for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2366          push '{' external_definition_list '}'                         // CFA, namespace
     2367                {
     2368                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23712369                                if ( isMangled( iter->linkage ) ) {             // ignore extern "C"
    23722370                                        iter->addQualifiers( $1->clone() );
     
    23752373                        xxx = false;
    23762374                        delete $1;
    2377                         $$ = $4;
     2375                        $$ = $5;
    23782376                }
    23792377        | declaration_qualifier_list type_qualifier_list
     
    23822380                        if ( $2->type->forall ) xxx = forall = true; // remember generic type
    23832381                }
    2384           '{' external_definition_list '}'                                      // CFA, namespace
    2385                 {
    2386                         for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     2382          push '{' external_definition_list '}'                         // CFA, namespace
     2383                {
     2384                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
    23872385                                if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C"
    23882386                                        iter->addQualifiers( $1->clone() );
     
    23932391                        delete $1;
    23942392                        delete $2;
    2395                         $$ = $5;
     2393                        $$ = $6;
    23962394                }
    23972395        ;
     
    24062404        | function_declarator compound_statement
    24072405                { $$ = $1->addFunctionBody( $2 ); }
    2408         | KR_function_declarator KR_parameter_list_opt compound_statement
     2406        | KR_function_declarator KR_declaration_list_opt compound_statement
    24092407                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    24102408        ;
     
    24462444
    24472445                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2448         | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2446        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24492447                {
    24502448                        rebindForall( $1, $2 );
     
    24522450                }
    24532451                // handles default int return type, OBSOLESCENT (see 1)
    2454         | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2452        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24552453                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24562454                // handles default int return type, OBSOLESCENT (see 1)
    2457         | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2455        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24582456                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24592457                // handles default int return type, OBSOLESCENT (see 1)
    2460         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
     2458        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24612459                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24622460        ;
     
    27032701        typedef
    27042702                // hide type name in enclosing scope by variable name
    2705                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
     2703                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
    27062704        | '(' paren_type ')'
    27072705                { $$ = $2; }
     
    31933191        '[' push cfa_abstract_parameter_list pop ']'
    31943192                { $$ = DeclarationNode::newTuple( $3 ); }
    3195         | '[' push type_specifier_nobody ELLIPSIS pop ']'
     3193        | '[' push type_specifier_nobody ELLIPSIS ']'
    31963194                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    3197         | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
     3195        | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'
    31983196                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    31993197        ;
Note: See TracChangeset for help on using the changeset viewer.