Changes in / [94b1022a:ae32d96]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r94b1022a rae32d96 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 30 20:29:03201813 // Update Count : 3 43212 // Last Modified On : Mon May 28 17:01:36 2018 13 // Update Count : 3383 14 14 // 15 15 … … 332 332 %type<decl> c_declaration static_assert 333 333 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 334 %type<decl> KR_ parameter_list KR_parameter_list_opt334 %type<decl> KR_declaration_list KR_declaration_list_opt 335 335 336 336 %type<decl> parameter_declaration parameter_list parameter_type_list_opt … … 854 854 // | '[' push assignment_expression pop ']' 855 855 // { $$ = 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 ) ) ); } 860 860 ; 861 861 … … 909 909 '{' '}' 910 910 { $$ = 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 912 915 local_label_declaration_opt // GCC, local labels 913 916 statement_decl_list // C99, intermix declarations and statements 914 917 pop '}' 915 { $$ = new StatementNode( build_compound( $ 4) ); }918 { $$ = new StatementNode( build_compound( $5 ) ); } 916 919 ; 917 920 918 921 statement_decl_list: // C99 919 922 statement_decl 920 | statement_decl_list statement_decl921 { if ( $1 != 0 ) { $1->set_last( $ 2); $$ = $1; } }923 | statement_decl_list push statement_decl 924 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } } 922 925 ; 923 926 … … 937 940 $$ = new StatementNode( $2 ); 938 941 } 939 | statement 942 | statement pop 940 943 ; 941 944 … … 952 955 953 956 selection_statement: 954 IF '(' push if_control_expression ')' statement pop%prec THEN957 IF '(' push if_control_expression ')' statement %prec THEN 955 958 // explicitly deal with the shift/reduce conflict on if/else 956 959 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 957 | IF '(' push if_control_expression ')' statement ELSE statement pop960 | IF '(' push if_control_expression ')' statement ELSE statement 958 961 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 959 962 | SWITCH '(' comma_expression ')' case_clause 960 963 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 961 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop'}' // CFA964 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 962 965 { 963 966 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); … … 971 974 | CHOOSE '(' comma_expression ')' case_clause // CFA 972 975 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 973 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop'}' // CFA976 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 974 977 { 975 978 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); … … 979 982 980 983 if_control_expression: 981 comma_expression 984 comma_expression pop 982 985 { $$ = new IfCtl( nullptr, $1 ); } 983 | c_declaration // no semi-colon986 | c_declaration pop // no semi-colon 984 987 { $$ = new IfCtl( $1, nullptr ); } 985 | cfa_declaration // no semi-colon988 | cfa_declaration pop // no semi-colon 986 989 { $$ = new IfCtl( $1, nullptr ); } 987 990 | declaration comma_expression // semi-colon separated … … 1044 1047 | DO statement WHILE '(' comma_expression ')' ';' 1045 1048 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1046 | FOR '(' push for_control_expression ')' statement pop1049 | FOR '(' push for_control_expression ')' statement 1047 1050 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1048 1051 ; 1049 1052 1050 1053 for_control_expression: 1051 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt1052 { $$ = new ForCtl( $1, $ 3, $5); }1054 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 1055 { $$ = new ForCtl( $1, $4, $6 ); } 1053 1056 | declaration comma_expression_opt ';' comma_expression_opt // C99 1054 1057 { $$ = new ForCtl( $1, $2, $4 ); } … … 1279 1282 1280 1283 declaration_list_opt: // used at beginning of switch statement 1284 pop // empty 1285 { $$ = nullptr; } 1286 | declaration_list 1287 ; 1288 1289 declaration_list: 1290 declaration 1291 | declaration_list push declaration 1292 { $$ = $1->appendList( $3 ); } 1293 ; 1294 1295 KR_declaration_list_opt: // used to declare parameter types in K&R style functions 1281 1296 // empty 1282 1297 { $$ = 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 1301 KR_declaration_list: 1299 1302 push c_declaration pop ';' 1300 1303 { $$ = $2; } 1301 | KR_ parameter_list push c_declaration pop ';'1304 | KR_declaration_list push c_declaration pop ';' 1302 1305 { $$ = $1->appendList( $3 ); } 1303 1306 ; … … 1319 1322 1320 1323 declaration: // old & new style declarations 1321 c_declaration ';'1322 | cfa_declaration ';'// CFA1324 c_declaration pop ';' 1325 | cfa_declaration pop ';' // CFA 1323 1326 | static_assert 1324 1327 ; … … 1428 1431 TYPEDEF cfa_variable_specifier 1429 1432 { 1430 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/);1433 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1431 1434 $$ = $2->addTypedef(); 1432 1435 } 1433 1436 | TYPEDEF cfa_function_specifier 1434 1437 { 1435 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/);1438 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1436 1439 $$ = $2->addTypedef(); 1437 1440 } 1438 1441 | cfa_typedef_declaration pop ',' push no_attr_identifier 1439 1442 { 1440 typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/);1443 typedefTable.addToEnclosingScope( *$5, TYPEDEFname ); 1441 1444 $$ = $1->appendList( $1->cloneType( $5 ) ); 1442 1445 } … … 1449 1452 TYPEDEF type_specifier declarator 1450 1453 { 1451 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/);1454 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1452 1455 $$ = $3->addType( $2 )->addTypedef(); 1453 1456 } 1454 1457 | typedef_declaration pop ',' push declarator 1455 1458 { 1456 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/);1459 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname ); 1457 1460 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1458 1461 } 1459 1462 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1460 1463 { 1461 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/);1464 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1462 1465 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1463 1466 } 1464 1467 | type_specifier TYPEDEF declarator 1465 1468 { 1466 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/);1469 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1467 1470 $$ = $3->addType( $1 )->addTypedef(); 1468 1471 } 1469 1472 | type_specifier TYPEDEF type_qualifier_list declarator 1470 1473 { 1471 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/);1474 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1472 1475 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1473 1476 } … … 1596 1599 1597 1600 forall: 1598 FORALL '(' type_parameter_list')' // CFA1599 { $$ = DeclarationNode::newForall( $ 3); }1601 FORALL '(' push type_parameter_list pop ')' // CFA 1602 { $$ = DeclarationNode::newForall( $4 ); } 1600 1603 ; 1601 1604 … … 2189 2192 type_parameter: // CFA 2190 2193 type_class no_attr_identifier_or_type_name 2191 { typedefTable.addTo Scope( *$2, TYPEDEFname /*, "9"*/); }2194 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); } 2192 2195 type_initializer_opt assertion_list_opt 2193 2196 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2225 2228 | '|' '{' push trait_declaration_list pop '}' 2226 2229 { $$ = $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; } 2229 2232 ; 2230 2233 … … 2258 2261 no_attr_identifier_or_type_name 2259 2262 { 2260 typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/);2263 typedefTable.addToEnclosingScope( *$1, TYPEDEFname ); 2261 2264 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2262 2265 } 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 ); 2267 2270 } 2268 2271 ; 2269 2272 2270 2273 trait_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 ); } 2275 2278 ; 2276 2279 … … 2310 2313 2311 2314 external_definition_list: 2312 push external_definition pop 2313 { $$ = $2; } 2315 external_definition 2314 2316 | external_definition_list 2315 2317 { forall = xxx; } 2316 push external_definition pop2318 push external_definition 2317 2319 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2318 2320 ; … … 2336 2338 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2337 2339 } 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 '}' 2343 2341 { 2344 2342 linkage = linkageStack.top(); 2345 2343 linkageStack.pop(); 2346 $$ = $ 6;2344 $$ = $5; 2347 2345 } 2348 2346 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown … … 2353 2351 | type_qualifier_list 2354 2352 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2355 '{' external_definition_list push '}'// CFA, namespace2356 { 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() ) { 2358 2356 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2359 2357 iter->addQualifiers( $1->clone() ); … … 2362 2360 xxx = false; 2363 2361 delete $1; 2364 $$ = $ 4;2362 $$ = $5; 2365 2363 } 2366 2364 | declaration_qualifier_list 2367 2365 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2368 '{' external_definition_list '}'// CFA, namespace2369 { 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() ) { 2371 2369 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2372 2370 iter->addQualifiers( $1->clone() ); … … 2375 2373 xxx = false; 2376 2374 delete $1; 2377 $$ = $ 4;2375 $$ = $5; 2378 2376 } 2379 2377 | declaration_qualifier_list type_qualifier_list … … 2382 2380 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2383 2381 } 2384 '{' external_definition_list '}'// CFA, namespace2385 { 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() ) { 2387 2385 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2388 2386 iter->addQualifiers( $1->clone() ); … … 2393 2391 delete $1; 2394 2392 delete $2; 2395 $$ = $ 5;2393 $$ = $6; 2396 2394 } 2397 2395 ; … … 2406 2404 | function_declarator compound_statement 2407 2405 { $$ = $1->addFunctionBody( $2 ); } 2408 | KR_function_declarator KR_ parameter_list_opt compound_statement2406 | KR_function_declarator KR_declaration_list_opt compound_statement 2409 2407 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2410 2408 ; … … 2446 2444 2447 2445 // Old-style K&R function definition, OBSOLESCENT (see 4) 2448 | declaration_specifier KR_function_declarator KR_ parameter_list_opt with_clause_opt compound_statement2446 | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2449 2447 { 2450 2448 rebindForall( $1, $2 ); … … 2452 2450 } 2453 2451 // handles default int return type, OBSOLESCENT (see 1) 2454 | type_qualifier_list KR_function_declarator KR_ parameter_list_opt with_clause_opt compound_statement2452 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2455 2453 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2456 2454 // handles default int return type, OBSOLESCENT (see 1) 2457 | declaration_qualifier_list KR_function_declarator KR_ parameter_list_opt with_clause_opt compound_statement2455 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2458 2456 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2459 2457 // 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_statement2458 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2461 2459 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2462 2460 ; … … 2703 2701 typedef 2704 2702 // hide type name in enclosing scope by variable name 2705 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/); }2703 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); } 2706 2704 | '(' paren_type ')' 2707 2705 { $$ = $2; } … … 3193 3191 '[' push cfa_abstract_parameter_list pop ']' 3194 3192 { $$ = DeclarationNode::newTuple( $3 ); } 3195 | '[' push type_specifier_nobody ELLIPSIS pop']'3193 | '[' push type_specifier_nobody ELLIPSIS ']' 3196 3194 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3197 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop']'3195 | '[' push type_specifier_nobody ELLIPSIS constant_expression ']' 3198 3196 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3199 3197 ;
Note:
See TracChangeset
for help on using the changeset viewer.