Changes in src/Parser/parser.yy [2871210:de62360d]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (44 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r2871210 rde62360d 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 3 13:53:45201513 // Update Count : 1 22012 // Last Modified On : Mon Jun 22 15:19:44 2015 13 // Update Count : 1082 14 14 // 15 15 … … 118 118 119 119 %type<tok> zero_one identifier no_attr_identifier no_01_identifier 120 %type<tok> identifier_or_type _name no_attr_identifier_or_type_name no_01_identifier_or_type_name120 %type<tok> identifier_or_typedef_name no_attr_identifier_or_typedef_name no_01_identifier_or_typedef_name 121 121 %type<constant> string_literal_list 122 122 … … 204 204 %type<decl> parameter_type_list_opt 205 205 206 %type<decl> paren_identifier paren_type 206 %type<decl> paren_identifier paren_typedef 207 207 208 208 %type<decl> storage_class storage_class_name storage_class_list … … 213 213 %type<decl> type_declarator type_declarator_name type_declaring_list 214 214 215 %type<decl> typedef type _array typedef_declaration typedef_declaration_specifier typedef_expression216 %type<decl> type _function type_parameter_array type_parameter_function type_parameter_ptr217 %type<decl> type _parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier218 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name215 %type<decl> typedef typedef_array typedef_declaration typedef_declaration_specifier typedef_expression 216 %type<decl> typedef_function typedef_parameter_array typedef_parameter_function typedef_parameter_ptr 217 %type<decl> typedef_parameter_redeclarator typedef_ptr typedef_redeclarator typedef_type_specifier 218 %type<decl> typegen_declaration_specifier typegen_type_specifier 219 219 220 220 %type<decl> type_name type_name_no_function … … 376 376 | no_attr_identifier ':' assignment_expression 377 377 { $$ = $3->set_asArgName( $1 ); } 378 // Only a list of no_attr_identifier_or_type _name is allowed in this context. However, there is insufficient378 // Only a list of no_attr_identifier_or_typedef_name is allowed in this context. However, there is insufficient 379 379 // look ahead to distinguish between this list of parameter names and a tuple, so the tuple form must be used 380 380 // with an appropriate semantic check. … … 564 564 // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with 565 565 // comma_expression in new_identifier_parameter_array and new_abstract_array 566 '[' ']'566 '[' push pop ']' 567 567 { $$ = new CompositeExprNode( new OperatorNode( OperatorNode::TupleC ) ); } 568 568 | '[' push assignment_expression pop ']' … … 924 924 925 925 label_list: // GCC, local label 926 no_attr_identifier_or_type _name {}927 | label_list ',' no_attr_identifier_or_type _name {}926 no_attr_identifier_or_typedef_name {} 927 | label_list ',' no_attr_identifier_or_typedef_name {} 928 928 ; 929 929 … … 965 965 $$ = $2->addQualifiers( $1 ); 966 966 } 967 | new_variable_declaration pop ',' push identifier_or_type _name initializer_opt967 | new_variable_declaration pop ',' push identifier_or_typedef_name initializer_opt 968 968 { 969 969 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); … … 975 975 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 976 976 // storage-class 977 new_abstract_declarator_no_tuple identifier_or_type _name asm_name_opt977 new_abstract_declarator_no_tuple identifier_or_typedef_name asm_name_opt 978 978 { 979 979 typedefTable.setNextIdentifier( *$2 ); 980 980 $$ = $1->addName( $2 ); 981 981 } 982 | new_abstract_tuple identifier_or_type _name asm_name_opt982 | new_abstract_tuple identifier_or_typedef_name asm_name_opt 983 983 { 984 984 typedefTable.setNextIdentifier( *$2 ); 985 985 $$ = $1->addName( $2 ); 986 986 } 987 | type_qualifier_list new_abstract_tuple identifier_or_type _name asm_name_opt987 | type_qualifier_list new_abstract_tuple identifier_or_typedef_name asm_name_opt 988 988 { 989 989 typedefTable.setNextIdentifier( *$3 ); … … 1013 1013 $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); 1014 1014 } 1015 | new_function_declaration pop ',' push identifier_or_type _name1015 | new_function_declaration pop ',' push identifier_or_typedef_name 1016 1016 { 1017 1017 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); … … 1021 1021 1022 1022 new_function_specifier: // CFA 1023 '[' ']' identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' // S/R conflict 1024 { 1025 $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); 1026 } 1027 // '[' ']' identifier '(' push new_parameter_type_list_opt pop ')' 1028 // { 1029 // typedefTable.setNextIdentifier( *$5 ); 1030 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1031 // } 1032 // | '[' ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')' 1033 // { 1034 // typedefTable.setNextIdentifier( *$5 ); 1035 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1036 // } 1037 // | '[' ']' typegen_name 1038 // identifier_or_type_name must be broken apart because of the sequence: 1023 '[' push pop ']' identifier '(' push new_parameter_type_list_opt pop ')' 1024 { 1025 typedefTable.setNextIdentifier( *( $5 ) ); 1026 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1027 } 1028 | '[' push pop ']' TYPEDEFname '(' push new_parameter_type_list_opt pop ')' 1029 { 1030 typedefTable.setNextIdentifier( *( $5 ) ); 1031 $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1032 } 1033 // identifier_or_typedef_name must be broken apart because of the sequence: 1039 1034 // 1040 // '[' ']' identifier_or_type _name '(' new_parameter_type_list_opt ')'1035 // '[' ']' identifier_or_typedef_name '(' new_parameter_type_list_opt ')' 1041 1036 // '[' ']' type_specifier 1042 1037 // 1043 // type_specifier can resolve to just TYPEDEFname (e.g. ,typedef int T; int f( T );). Therefore this must be1044 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type _name.1045 | new_abstract_tuple identifier_or_type _name '(' push new_parameter_type_list_opt pop ')'1038 // type_specifier can resolve to just TYPEDEFname (e.g. typedef int T; int f( T );). Therefore this must be 1039 // flattened to allow lookahead to the '(' without having to reduce identifier_or_typedef_name. 1040 | new_abstract_tuple identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')' 1046 1041 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator). 1047 1042 { 1048 1043 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); 1049 1044 } 1050 | new_function_return identifier_or_type _name '(' push new_parameter_type_list_opt pop ')'1045 | new_function_return identifier_or_typedef_name '(' push new_parameter_type_list_opt pop ')' 1051 1046 { 1052 1047 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); … … 1112 1107 ; 1113 1108 1114 typedef_expression: 1115 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1109 typedef_expression: // GCC, naming expression type 1116 1110 TYPEDEF no_attr_identifier '=' assignment_expression 1117 1111 { … … 1361 1355 aggregate_name: 1362 1356 aggregate_key '{' field_declaration_list '}' 1363 { $$ = DeclarationNode::newAggregate( $1, 0, 0, $3 ); } 1364 | aggregate_key no_attr_identifier_or_type_name 1365 { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0 ); } 1366 | aggregate_key no_attr_identifier_or_type_name '{' field_declaration_list '}' 1367 { $$ = DeclarationNode::newAggregate( $1, $2, 0, $4 ); } 1368 | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1369 { $$ = DeclarationNode::newAggregate( $1, 0, $3, $6 ); } 1370 | aggregate_key typegen_name // CFA, S/R conflict 1371 { $$ = $2; } 1357 { $$ = DeclarationNode::newAggregate( $1, 0, 0, 0, $3 ); } 1358 | aggregate_key no_attr_identifier_or_typedef_name 1359 { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, 0 ); } 1360 | aggregate_key no_attr_identifier_or_typedef_name '{' field_declaration_list '}' 1361 { $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, $4 ); } 1362 | aggregate_key '(' push type_parameter_list pop ')' '{' field_declaration_list '}' // CFA 1363 { $$ = DeclarationNode::newAggregate( $1, 0, $4, 0, $8 ); } 1364 | aggregate_key '(' push type_parameter_list pop ')' no_attr_identifier_or_typedef_name // CFA 1365 { $$ = DeclarationNode::newAggregate( $1, $7, $4, 0, 0 ); } 1366 | aggregate_key '(' push type_parameter_list pop ')' no_attr_identifier_or_typedef_name '{' field_declaration_list '}' // CFA 1367 { $$ = DeclarationNode::newAggregate( $1, $7, $4, 0, $9 ); } 1368 | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1369 { $$ = DeclarationNode::newAggregate( $1, 0, $4, $8, $11 ); } 1370 | aggregate_key TYPEGENname '(' type_name_list ')' // CFA 1371 {} 1372 | aggregate_key '(' push type_name_list pop ')' no_attr_identifier_or_typedef_name // CFA 1373 // push and pop are only to prevent S/R conflicts 1374 { $$ = DeclarationNode::newAggregate( $1, $7, 0, $4, 0 ); } 1375 | aggregate_key '(' push type_parameter_list pop ')' '(' type_name_list ')' no_attr_identifier_or_typedef_name '{' field_declaration_list '}' // CFA 1376 { $$ = DeclarationNode::newAggregate( $1, $10, $4, $8, $12 ); } 1372 1377 ; 1373 1378 … … 1397 1402 new_field_declaring_list: // CFA, new style field declaration 1398 1403 new_abstract_declarator_tuple // CFA, no field name 1399 | new_abstract_declarator_tuple no_attr_identifier_or_type _name1404 | new_abstract_declarator_tuple no_attr_identifier_or_typedef_name 1400 1405 { $$ = $1->addName( $2 ); } 1401 | new_field_declaring_list ',' no_attr_identifier_or_type _name1406 | new_field_declaring_list ',' no_attr_identifier_or_typedef_name 1402 1407 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 1403 1408 | new_field_declaring_list ',' // CFA, no field name … … 1420 1425 // A semantic check is required to ensure bit_subrange only appears on base type int. 1421 1426 { $$ = $1->addBitfield( $2 ); } 1422 | type _redeclarator bit_subrange_size_opt1427 | typedef_redeclarator bit_subrange_size_opt 1423 1428 // A semantic check is required to ensure bit_subrange only appears on base type int. 1424 1429 { $$ = $1->addBitfield( $2 ); } … … 1445 1450 enum_key '{' enumerator_list comma_opt '}' 1446 1451 { $$ = DeclarationNode::newEnum( 0, $3 ); } 1447 | enum_key no_attr_identifier_or_type _name '{' enumerator_list comma_opt '}'1452 | enum_key no_attr_identifier_or_typedef_name '{' enumerator_list comma_opt '}' 1448 1453 { $$ = DeclarationNode::newEnum( $2, $4 ); } 1449 | enum_key no_attr_identifier_or_type _name1454 | enum_key no_attr_identifier_or_typedef_name 1450 1455 { $$ = DeclarationNode::newEnum( $2, 0 ); } 1451 1456 ; 1452 1457 1453 1458 enumerator_list: 1454 no_attr_identifier_or_type _name enumerator_value_opt1459 no_attr_identifier_or_typedef_name enumerator_value_opt 1455 1460 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } 1456 | enumerator_list ',' no_attr_identifier_or_type _name enumerator_value_opt1461 | enumerator_list ',' no_attr_identifier_or_typedef_name enumerator_value_opt 1457 1462 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } 1458 1463 ; … … 1524 1529 1525 1530 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics 1526 // for typedef name by using type _parameter_redeclarator instead of typedef_redeclarator, and function prototypes.1531 // for typedef name by using typedef_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. 1527 1532 1528 1533 new_parameter_declaration: // CFA, new & old style parameter declaration 1529 1534 parameter_declaration 1530 | new_identifier_parameter_declarator_no_tuple identifier_or_type _name assignment_opt1535 | new_identifier_parameter_declarator_no_tuple identifier_or_typedef_name assignment_opt 1531 1536 { $$ = $1->addName( $2 ); } 1532 | new_abstract_tuple identifier_or_type _name assignment_opt1537 | new_abstract_tuple identifier_or_typedef_name assignment_opt 1533 1538 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator). 1534 1539 { $$ = $1->addName( $2 ); } 1535 | type_qualifier_list new_abstract_tuple identifier_or_type _name assignment_opt1540 | type_qualifier_list new_abstract_tuple identifier_or_typedef_name assignment_opt 1536 1541 { $$ = $2->addName( $3 )->addQualifiers( $1 ); } 1537 1542 | new_function_specifier … … 1554 1559 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); 1555 1560 } 1556 | declaration_specifier type _parameter_redeclarator assignment_opt1561 | declaration_specifier typedef_parameter_redeclarator assignment_opt 1557 1562 { 1558 1563 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 1578 1583 ; 1579 1584 1580 identifier_or_type _name:1585 identifier_or_typedef_name: 1581 1586 identifier 1582 1587 | TYPEDEFname … … 1584 1589 ; 1585 1590 1586 no_01_identifier_or_type _name:1591 no_01_identifier_or_typedef_name: 1587 1592 no_01_identifier 1588 1593 | TYPEDEFname … … 1590 1595 ; 1591 1596 1592 no_attr_identifier_or_type _name:1597 no_attr_identifier_or_typedef_name: 1593 1598 no_attr_identifier 1594 1599 | TYPEDEFname 1595 | TYPEGENname1600 // | TYPEGENname 1596 1601 ; 1597 1602 … … 1614 1619 // empty 1615 1620 { $$ = 0; } 1616 | '=' initializer 1617 { $$ = $2; } 1621 | '=' initializer { $$ = $2; } 1618 1622 ; 1619 1623 … … 1643 1647 designation: 1644 1648 designator_list ':' // C99, CFA uses ":" instead of "=" 1645 | no_attr_identifier_or_type _name ':'// GCC, field name1646 { $$ = new VarRefNode( $1 ); }1649 | no_attr_identifier_or_typedef_name ':' // GCC, field name 1650 { $$ = new VarRefNode( $1 ); } 1647 1651 ; 1648 1652 1649 1653 designator_list: // C99 1650 1654 designator 1651 | designator_list designator 1652 { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1655 | designator_list designator { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1653 1656 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); } 1654 1657 ; 1655 1658 1656 1659 designator: 1657 '.' no_attr_identifier_or_type _name// C99, field name1660 '.' no_attr_identifier_or_typedef_name // C99, field name 1658 1661 { $$ = new VarRefNode( $2 ); } 1659 1662 | '[' push assignment_expression pop ']' // C99, single array element … … 1697 1700 1698 1701 typegen_type_specifier: // CFA 1699 typegen_name 1700 | type_qualifier_list typegen_name 1701 { $$ = $2->addQualifiers( $1 ); } 1702 TYPEGENname '(' type_name_list ')' 1703 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); } 1704 | type_qualifier_list TYPEGENname '(' type_name_list ')' 1705 { $$ = DeclarationNode::newFromTypeGen( $2, $4 )->addQualifiers( $1 ); } 1702 1706 | typegen_type_specifier type_qualifier 1703 1707 { $$ = $1->addQualifiers( $2 ); } 1704 ;1705 1706 typegen_name: // CFA1707 TYPEGENname '(' type_name_list ')'1708 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); }1709 1708 ; 1710 1709 … … 1716 1715 1717 1716 type_parameter: // CFA 1718 type_class no_attr_identifier_or_type _name1719 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); }1717 type_class no_attr_identifier_or_typedef_name 1718 { typedefTable.addToEnclosingScope(*( $2 ), TypedefTable::TD ); } 1720 1719 assertion_list_opt 1721 1720 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); } … … 1740 1739 1741 1740 assertion: // CFA 1742 '|' no_attr_identifier_or_type _name '(' type_name_list ')'1743 { 1744 typedefTable.openContext( * $2);1741 '|' no_attr_identifier_or_typedef_name '(' type_name_list ')' 1742 { 1743 typedefTable.openContext( *( $2 ) ); 1745 1744 $$ = DeclarationNode::newContextUse( $2, $4 ); 1746 1745 } … … 1778 1777 1779 1778 type_declarator_name: // CFA 1780 no_attr_identifier_or_type _name1779 no_attr_identifier_or_typedef_name 1781 1780 { 1782 1781 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD ); 1783 1782 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 1784 1783 } 1785 | no_01_identifier_or_type _name '(' push type_parameter_list pop ')'1784 | no_01_identifier_or_typedef_name '(' push type_parameter_list pop ')' 1786 1785 { 1787 1786 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); … … 1791 1790 1792 1791 context_specifier: // CFA 1793 CONTEXT no_attr_identifier_or_type _name '(' push type_parameter_list pop ')' '{' '}'1792 CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' '}' 1794 1793 { 1795 1794 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 1796 1795 $$ = DeclarationNode::newContext( $2, $5, 0 ); 1797 1796 } 1798 | CONTEXT no_attr_identifier_or_type _name '(' push type_parameter_list pop ')' '{'1797 | CONTEXT no_attr_identifier_or_typedef_name '(' push type_parameter_list pop ')' '{' 1799 1798 { 1800 1799 typedefTable.enterContext( *$2 ); … … 1831 1830 $$ = $1; 1832 1831 } 1833 | new_context_declaring_list pop ',' push identifier_or_type _name1832 | new_context_declaring_list pop ',' push identifier_or_typedef_name 1834 1833 { 1835 1834 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); … … 1900 1899 external_function_definition: 1901 1900 function_definition 1901 1902 1902 // These rules are a concession to the "implicit int" type_specifier because there is a significant amount of 1903 1903 // code with functions missing a type-specifier on the return type. Parsing is possible because … … 1982 1982 variable_declarator 1983 1983 | function_declarator 1984 | type _redeclarator1984 | typedef_redeclarator 1985 1985 ; 1986 1986 … … 2021 2021 2022 2022 any_word: // GCC 2023 identifier_or_type _name {}2023 identifier_or_typedef_name {} 2024 2024 | storage_class_name {} 2025 2025 | basic_type_name {} … … 2103 2103 // This pattern parses a function declarator that is not redefining a typedef name. Because functions cannot be nested, 2104 2104 // there is no context where a function definition can redefine a typedef name. To allow nested functions requires 2105 // further separation of variable and function declarators in type _redeclarator. The pattern precludes returning2105 // further separation of variable and function declarators in typedef_redeclarator. The pattern precludes returning 2106 2106 // arrays and functions versus pointers to arrays and functions. 2107 2107 … … 2176 2176 ; 2177 2177 2178 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.:2178 // This pattern parses a declaration for a variable or function prototype that redefines a typedef name, e.g.: 2179 2179 // 2180 2180 // typedef int foo; … … 2186 2186 // and functions versus pointers to arrays and functions. 2187 2187 2188 type_redeclarator: 2189 paren_type attribute_list_opt 2190 | type_ptr 2191 | type_array attribute_list_opt 2192 | type_function attribute_list_opt 2193 ; 2194 2195 paren_type: 2196 typedef 2197 | '(' paren_type ')' 2198 { $$ = $2; } 2199 ; 2200 2201 type_ptr: 2202 '*' type_redeclarator 2188 typedef_redeclarator: 2189 paren_typedef attribute_list_opt 2190 | typedef_ptr 2191 | typedef_array attribute_list_opt 2192 | typedef_function attribute_list_opt 2193 ; 2194 2195 paren_typedef: 2196 TYPEDEFname 2197 { 2198 typedefTable.setNextIdentifier( *( $1 ) ); 2199 $$ = DeclarationNode::newName( $1 ); 2200 } 2201 | '(' paren_typedef ')' 2202 { $$ = $2; } 2203 ; 2204 2205 typedef_ptr: 2206 '*' typedef_redeclarator 2203 2207 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2204 | '*' type_qualifier_list type _redeclarator2208 | '*' type_qualifier_list typedef_redeclarator 2205 2209 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2206 | '(' type _ptr ')'2207 { $$ = $2; } 2208 ; 2209 2210 type _array:2211 paren_type array_dimension2210 | '(' typedef_ptr ')' 2211 { $$ = $2; } 2212 ; 2213 2214 typedef_array: 2215 paren_typedef array_dimension 2212 2216 { $$ = $1->addArray( $2 ); } 2213 | '(' type _ptr ')' array_dimension2217 | '(' typedef_ptr ')' array_dimension 2214 2218 { $$ = $2->addArray( $4 ); } 2215 | '(' type _array ')' multi_array_dimension// redundant parenthesis2219 | '(' typedef_array ')' multi_array_dimension // redundant parenthesis 2216 2220 { $$ = $2->addArray( $4 ); } 2217 | '(' type _array ')' // redundant parenthesis2218 { $$ = $2; } 2219 ; 2220 2221 type _function:2222 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2221 | '(' typedef_array ')' // redundant parenthesis 2222 { $$ = $2; } 2223 ; 2224 2225 typedef_function: 2226 paren_typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2223 2227 { $$ = $1->addParamList( $4 ); } 2224 | '(' type _ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2228 | '(' typedef_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2225 2229 { $$ = $2->addParamList( $6 ); } 2226 | '(' type _function ')'// redundant parenthesis2230 | '(' typedef_function ')' // redundant parenthesis 2227 2231 { $$ = $2; } 2228 2232 ; … … 2295 2299 // functions. 2296 2300 2297 type _parameter_redeclarator:2301 typedef_parameter_redeclarator: 2298 2302 typedef attribute_list_opt 2299 | type _parameter_ptr2300 | type _parameter_array attribute_list_opt2301 | type _parameter_function attribute_list_opt2303 | typedef_parameter_ptr 2304 | typedef_parameter_array attribute_list_opt 2305 | typedef_parameter_function attribute_list_opt 2302 2306 ; 2303 2307 … … 2308 2312 $$ = DeclarationNode::newName( $1 ); 2309 2313 } 2310 | TYPEGENname 2311 { 2312 typedefTable.setNextIdentifier( *$1 ); 2313 $$ = DeclarationNode::newName( $1 ); 2314 } 2315 ; 2316 2317 type_parameter_ptr: 2318 '*' type_parameter_redeclarator 2314 ; 2315 2316 typedef_parameter_ptr: 2317 '*' typedef_parameter_redeclarator 2319 2318 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2320 | '*' type_qualifier_list type _parameter_redeclarator2319 | '*' type_qualifier_list typedef_parameter_redeclarator 2321 2320 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2322 | '(' type _parameter_ptr ')'2323 { $$ = $2; } 2324 ; 2325 2326 type _parameter_array:2321 | '(' typedef_parameter_ptr ')' 2322 { $$ = $2; } 2323 ; 2324 2325 typedef_parameter_array: 2327 2326 typedef array_parameter_dimension 2328 2327 { $$ = $1->addArray( $2 ); } 2329 | '(' type _parameter_ptr ')' array_parameter_dimension2328 | '(' typedef_parameter_ptr ')' array_parameter_dimension 2330 2329 { $$ = $2->addArray( $4 ); } 2331 2330 ; 2332 2331 2333 type _parameter_function:2332 typedef_parameter_function: 2334 2333 typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2335 2334 { $$ = $1->addParamList( $4 ); } 2336 | '(' type _parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2335 | '(' typedef_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2337 2336 { $$ = $2->addParamList( $6 ); } 2338 2337 ; … … 2387 2386 array_dimension: 2388 2387 // Only the first dimension can be empty. 2389 '[' ']'2388 '[' push pop ']' 2390 2389 { $$ = DeclarationNode::newArray( 0, 0, false ); } 2391 | '[' ']' multi_array_dimension2392 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $ 3); }2390 | '[' push pop ']' multi_array_dimension 2391 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $5 ); } 2393 2392 | multi_array_dimension 2394 2393 ; … … 2466 2465 2467 2466 array_parameter_1st_dimension: 2468 '[' ']'2467 '[' push pop ']' 2469 2468 { $$ = DeclarationNode::newArray( 0, 0, false ); } 2470 2469 // multi_array_dimension handles the '[' '*' ']' case … … 2559 2558 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to 2560 2559 // shift/reduce conflict with new-style empty (void) function return type. 2561 '[' ']' type_specifier2562 { $$ = $ 3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2560 '[' push pop ']' type_specifier 2561 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2563 2562 | new_array_parameter_1st_dimension type_specifier 2564 2563 { $$ = $2->addNewArray( $1 ); } 2565 | '[' ']' multi_array_dimension type_specifier2566 { $$ = $ 4->addNewArray( $3)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2564 | '[' push pop ']' multi_array_dimension type_specifier 2565 { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2567 2566 | new_array_parameter_1st_dimension multi_array_dimension type_specifier 2568 2567 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } 2569 2568 | multi_array_dimension type_specifier 2570 2569 { $$ = $2->addNewArray( $1 ); } 2571 | '[' ']' new_identifier_parameter_ptr2572 { $$ = $ 3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2570 | '[' push pop ']' new_identifier_parameter_ptr 2571 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2573 2572 | new_array_parameter_1st_dimension new_identifier_parameter_ptr 2574 2573 { $$ = $2->addNewArray( $1 ); } 2575 | '[' ']' multi_array_dimension new_identifier_parameter_ptr2576 { $$ = $ 4->addNewArray( $3)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2574 | '[' push pop ']' multi_array_dimension new_identifier_parameter_ptr 2575 { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2577 2576 | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr 2578 2577 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } … … 2603 2602 // These rules need LR(3): 2604 2603 // 2605 // new_abstract_tuple identifier_or_type _name2606 // '[' new_parameter_list ']' identifier_or_type _name '(' new_parameter_type_list_opt ')'2604 // new_abstract_tuple identifier_or_typedef_name 2605 // '[' new_parameter_list ']' identifier_or_typedef_name '(' new_parameter_type_list_opt ')' 2607 2606 // 2608 2607 // since a function return type can be syntactically identical to a tuple type: … … 2611 2610 // [int, int] f( int ); 2612 2611 // 2613 // Therefore, it is necessary to look at the token after identifier_or_type _name to know when to reduce2612 // Therefore, it is necessary to look at the token after identifier_or_typedef_name to know when to reduce 2614 2613 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary 2615 2614 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are … … 2646 2645 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with 2647 2646 // empty (void) function return type. 2648 '[' ']' type_specifier2649 { $$ = $ 3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2650 | '[' ']' multi_array_dimension type_specifier2651 { $$ = $ 4->addNewArray( $3)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2647 '[' push pop ']' type_specifier 2648 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2649 | '[' push pop ']' multi_array_dimension type_specifier 2650 { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2652 2651 | multi_array_dimension type_specifier 2653 2652 { $$ = $2->addNewArray( $1 ); } 2654 | '[' ']' new_abstract_ptr2655 { $$ = $ 3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2656 | '[' ']' multi_array_dimension new_abstract_ptr2657 { $$ = $ 4->addNewArray( $3)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2653 | '[' push pop ']' new_abstract_ptr 2654 { $$ = $5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2655 | '[' push pop ']' multi_array_dimension new_abstract_ptr 2656 { $$ = $6->addNewArray( $5 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2658 2657 | multi_array_dimension new_abstract_ptr 2659 2658 { $$ = $2->addNewArray( $1 ); } … … 2666 2665 2667 2666 new_abstract_function: // CFA 2668 '[' ']' '(' new_parameter_type_list_opt ')'2669 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $ 4, 0 ); }2667 '[' push pop ']' '(' new_parameter_type_list_opt ')' 2668 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $6, 0 ); } 2670 2669 | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' 2671 2670 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
Note:
See TracChangeset
for help on using the changeset viewer.