Changeset 413f7f8 for src/Parser/parser.yy
- Timestamp:
- Jul 7, 2015, 1:49:58 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 82dd287
- Parents:
- e0ff3e6 (diff), 8686f31 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
re0ff3e6 r413f7f8 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 22 15:19:44201513 // Update Count : 1 08212 // Last Modified On : Fri Jul 3 13:53:45 2015 13 // Update Count : 1220 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 def_name no_attr_identifier_or_typedef_name no_01_identifier_or_typedef_name120 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name no_01_identifier_or_type_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 def206 %type<decl> paren_identifier paren_type 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 def_array typedef_declaration typedef_declaration_specifier typedef_expression216 %type<decl> type def_function typedef_parameter_array typedef_parameter_function typedef_parameter_ptr217 %type<decl> type def_parameter_redeclarator typedef_ptr typedef_redeclarator typedef_type_specifier218 %type<decl> typegen_declaration_specifier typegen_type_specifier 215 %type<decl> typedef type_array typedef_declaration typedef_declaration_specifier typedef_expression 216 %type<decl> type_function type_parameter_array type_parameter_function type_parameter_ptr 217 %type<decl> type_parameter_redeclarator type_ptr type_redeclarator typedef_type_specifier 218 %type<decl> typegen_declaration_specifier typegen_type_specifier typegen_name 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 def_name is allowed in this context. However, there is insufficient378 // Only a list of no_attr_identifier_or_type_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 '[' push pop']'566 '[' ']' 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 def_name {}927 | label_list ',' no_attr_identifier_or_type def_name {}926 no_attr_identifier_or_type_name {} 927 | label_list ',' no_attr_identifier_or_type_name {} 928 928 ; 929 929 … … 965 965 $$ = $2->addQualifiers( $1 ); 966 966 } 967 | new_variable_declaration pop ',' push identifier_or_type def_name initializer_opt967 | new_variable_declaration pop ',' push identifier_or_type_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 def_name asm_name_opt977 new_abstract_declarator_no_tuple identifier_or_type_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 def_name asm_name_opt982 | new_abstract_tuple identifier_or_type_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 def_name asm_name_opt987 | type_qualifier_list new_abstract_tuple identifier_or_type_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 def_name1015 | new_function_declaration pop ',' push identifier_or_type_name 1016 1016 { 1017 1017 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); … … 1021 1021 1022 1022 new_function_specifier: // CFA 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: 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: 1034 1039 // 1035 // '[' ']' identifier_or_type def_name '(' new_parameter_type_list_opt ')'1040 // '[' ']' identifier_or_type_name '(' new_parameter_type_list_opt ')' 1036 1041 // '[' ']' type_specifier 1037 1042 // 1038 // type_specifier can resolve to just TYPEDEFname (e.g. typedef int T; int f( T );). Therefore this must be1039 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type def_name.1040 | new_abstract_tuple identifier_or_type def_name '(' push new_parameter_type_list_opt pop ')'1043 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1044 // 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 ')' 1041 1046 // To obtain LR(1 ), this rule must be factored out from function return type (see new_abstract_declarator). 1042 1047 { 1043 1048 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); 1044 1049 } 1045 | new_function_return identifier_or_type def_name '(' push new_parameter_type_list_opt pop ')'1050 | new_function_return identifier_or_type_name '(' push new_parameter_type_list_opt pop ')' 1046 1051 { 1047 1052 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); … … 1107 1112 ; 1108 1113 1109 typedef_expression: // GCC, naming expression type 1114 typedef_expression: 1115 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1110 1116 TYPEDEF no_attr_identifier '=' assignment_expression 1111 1117 { … … 1355 1361 aggregate_name: 1356 1362 aggregate_key '{' field_declaration_list '}' 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 ); } 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; } 1377 1372 ; 1378 1373 … … 1402 1397 new_field_declaring_list: // CFA, new style field declaration 1403 1398 new_abstract_declarator_tuple // CFA, no field name 1404 | new_abstract_declarator_tuple no_attr_identifier_or_type def_name1399 | new_abstract_declarator_tuple no_attr_identifier_or_type_name 1405 1400 { $$ = $1->addName( $2 ); } 1406 | new_field_declaring_list ',' no_attr_identifier_or_type def_name1401 | new_field_declaring_list ',' no_attr_identifier_or_type_name 1407 1402 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 1408 1403 | new_field_declaring_list ',' // CFA, no field name … … 1425 1420 // A semantic check is required to ensure bit_subrange only appears on base type int. 1426 1421 { $$ = $1->addBitfield( $2 ); } 1427 | type def_redeclarator bit_subrange_size_opt1422 | type_redeclarator bit_subrange_size_opt 1428 1423 // A semantic check is required to ensure bit_subrange only appears on base type int. 1429 1424 { $$ = $1->addBitfield( $2 ); } … … 1450 1445 enum_key '{' enumerator_list comma_opt '}' 1451 1446 { $$ = DeclarationNode::newEnum( 0, $3 ); } 1452 | enum_key no_attr_identifier_or_type def_name '{' enumerator_list comma_opt '}'1447 | enum_key no_attr_identifier_or_type_name '{' enumerator_list comma_opt '}' 1453 1448 { $$ = DeclarationNode::newEnum( $2, $4 ); } 1454 | enum_key no_attr_identifier_or_type def_name1449 | enum_key no_attr_identifier_or_type_name 1455 1450 { $$ = DeclarationNode::newEnum( $2, 0 ); } 1456 1451 ; 1457 1452 1458 1453 enumerator_list: 1459 no_attr_identifier_or_type def_name enumerator_value_opt1454 no_attr_identifier_or_type_name enumerator_value_opt 1460 1455 { $$ = DeclarationNode::newEnumConstant( $1, $2 ); } 1461 | enumerator_list ',' no_attr_identifier_or_type def_name enumerator_value_opt1456 | enumerator_list ',' no_attr_identifier_or_type_name enumerator_value_opt 1462 1457 { $$ = $1->appendList( DeclarationNode::newEnumConstant( $3, $4 ) ); } 1463 1458 ; … … 1529 1524 1530 1525 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics 1531 // for typedef name by using type def_parameter_redeclarator instead of typedef_redeclarator, and function prototypes.1526 // for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. 1532 1527 1533 1528 new_parameter_declaration: // CFA, new & old style parameter declaration 1534 1529 parameter_declaration 1535 | new_identifier_parameter_declarator_no_tuple identifier_or_type def_name assignment_opt1530 | new_identifier_parameter_declarator_no_tuple identifier_or_type_name assignment_opt 1536 1531 { $$ = $1->addName( $2 ); } 1537 | new_abstract_tuple identifier_or_type def_name assignment_opt1532 | new_abstract_tuple identifier_or_type_name assignment_opt 1538 1533 // To obtain LR(1), these rules must be duplicated here (see new_abstract_declarator). 1539 1534 { $$ = $1->addName( $2 ); } 1540 | type_qualifier_list new_abstract_tuple identifier_or_type def_name assignment_opt1535 | type_qualifier_list new_abstract_tuple identifier_or_type_name assignment_opt 1541 1536 { $$ = $2->addName( $3 )->addQualifiers( $1 ); } 1542 1537 | new_function_specifier … … 1559 1554 $$ = $2->addType( $1 )->addInitializer( new InitializerNode( $3 ) ); 1560 1555 } 1561 | declaration_specifier type def_parameter_redeclarator assignment_opt1556 | declaration_specifier type_parameter_redeclarator assignment_opt 1562 1557 { 1563 1558 typedefTable.addToEnclosingScope( TypedefTable::ID ); … … 1583 1578 ; 1584 1579 1585 identifier_or_type def_name:1580 identifier_or_type_name: 1586 1581 identifier 1587 1582 | TYPEDEFname … … 1589 1584 ; 1590 1585 1591 no_01_identifier_or_type def_name:1586 no_01_identifier_or_type_name: 1592 1587 no_01_identifier 1593 1588 | TYPEDEFname … … 1595 1590 ; 1596 1591 1597 no_attr_identifier_or_type def_name:1592 no_attr_identifier_or_type_name: 1598 1593 no_attr_identifier 1599 1594 | TYPEDEFname 1600 //| TYPEGENname1595 | TYPEGENname 1601 1596 ; 1602 1597 … … 1619 1614 // empty 1620 1615 { $$ = 0; } 1621 | '=' initializer { $$ = $2; } 1616 | '=' initializer 1617 { $$ = $2; } 1622 1618 ; 1623 1619 … … 1647 1643 designation: 1648 1644 designator_list ':' // C99, CFA uses ":" instead of "=" 1649 | no_attr_identifier_or_type def_name ':'// GCC, field name1650 1645 | no_attr_identifier_or_type_name ':' // GCC, field name 1646 { $$ = new VarRefNode( $1 ); } 1651 1647 ; 1652 1648 1653 1649 designator_list: // C99 1654 1650 designator 1655 | designator_list designator { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1651 | designator_list designator 1652 { $$ = (ExpressionNode *)( $1->set_link( $2 )); } 1656 1653 //| designator_list designator { $$ = new CompositeExprNode( $1, $2 ); } 1657 1654 ; 1658 1655 1659 1656 designator: 1660 '.' no_attr_identifier_or_type def_name// C99, field name1657 '.' no_attr_identifier_or_type_name // C99, field name 1661 1658 { $$ = new VarRefNode( $2 ); } 1662 1659 | '[' push assignment_expression pop ']' // C99, single array element … … 1700 1697 1701 1698 typegen_type_specifier: // CFA 1699 typegen_name 1700 | type_qualifier_list typegen_name 1701 { $$ = $2->addQualifiers( $1 ); } 1702 | typegen_type_specifier type_qualifier 1703 { $$ = $1->addQualifiers( $2 ); } 1704 ; 1705 1706 typegen_name: // CFA 1702 1707 TYPEGENname '(' type_name_list ')' 1703 1708 { $$ = DeclarationNode::newFromTypeGen( $1, $3 ); } 1704 | type_qualifier_list TYPEGENname '(' type_name_list ')'1705 { $$ = DeclarationNode::newFromTypeGen( $2, $4 )->addQualifiers( $1 ); }1706 | typegen_type_specifier type_qualifier1707 { $$ = $1->addQualifiers( $2 ); }1708 1709 ; 1709 1710 … … 1715 1716 1716 1717 type_parameter: // CFA 1717 type_class no_attr_identifier_or_type def_name1718 { typedefTable.addToEnclosingScope( *( $2 ), TypedefTable::TD ); }1718 type_class no_attr_identifier_or_type_name 1719 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); } 1719 1720 assertion_list_opt 1720 1721 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addAssertions( $4 ); } … … 1739 1740 1740 1741 assertion: // CFA 1741 '|' no_attr_identifier_or_type def_name '(' type_name_list ')'1742 { 1743 typedefTable.openContext( * ( $2 ));1742 '|' no_attr_identifier_or_type_name '(' type_name_list ')' 1743 { 1744 typedefTable.openContext( *$2 ); 1744 1745 $$ = DeclarationNode::newContextUse( $2, $4 ); 1745 1746 } … … 1777 1778 1778 1779 type_declarator_name: // CFA 1779 no_attr_identifier_or_type def_name1780 no_attr_identifier_or_type_name 1780 1781 { 1781 1782 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD ); 1782 1783 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 1783 1784 } 1784 | no_01_identifier_or_type def_name '(' push type_parameter_list pop ')'1785 | no_01_identifier_or_type_name '(' push type_parameter_list pop ')' 1785 1786 { 1786 1787 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); … … 1790 1791 1791 1792 context_specifier: // CFA 1792 CONTEXT no_attr_identifier_or_type def_name '(' push type_parameter_list pop ')' '{' '}'1793 CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' 1793 1794 { 1794 1795 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 1795 1796 $$ = DeclarationNode::newContext( $2, $5, 0 ); 1796 1797 } 1797 | CONTEXT no_attr_identifier_or_type def_name '(' push type_parameter_list pop ')' '{'1798 | CONTEXT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 1798 1799 { 1799 1800 typedefTable.enterContext( *$2 ); … … 1830 1831 $$ = $1; 1831 1832 } 1832 | new_context_declaring_list pop ',' push identifier_or_type def_name1833 | new_context_declaring_list pop ',' push identifier_or_type_name 1833 1834 { 1834 1835 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); … … 1899 1900 external_function_definition: 1900 1901 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 def_redeclarator1984 | type_redeclarator 1985 1985 ; 1986 1986 … … 2021 2021 2022 2022 any_word: // GCC 2023 identifier_or_type def_name {}2023 identifier_or_type_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 def_redeclarator. The pattern precludes returning2105 // further separation of variable and function declarators in type_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 defname, e.g.:2178 // This pattern parses a declaration for a variable or function prototype that redefines a type name, e.g.: 2179 2179 // 2180 2180 // typedef int foo; … … 2186 2186 // and functions versus pointers to arrays and functions. 2187 2187 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 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 2207 2203 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2208 | '*' type_qualifier_list type def_redeclarator2204 | '*' type_qualifier_list type_redeclarator 2209 2205 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2210 | '(' type def_ptr ')'2211 { $$ = $2; } 2212 ; 2213 2214 type def_array:2215 paren_type defarray_dimension2206 | '(' type_ptr ')' 2207 { $$ = $2; } 2208 ; 2209 2210 type_array: 2211 paren_type array_dimension 2216 2212 { $$ = $1->addArray( $2 ); } 2217 | '(' type def_ptr ')' array_dimension2213 | '(' type_ptr ')' array_dimension 2218 2214 { $$ = $2->addArray( $4 ); } 2219 | '(' type def_array ')' multi_array_dimension// redundant parenthesis2215 | '(' type_array ')' multi_array_dimension // redundant parenthesis 2220 2216 { $$ = $2->addArray( $4 ); } 2221 | '(' type def_array ')' // redundant parenthesis2222 { $$ = $2; } 2223 ; 2224 2225 type def_function:2226 paren_type def'(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2217 | '(' type_array ')' // redundant parenthesis 2218 { $$ = $2; } 2219 ; 2220 2221 type_function: 2222 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2227 2223 { $$ = $1->addParamList( $4 ); } 2228 | '(' type def_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2224 | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2229 2225 { $$ = $2->addParamList( $6 ); } 2230 | '(' type def_function ')'// redundant parenthesis2226 | '(' type_function ')' // redundant parenthesis 2231 2227 { $$ = $2; } 2232 2228 ; … … 2299 2295 // functions. 2300 2296 2301 type def_parameter_redeclarator:2297 type_parameter_redeclarator: 2302 2298 typedef attribute_list_opt 2303 | type def_parameter_ptr2304 | type def_parameter_array attribute_list_opt2305 | type def_parameter_function attribute_list_opt2299 | type_parameter_ptr 2300 | type_parameter_array attribute_list_opt 2301 | type_parameter_function attribute_list_opt 2306 2302 ; 2307 2303 … … 2312 2308 $$ = DeclarationNode::newName( $1 ); 2313 2309 } 2314 ; 2315 2316 typedef_parameter_ptr: 2317 '*' typedef_parameter_redeclarator 2310 | TYPEGENname 2311 { 2312 typedefTable.setNextIdentifier( *$1 ); 2313 $$ = DeclarationNode::newName( $1 ); 2314 } 2315 ; 2316 2317 type_parameter_ptr: 2318 '*' type_parameter_redeclarator 2318 2319 { $$ = $2->addPointer( DeclarationNode::newPointer( 0 ) ); } 2319 | '*' type_qualifier_list type def_parameter_redeclarator2320 | '*' type_qualifier_list type_parameter_redeclarator 2320 2321 { $$ = $3->addPointer( DeclarationNode::newPointer( $2 ) ); } 2321 | '(' type def_parameter_ptr ')'2322 { $$ = $2; } 2323 ; 2324 2325 type def_parameter_array:2322 | '(' type_parameter_ptr ')' 2323 { $$ = $2; } 2324 ; 2325 2326 type_parameter_array: 2326 2327 typedef array_parameter_dimension 2327 2328 { $$ = $1->addArray( $2 ); } 2328 | '(' type def_parameter_ptr ')' array_parameter_dimension2329 | '(' type_parameter_ptr ')' array_parameter_dimension 2329 2330 { $$ = $2->addArray( $4 ); } 2330 2331 ; 2331 2332 2332 type def_parameter_function:2333 type_parameter_function: 2333 2334 typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2334 2335 { $$ = $1->addParamList( $4 ); } 2335 | '(' type def_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)2336 | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2336 2337 { $$ = $2->addParamList( $6 ); } 2337 2338 ; … … 2386 2387 array_dimension: 2387 2388 // Only the first dimension can be empty. 2388 '[' push pop']'2389 '[' ']' 2389 2390 { $$ = DeclarationNode::newArray( 0, 0, false ); } 2390 | '[' push pop']' multi_array_dimension2391 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $ 5); }2391 | '[' ']' multi_array_dimension 2392 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); } 2392 2393 | multi_array_dimension 2393 2394 ; … … 2465 2466 2466 2467 array_parameter_1st_dimension: 2467 '[' push pop']'2468 '[' ']' 2468 2469 { $$ = DeclarationNode::newArray( 0, 0, false ); } 2469 2470 // multi_array_dimension handles the '[' '*' ']' case … … 2558 2559 // Only the first dimension can be empty or have qualifiers. Empty dimension must be factored out due to 2559 2560 // shift/reduce conflict with new-style empty (void) function return type. 2560 '[' push pop']' type_specifier2561 { $$ = $ 5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2561 '[' ']' type_specifier 2562 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2562 2563 | new_array_parameter_1st_dimension type_specifier 2563 2564 { $$ = $2->addNewArray( $1 ); } 2564 | '[' push pop']' multi_array_dimension type_specifier2565 { $$ = $ 6->addNewArray( $5)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2565 | '[' ']' multi_array_dimension type_specifier 2566 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2566 2567 | new_array_parameter_1st_dimension multi_array_dimension type_specifier 2567 2568 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } 2568 2569 | multi_array_dimension type_specifier 2569 2570 { $$ = $2->addNewArray( $1 ); } 2570 | '[' push pop']' new_identifier_parameter_ptr2571 { $$ = $ 5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2571 | '[' ']' new_identifier_parameter_ptr 2572 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2572 2573 | new_array_parameter_1st_dimension new_identifier_parameter_ptr 2573 2574 { $$ = $2->addNewArray( $1 ); } 2574 | '[' push pop']' multi_array_dimension new_identifier_parameter_ptr2575 { $$ = $ 6->addNewArray( $5)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2575 | '[' ']' multi_array_dimension new_identifier_parameter_ptr 2576 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2576 2577 | new_array_parameter_1st_dimension multi_array_dimension new_identifier_parameter_ptr 2577 2578 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } … … 2602 2603 // These rules need LR(3): 2603 2604 // 2604 // new_abstract_tuple identifier_or_type def_name2605 // '[' new_parameter_list ']' identifier_or_type def_name '(' new_parameter_type_list_opt ')'2605 // new_abstract_tuple identifier_or_type_name 2606 // '[' new_parameter_list ']' identifier_or_type_name '(' new_parameter_type_list_opt ')' 2606 2607 // 2607 2608 // since a function return type can be syntactically identical to a tuple type: … … 2610 2611 // [int, int] f( int ); 2611 2612 // 2612 // Therefore, it is necessary to look at the token after identifier_or_type def_name to know when to reduce2613 // Therefore, it is necessary to look at the token after identifier_or_type_name to know when to reduce 2613 2614 // new_abstract_tuple. To make this LR(1), several rules have to be flattened (lengthened) to allow the necessary 2614 2615 // lookahead. To accomplish this, new_abstract_declarator has an entry point without tuple, and tuple declarations are … … 2645 2646 // Only the first dimension can be empty. Empty dimension must be factored out due to shift/reduce conflict with 2646 2647 // empty (void) function return type. 2647 '[' push pop']' type_specifier2648 { $$ = $ 5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2649 | '[' push pop']' multi_array_dimension type_specifier2650 { $$ = $ 6->addNewArray( $5)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2648 '[' ']' type_specifier 2649 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2650 | '[' ']' multi_array_dimension type_specifier 2651 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2651 2652 | multi_array_dimension type_specifier 2652 2653 { $$ = $2->addNewArray( $1 ); } 2653 | '[' push pop']' new_abstract_ptr2654 { $$ = $ 5->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2655 | '[' push pop']' multi_array_dimension new_abstract_ptr2656 { $$ = $ 6->addNewArray( $5)->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2654 | '[' ']' new_abstract_ptr 2655 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2656 | '[' ']' multi_array_dimension new_abstract_ptr 2657 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); } 2657 2658 | multi_array_dimension new_abstract_ptr 2658 2659 { $$ = $2->addNewArray( $1 ); } … … 2665 2666 2666 2667 new_abstract_function: // CFA 2667 '[' push pop']' '(' new_parameter_type_list_opt ')'2668 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $ 6, 0 ); }2668 '[' ']' '(' new_parameter_type_list_opt ')' 2669 { $$ = DeclarationNode::newFunction( 0, DeclarationNode::newTuple( 0 ), $4, 0 ); } 2669 2670 | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' 2670 2671 { $$ = DeclarationNode::newFunction( 0, $1, $4, 0 ); }
Note:
See TracChangeset
for help on using the changeset viewer.