Changeset 58fe85a for src/Parser/parser.yy
- Timestamp:
- Jan 7, 2021, 3:27:00 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:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (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
r3c64c668 r58fe85a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Feb 21 14:47:29202013 // Update Count : 4 46812 // Last Modified On : Sat Oct 24 08:21:14 2020 13 // Update Count : 4624 14 14 // 15 15 … … 204 204 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc ); 205 205 } else { 206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;206 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 207 207 } // if 208 208 } else { 209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed " ); return nullptr;209 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 210 210 } // if 211 211 } // forCtrl … … 278 278 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 279 279 %token SIZEOF OFFSETOF 280 // %token SUSPEND RESUME // CFA 280 // %token RESUME // CFA 281 %token SUSPEND // CFA 281 282 %token ATTRIBUTE EXTENSION // GCC 282 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 328 329 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 329 330 %type<en> comma_expression comma_expression_opt 330 %type<en> argument_expression_list 331 %type<en> argument_expression_list_opt argument_expression default_initialize_opt 331 332 %type<ifctl> if_control_expression 332 333 %type<fctl> for_control_expression for_control_expression_list … … 369 370 %type<decl> assertion assertion_list assertion_list_opt 370 371 371 %type<en> 372 %type<en> bit_subrange_size_opt bit_subrange_size 372 373 373 374 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 623 624 // equivalent to the old x[i,j]. 624 625 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 625 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call626 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 626 627 { 627 628 Token fn; … … 629 630 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 630 631 } 631 | postfix_expression '(' argument_expression_list ')'632 | postfix_expression '(' argument_expression_list_opt ')' 632 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 633 634 | postfix_expression '`' identifier // CFA, postfix call … … 661 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 662 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 663 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call664 | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call 664 665 { 665 666 Token fn; … … 669 670 ; 670 671 671 argument_expression_list :672 argument_expression_list_opt: 672 673 // empty 673 674 { $$ = nullptr; } 674 675 | argument_expression 675 | argument_expression_list ',' argument_expression676 | argument_expression_list_opt ',' argument_expression 676 677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 677 678 ; … … 792 793 | '(' aggregate_control '&' ')' cast_expression // CFA 793 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 794 // VIRTUAL cannot be opt because of look ahead issues795 795 | '(' VIRTUAL ')' cast_expression // CFA 796 796 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } … … 918 918 conditional_expression 919 919 | unary_expression assignment_operator assignment_expression 920 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 920 { 921 // if ( $2 == OperKinds::AtAssn ) { 922 // SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 923 // } else { 924 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); 925 // } // if 926 } 921 927 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 922 928 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 959 965 960 966 tuple_expression_list: 961 assignment_expression_opt 962 | tuple_expression_list ',' assignment_expression_opt 967 assignment_expression 968 | '@' // CFA 969 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; } 970 | tuple_expression_list ',' assignment_expression 963 971 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 972 | tuple_expression_list ',' '@' 973 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; } 964 974 ; 965 975 … … 1070 1080 IF '(' if_control_expression ')' statement %prec THEN 1071 1081 // explicitly deal with the shift/reduce conflict on if/else 1072 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }1082 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); } 1073 1083 | IF '(' if_control_expression ')' statement ELSE statement 1074 { $$ = new StatementNode( build_if( $3, $5, $7) ); }1084 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 ) ) ); } 1075 1085 ; 1076 1086 … … 1120 1130 1121 1131 case_clause: // CFA 1122 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 )) ); }1132 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( $2 ) ); } 1123 1133 ; 1124 1134 … … 1138 1148 iteration_statement: 1139 1149 WHILE '(' push if_control_expression ')' statement pop 1140 { $$ = new StatementNode( build_while( $4, $6) ); }1150 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); } 1141 1151 | WHILE '(' ')' statement // CFA => while ( 1 ) 1142 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4) ); }1152 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); } 1143 1153 | DO statement WHILE '(' comma_expression ')' ';' 1144 { $$ = new StatementNode( build_do_while( $5, $2) ); }1154 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); } 1145 1155 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1146 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2) ); }1156 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); } 1147 1157 | FOR '(' push for_control_expression_list ')' statement pop 1148 { $$ = new StatementNode( build_for( $4, $6) ); }1158 { $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 ) ) ); } 1149 1159 | FOR '(' ')' statement // CFA => for ( ;; ) 1150 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4) ); }1160 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); } 1151 1161 ; 1152 1162 … … 1185 1195 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1186 1196 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1187 | '=' comma_expression 1197 | '=' comma_expression // CFA 1188 1198 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1189 1199 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1192 1202 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1193 1203 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1204 | comma_expression ';' // CFA 1205 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); } 1194 1206 | comma_expression ';' comma_expression // CFA 1195 1207 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1208 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 | comma_expression ';' '=' comma_expression 1209 | comma_expression ';' '=' comma_expression // CFA 1198 1210 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1199 1211 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1259 1271 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1260 1272 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1261 // | SUSPEND ';' 1262 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1263 // | SUSPEND compound_statement ';' 1264 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1273 | SUSPEND ';' 1274 { $$ = new StatementNode( build_suspend( nullptr ) ); } 1275 | SUSPEND compound_statement 1276 { $$ = new StatementNode( build_suspend( $2 ) ); } 1277 | SUSPEND COROUTINE ';' 1278 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); } 1279 | SUSPEND COROUTINE compound_statement 1280 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); } 1281 | SUSPEND GENERATOR ';' 1282 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); } 1283 | SUSPEND GENERATOR compound_statement 1284 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); } 1265 1285 | THROW assignment_expression_opt ';' // handles rethrow 1266 1286 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1285 1305 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex". 1286 1306 mutex_statement: 1287 MUTEX '(' argument_expression_list ')' statement1307 MUTEX '(' argument_expression_list_opt ')' statement 1288 1308 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } 1289 1309 ; … … 1302 1322 WAITFOR '(' cast_expression ')' 1303 1323 { $$ = $3; } 1304 // | WAITFOR '(' cast_expression ',' argument_expression_list ')'1324 // | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')' 1305 1325 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1306 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'1326 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')' 1307 1327 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1308 1328 ; … … 1311 1331 cast_expression 1312 1332 | cast_expression_list ',' cast_expression 1313 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1333 // { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1334 { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; } 1314 1335 ; 1315 1336 … … 1320 1341 waitfor_clause: 1321 1342 when_clause_opt waitfor statement %prec THEN 1322 { $$ = build_waitfor( $2, $3, $1 ); }1343 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); } 1323 1344 | when_clause_opt waitfor statement WOR waitfor_clause 1324 { $$ = build_waitfor( $2, $3, $1, $5 ); }1345 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); } 1325 1346 | when_clause_opt timeout statement %prec THEN 1326 { $$ = build_waitfor_timeout( $2, $3, $1 ); }1347 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); } 1327 1348 | when_clause_opt ELSE statement 1328 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }1349 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); } 1329 1350 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1330 1351 | when_clause_opt timeout statement WOR ELSE statement 1331 1352 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1332 1353 | when_clause_opt timeout statement WOR when_clause ELSE statement 1333 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); }1354 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); } 1334 1355 ; 1335 1356 … … 1654 1675 1655 1676 typedef_expression: 1656 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression1677 // deprecated GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1657 1678 TYPEDEF identifier '=' assignment_expression 1658 1679 { 1659 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1660 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1680 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1661 1681 } 1662 1682 | typedef_expression pop ',' push identifier '=' assignment_expression 1663 1683 { 1664 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1665 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1666 } 1667 ; 1668 1669 //c_declaration: 1670 // declaring_list pop ';' 1671 // | typedef_declaration pop ';' 1672 // | typedef_expression pop ';' // GCC, naming expression type 1673 // | sue_declaration_specifier pop ';' 1674 // ; 1675 // 1676 //declaring_list: 1677 // // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1678 // // storage-class 1679 // declarator asm_name_opt initializer_opt 1680 // { 1681 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1682 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1683 // } 1684 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1685 // { 1686 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1687 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1688 // } 1689 // ; 1684 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1685 } 1686 ; 1690 1687 1691 1688 c_declaration: … … 1693 1690 { $$ = distAttr( $1, $2 ); } 1694 1691 | typedef_declaration 1695 | typedef_expression // GCC, naming expression type1692 | typedef_expression // deprecated GCC, naming expression type 1696 1693 | sue_declaration_specifier 1697 1694 ; … … 2072 2069 { yyy = true; $$ = AggregateDecl::Union; } 2073 2070 | EXCEPTION // CFA 2074 { yyy = true; $$ = AggregateDecl::Exception; } 2071 // { yyy = true; $$ = AggregateDecl::Exception; } 2072 { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2075 2073 ; 2076 2074 2077 2075 aggregate_control: // CFA 2078 GENERATOR 2079 { yyy = true; $$ = AggregateDecl::Coroutine; } 2076 MONITOR 2077 { yyy = true; $$ = AggregateDecl::Monitor; } 2078 | MUTEX STRUCT 2079 { yyy = true; $$ = AggregateDecl::Monitor; } 2080 | GENERATOR 2081 { yyy = true; $$ = AggregateDecl::Generator; } 2082 | MUTEX GENERATOR 2083 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2080 2084 | COROUTINE 2081 2085 { yyy = true; $$ = AggregateDecl::Coroutine; } 2082 | M ONITOR2083 { yyy = true; $$ = AggregateDecl::Monitor; }2086 | MUTEX COROUTINE 2087 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2084 2088 | THREAD 2085 2089 { yyy = true; $$ = AggregateDecl::Thread; } 2090 | MUTEX THREAD 2091 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2086 2092 ; 2087 2093 … … 2406 2412 // Overloading: function, data, and operator identifiers may be overloaded. 2407 2413 // 2408 // Type declarations: " type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object2414 // Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object 2409 2415 // and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide 2410 2416 // definitions of new types. Type declarations with storage class "extern" provide opaque types. … … 2435 2441 type_class identifier_or_type_name 2436 2442 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2437 2443 type_initializer_opt assertion_list_opt 2438 2444 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2439 2445 | type_specifier identifier_parameter_declarator … … 2462 2468 assertion 2463 2469 | assertion_list assertion 2464 { $$ = $1 ? $1->appendList( $2 ) : $2; }2470 { $$ = $1->appendList( $2 ); } 2465 2471 ; 2466 2472 … … 2749 2755 | attr_name 2750 2756 { $$ = DeclarationNode::newAttribute( $1 ); } 2751 | attr_name '(' argument_expression_list ')'2757 | attr_name '(' argument_expression_list_opt ')' 2752 2758 { $$ = DeclarationNode::newAttribute( $1, $3 ); } 2753 2759 ;
Note:
See TracChangeset
for help on using the changeset viewer.