Changeset 8e4aa05 for src/Parser/parser.yy
- Timestamp:
- Mar 4, 2021, 7:40:25 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 77d601f
- Parents:
- 342af53 (diff), a5040fe (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
r342af53 r8e4aa05 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 11 21:32:10202113 // Update Count : 4 63312 // Last Modified On : Wed Feb 17 09:03:07 2021 13 // Update Count : 4722 14 14 // 15 15 … … 41 41 42 42 %{ 43 #define YYDEBUG_LEXER_TEXT (yylval)// lexer loads this up each time43 #define YYDEBUG_LEXER_TEXT( yylval ) // lexer loads this up each time 44 44 #define YYDEBUG 1 // get the pretty debugging code to compile 45 45 #define YYERROR_VERBOSE // more information in syntax errors … … 63 63 extern TypedefTable typedefTable; 64 64 65 stack< LinkageSpec::Spec> linkageStack;65 stack<LinkageSpec::Spec> linkageStack; 66 66 67 67 bool appendStr( string & to, string & from ) { … … 187 187 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get()); 188 188 if ( constant && (constant->get_constant()->get_value() == "0" || constant->get_constant()->get_value() == "1") ) { 189 type = new ExpressionNode( new CastExpr( maybeMoveBuild< Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );189 type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) ); 190 190 } // if 191 191 return new ForCtrl( … … 282 282 %token ATTRIBUTE EXTENSION // GCC 283 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN 284 %token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY CATCH CATCHRESUME FINALLYTHROW THROWRESUME AT WITH WHEN WAITFOR // CFA284 %token CHOOSE DISABLE ENABLE FALLTHRU FALLTHROUGH TRY THROW THROWRESUME AT WITH WHEN WAITFOR // CFA 285 285 %token ASM // C99, extension ISO/IEC 9899:1999 Section J.5.10(1) 286 286 %token ALIGNAS ALIGNOF GENERIC STATICASSERT // C11 287 287 288 288 // names and constants: lexer differentiates between identifier and typedef names 289 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFnameTYPEGENname290 %token<tok> TIMEOUT WOR291 %token<tok> INTEGERconstant CHARACTERconstantSTRINGliteral289 %token<tok> IDENTIFIER QUOTED_IDENTIFIER TYPEDEFname TYPEGENname 290 %token<tok> TIMEOUT WOR CATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA 291 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 292 292 %token<tok> DIRECTIVE 293 293 // Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and … … 440 440 441 441 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list 442 %type<decl> type_specifier type_specifier_nobody 442 %type<decl> type_specifier type_specifier_nobody enum_specifier_nobody 443 443 444 444 %type<decl> variable_declarator variable_ptr variable_array variable_function 445 445 %type<decl> variable_abstract_declarator variable_abstract_ptr variable_abstract_array variable_abstract_function 446 446 447 %type<decl> attribute_list_opt attribute_list attribute_ name_list attributeattribute_name447 %type<decl> attribute_list_opt attribute_list attribute_opt attribute attribute_name_list attribute_name 448 448 449 449 // initializers … … 462 462 // Order of these lines matters (low-to-high precedence). THEN is left associative over WOR/TIMEOUT/ELSE, WOR is left 463 463 // associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE. 464 %precedence THEN // rule precedence for IF/WAITFOR statement 465 %precedence WOR // token precedence for start of WOR in WAITFOR statement 466 %precedence TIMEOUT // token precedence for start of TIMEOUT in WAITFOR statement 467 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 464 %precedence THEN // rule precedence for IF/WAITFOR statement 465 %precedence WOR // token precedence for start of WOR in WAITFOR statement 466 %precedence TIMEOUT // token precedence for start of TIMEOUT in WAITFOR statement 467 %precedence CATCH // token precedence for start of TIMEOUT in WAITFOR statement 468 %precedence RECOVER // token precedence for start of TIMEOUT in WAITFOR statement 469 %precedence CATCHRESUME // token precedence for start of TIMEOUT in WAITFOR statement 470 %precedence FIXUP // token precedence for start of TIMEOUT in WAITFOR statement 471 %precedence FINALLY // token precedence for start of TIMEOUT in WAITFOR statement 472 %precedence ELSE // token precedence for start of else clause in IF/WAITFOR statement 473 468 474 469 475 // Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous: … … 544 550 TIMEOUT 545 551 | WOR 552 | CATCH 553 | RECOVER 554 | CATCHRESUME 555 | FIXUP 556 | FINALLY 546 557 ; 547 558 … … 578 589 { $$ = $2; } 579 590 | '(' compound_statement ')' // GCC, lambda expression 580 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement>($2) ) ) ); }591 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); } 581 592 | type_name '.' identifier // CFA, nested type 582 593 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 610 621 { 611 622 // create a GenericExpr wrapper with one association pair 612 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3) } } );623 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } ); 613 624 } 614 625 | DEFAULT ':' assignment_expression 615 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3) } } ); }626 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); } 616 627 ; 617 628 618 629 postfix_expression: 619 630 primary_expression 631 | postfix_expression '[' assignment_expression ',' comma_expression ']' 632 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); } 633 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; } 620 634 | postfix_expression '[' assignment_expression ']' 621 635 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 743 757 switch ( $1 ) { 744 758 case OperKinds::AddressOf: 745 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) );759 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ); 746 760 break; 747 761 case OperKinds::PointTo: … … 749 763 break; 750 764 case OperKinds::And: 751 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild< Expression>( $2 ) ) ) );765 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) ); 752 766 break; 753 767 default: … … 762 776 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::Decr, $2 ) ); } 763 777 | SIZEOF unary_expression 764 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }778 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); } 765 779 | SIZEOF '(' type_no_function ')' 766 780 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuildType( $3 ) ) ); } 767 781 | ALIGNOF unary_expression // GCC, variable alignment 768 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild< Expression>( $2 ) ) ); }782 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); } 769 783 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 770 784 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuildType( $3 ) ) ); } … … 794 808 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 795 809 | '(' VIRTUAL ')' cast_expression // CFA 796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }810 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); } 797 811 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 798 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }812 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); } 799 813 | '(' RETURN type_no_function ')' cast_expression // CFA 800 814 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } … … 977 991 assignment_expression 978 992 | comma_expression ',' assignment_expression 979 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }993 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 980 994 ; 981 995 … … 1102 1116 constant_expression { $$ = $1; } 1103 1117 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1104 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }1118 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 1105 1119 | subrange // CFA, subrange 1106 1120 ; … … 1247 1261 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 1248 1262 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1249 1263 | fall_through_name ';' // CFA 1250 1264 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); } 1251 1265 | fall_through_name identifier_or_type_name ';' // CFA 1252 1266 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); } 1253 1267 | fall_through_name DEFAULT ';' // CFA … … 1363 1377 1364 1378 exception_statement: 1365 TRY compound_statement handler_clause 1379 TRY compound_statement handler_clause %prec THEN 1366 1380 { $$ = new StatementNode( build_try( $2, $3, 0 ) ); } 1367 1381 | TRY compound_statement finally_clause … … 1386 1400 handler_key: 1387 1401 CATCH { $$ = CatchStmt::Terminate; } 1402 | RECOVER { $$ = CatchStmt::Terminate; } 1388 1403 | CATCHRESUME { $$ = CatchStmt::Resume; } 1404 | FIXUP { $$ = CatchStmt::Resume; } 1389 1405 ; 1390 1406 … … 1448 1464 asm_operand: // GCC 1449 1465 string_literal '(' constant_expression ')' 1450 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild< Expression>( $3 ) ) ); }1466 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); } 1451 1467 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1452 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild< Expression>( $6 ) ) ); }1468 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); } 1453 1469 ; 1454 1470 … … 1736 1752 | sue_type_specifier_nobody 1737 1753 | type_type_specifier 1754 ; 1755 1756 enum_specifier_nobody: // type specifier - {...} 1757 // Preclude SUE declarations in restricted scopes (see type_specifier_nobody) 1758 basic_type_specifier 1759 | sue_type_specifier_nobody 1738 1760 ; 1739 1761 … … 2004 2026 ; 2005 2027 2006 fred:2007 // empty2008 { yyy = false; }2009 ;2010 2011 2028 aggregate_type: // struct, union 2012 2029 aggregate_key attribute_list_opt … … 2014 2031 '{' field_declaration_list_opt '}' type_parameters_opt 2015 2032 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); } 2016 | aggregate_key attribute_list_opt identifier fred2033 | aggregate_key attribute_list_opt identifier 2017 2034 { 2018 2035 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef … … 2020 2037 } 2021 2038 '{' field_declaration_list_opt '}' type_parameters_opt 2022 { $$ = DeclarationNode::newAggregate( $1, $3, $ 9, $7, true )->addQualifiers( $2 ); }2023 | aggregate_key attribute_list_opt type_name fred2039 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); } 2040 | aggregate_key attribute_list_opt type_name 2024 2041 { 2025 2042 // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one) … … 2028 2045 } 2029 2046 '{' field_declaration_list_opt '}' type_parameters_opt 2030 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $ 9, $7, true )->addQualifiers( $2 ); }2047 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $8, $6, true )->addQualifiers( $2 ); } 2031 2048 | aggregate_type_nobody 2032 2049 ; … … 2040 2057 2041 2058 aggregate_type_nobody: // struct, union - {...} 2042 aggregate_key attribute_list_opt identifier fred2059 aggregate_key attribute_list_opt identifier 2043 2060 { 2044 2061 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); … … 2046 2063 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 2047 2064 } 2048 | aggregate_key attribute_list_opt type_name fred2065 | aggregate_key attribute_list_opt type_name 2049 2066 { 2050 2067 forall = false; // reset … … 2184 2201 ; 2185 2202 2203 // Cannot use attribute_list_opt because of ambiguity with enum_specifier_nobody, which already parses attribute. 2204 // Hence, only a single attribute is allowed after the "ENUM". 2186 2205 enum_type: // enum 2187 ENUM attribute_ list_opt '{' enumerator_list comma_opt '}'2206 ENUM attribute_opt '{' enumerator_list comma_opt '}' 2188 2207 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2189 | ENUM attribute_ list_opt identifier2208 | ENUM attribute_opt identifier 2190 2209 { typedefTable.makeTypedef( *$3 ); } 2191 2210 '{' enumerator_list comma_opt '}' 2192 2211 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2193 | ENUM attribute_ list_opt type_name2212 | ENUM attribute_opt typedef // enum cannot be generic 2194 2213 '{' enumerator_list comma_opt '}' 2195 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); } 2214 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); } 2215 | ENUM enum_specifier_nobody '{' enumerator_list comma_opt '}' 2216 // { $$ = DeclarationNode::newEnum( nullptr, $4, true ); } 2217 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2218 | ENUM enum_specifier_nobody declarator '{' enumerator_list comma_opt '}' 2219 // { 2220 // typedefTable.makeTypedef( *$3->name ); 2221 // $$ = DeclarationNode::newEnum( nullptr, $5, true ); 2222 // } 2223 { SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; } 2196 2224 | enum_type_nobody 2197 2225 ; 2198 2226 2199 2227 enum_type_nobody: // enum - {...} 2200 ENUM attribute_ list_opt identifier2228 ENUM attribute_opt identifier 2201 2229 { 2202 2230 typedefTable.makeTypedef( *$3 ); 2203 2231 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2204 2232 } 2205 | ENUM attribute_ list_opt type_name2233 | ENUM attribute_opt type_name // enum cannot be generic 2206 2234 { 2207 2235 typedefTable.makeTypedef( *$3->type->symbolic.name ); … … 2220 2248 // empty 2221 2249 { $$ = nullptr; } 2222 | '=' constant_expression 2223 { $$ = $2; } 2250 // | '=' constant_expression 2251 // { $$ = $2; } 2252 | '=' initializer 2253 { $$ = $2->get_expression(); } // FIX ME: enum only deals with constant_expression 2224 2254 ; 2225 2255 … … 2403 2433 { $$ = $3; } 2404 2434 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2405 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression>( $5 ) ) ); }2435 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); } 2406 2436 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2407 2437 { $$ = $4; } … … 2441 2471 type_parameter: // CFA 2442 2472 type_class identifier_or_type_name 2443 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2473 { 2474 typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2475 if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); } 2476 if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); } 2477 if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); } 2478 } 2444 2479 type_initializer_opt assertion_list_opt 2445 2480 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2734 2769 subrange: 2735 2770 constant_expression '~' constant_expression // CFA, integer subrange 2736 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $1 ), maybeMoveBuild< Expression>( $3 ) ) ); }2771 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); } 2737 2772 ; 2738 2773 … … 2758 2793 | attribute_list attribute 2759 2794 { $$ = $2->addQualifiers( $1 ); } 2795 ; 2796 2797 attribute_opt: 2798 // empty 2799 { $$ = nullptr; } 2800 | attribute 2760 2801 ; 2761 2802 … … 3162 3203 | '[' ']' multi_array_dimension 3163 3204 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); } 3205 | '[' push assignment_expression pop ',' comma_expression ']' 3206 { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); } 3207 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; } 3164 3208 | multi_array_dimension 3165 3209 ;
Note:
See TracChangeset
for help on using the changeset viewer.