Changes in src/Parser/parser.yy [a025ea8:c744563a]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
ra025ea8 rc744563a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Oct 24 08:21:14202013 // Update Count : 4 62412 // Last Modified On : Fri Feb 21 14:47:29 2020 13 // Update Count : 4468 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 RESUME // CFA 281 %token SUSPEND // CFA 280 // %token SUSPEND RESUME // CFA 282 281 %token ATTRIBUTE EXTENSION // GCC 283 282 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 329 328 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 330 329 %type<en> comma_expression comma_expression_opt 331 %type<en> argument_expression_list _optargument_expression default_initialize_opt330 %type<en> argument_expression_list argument_expression default_initialize_opt 332 331 %type<ifctl> if_control_expression 333 332 %type<fctl> for_control_expression for_control_expression_list … … 370 369 %type<decl> assertion assertion_list assertion_list_opt 371 370 372 %type<en> bit_subrange_size_opt bit_subrange_size371 %type<en> bit_subrange_size_opt bit_subrange_size 373 372 374 373 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 624 623 // equivalent to the old x[i,j]. 625 624 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 626 | postfix_expression '{' argument_expression_list _opt'}' // CFA, constructor call625 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 627 626 { 628 627 Token fn; … … 630 629 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 631 630 } 632 | postfix_expression '(' argument_expression_list _opt')'631 | postfix_expression '(' argument_expression_list ')' 633 632 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 633 | postfix_expression '`' identifier // CFA, postfix call … … 662 661 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 663 662 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 664 | '^' primary_expression '{' argument_expression_list _opt'}' // CFA, destructor call663 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call 665 664 { 666 665 Token fn; … … 670 669 ; 671 670 672 argument_expression_list _opt:671 argument_expression_list: 673 672 // empty 674 673 { $$ = nullptr; } 675 674 | argument_expression 676 | argument_expression_list _opt',' argument_expression675 | argument_expression_list ',' argument_expression 677 676 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 678 677 ; … … 793 792 | '(' aggregate_control '&' ')' cast_expression // CFA 794 793 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 794 // VIRTUAL cannot be opt because of look ahead issues 795 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 { 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 } 920 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 927 921 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 928 922 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 965 959 966 960 tuple_expression_list: 967 assignment_expression 968 | '@' // CFA 969 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; } 970 | tuple_expression_list ',' assignment_expression 961 assignment_expression_opt 962 | tuple_expression_list ',' assignment_expression_opt 971 963 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 972 | tuple_expression_list ',' '@'973 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }974 964 ; 975 965 … … 1080 1070 IF '(' if_control_expression ')' statement %prec THEN 1081 1071 // explicitly deal with the shift/reduce conflict on if/else 1082 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), nullptr ) ); }1072 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 1083 1073 | IF '(' if_control_expression ')' statement ELSE statement 1084 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound( $7 )) ); }1074 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 1085 1075 ; 1086 1076 … … 1130 1120 1131 1121 case_clause: // CFA 1132 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( $2) ); }1122 case_label_list statement { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); } 1133 1123 ; 1134 1124 … … 1148 1138 iteration_statement: 1149 1139 WHILE '(' push if_control_expression ')' statement pop 1150 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 )) ); }1140 { $$ = new StatementNode( build_while( $4, $6 ) ); } 1151 1141 | WHILE '(' ')' statement // CFA => while ( 1 ) 1152 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 )) ); }1142 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); } 1153 1143 | DO statement WHILE '(' comma_expression ')' ';' 1154 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 )) ); }1144 { $$ = new StatementNode( build_do_while( $5, $2 ) ); } 1155 1145 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1156 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 )) ); }1146 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1157 1147 | FOR '(' push for_control_expression_list ')' statement pop 1158 { $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 )) ); }1148 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1159 1149 | FOR '(' ')' statement // CFA => for ( ;; ) 1160 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 )) ); }1150 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), $4 ) ); } 1161 1151 ; 1162 1152 … … 1195 1185 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1186 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 | '=' comma_expression // CFA1187 | '=' comma_expression // CFA 1198 1188 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1199 1189 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1202 1192 | comma_expression inclexcl comma_expression '~' comma_expression // CFA 1203 1193 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1204 | comma_expression ';' // CFA1205 { $$ = forCtrl( new ExpressionNode( build_constantInteger( *new string( "0u" ) ) ), $1, nullptr, OperKinds::LThan, nullptr, nullptr ); }1206 1194 | comma_expression ';' comma_expression // CFA 1207 1195 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1208 1196 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1209 | comma_expression ';' '=' comma_expression // CFA1197 | comma_expression ';' '=' comma_expression // CFA 1210 1198 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1211 1199 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1271 1259 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1272 1260 { SemanticError( yylloc, "Initializer return 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 ) ); } 1261 // | SUSPEND ';' 1262 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1263 // | SUSPEND compound_statement ';' 1264 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1285 1265 | THROW assignment_expression_opt ';' // handles rethrow 1286 1266 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1305 1285 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex". 1306 1286 mutex_statement: 1307 MUTEX '(' argument_expression_list _opt')' statement1287 MUTEX '(' argument_expression_list ')' statement 1308 1288 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } 1309 1289 ; … … 1322 1302 WAITFOR '(' cast_expression ')' 1323 1303 { $$ = $3; } 1324 // | WAITFOR '(' cast_expression ',' argument_expression_list _opt')'1304 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1325 1305 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1326 | WAITFOR '(' cast_expression_list ':' argument_expression_list _opt')'1306 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1327 1307 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1328 1308 ; … … 1331 1311 cast_expression 1332 1312 | cast_expression_list ',' cast_expression 1333 // { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1334 { SemanticError( yylloc, "List of mutex member is currently unimplemented." ); $$ = nullptr; } 1313 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1335 1314 ; 1336 1315 … … 1341 1320 waitfor_clause: 1342 1321 when_clause_opt waitfor statement %prec THEN 1343 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); }1322 { $$ = build_waitfor( $2, $3, $1 ); } 1344 1323 | when_clause_opt waitfor statement WOR waitfor_clause 1345 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); }1324 { $$ = build_waitfor( $2, $3, $1, $5 ); } 1346 1325 | when_clause_opt timeout statement %prec THEN 1347 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); }1326 { $$ = build_waitfor_timeout( $2, $3, $1 ); } 1348 1327 | when_clause_opt ELSE statement 1349 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }1328 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1350 1329 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1351 1330 | when_clause_opt timeout statement WOR ELSE statement 1352 1331 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1353 1332 | when_clause_opt timeout statement WOR when_clause ELSE statement 1354 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5 ); }1333 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } 1355 1334 ; 1356 1335 … … 1675 1654 1676 1655 typedef_expression: 1677 // deprecatedGCC, naming expression type: typedef name = exp; gives a name to the type of an expression1656 // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression 1678 1657 TYPEDEF identifier '=' assignment_expression 1679 1658 { 1680 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1659 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1660 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1681 1661 } 1682 1662 | typedef_expression pop ',' push identifier '=' assignment_expression 1683 1663 { 1684 SemanticError( yylloc, "Typedef expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1685 } 1686 ; 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 // ; 1687 1690 1688 1691 c_declaration: … … 1690 1693 { $$ = distAttr( $1, $2 ); } 1691 1694 | typedef_declaration 1692 | typedef_expression // deprecatedGCC, naming expression type1695 | typedef_expression // GCC, naming expression type 1693 1696 | sue_declaration_specifier 1694 1697 ; … … 2069 2072 { yyy = true; $$ = AggregateDecl::Union; } 2070 2073 | EXCEPTION // CFA 2071 // { yyy = true; $$ = AggregateDecl::Exception; } 2072 { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2074 { yyy = true; $$ = AggregateDecl::Exception; } 2073 2075 ; 2074 2076 2075 2077 aggregate_control: // CFA 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; } 2078 GENERATOR 2079 { yyy = true; $$ = AggregateDecl::Coroutine; } 2084 2080 | COROUTINE 2085 2081 { yyy = true; $$ = AggregateDecl::Coroutine; } 2086 | M UTEX COROUTINE2087 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }2082 | MONITOR 2083 { yyy = true; $$ = AggregateDecl::Monitor; } 2088 2084 | THREAD 2089 2085 { yyy = true; $$ = AggregateDecl::Thread; } 2090 | MUTEX THREAD2091 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }2092 2086 ; 2093 2087 … … 2412 2406 // Overloading: function, data, and operator identifiers may be overloaded. 2413 2407 // 2414 // Type declarations: " otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object2408 // Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object 2415 2409 // and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide 2416 2410 // definitions of new types. Type declarations with storage class "extern" provide opaque types. … … 2441 2435 type_class identifier_or_type_name 2442 2436 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2443 type_initializer_opt assertion_list_opt2437 type_initializer_opt assertion_list_opt 2444 2438 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2445 2439 | type_specifier identifier_parameter_declarator … … 2468 2462 assertion 2469 2463 | assertion_list assertion 2470 { $$ = $1 ->appendList( $2 ); }2464 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2471 2465 ; 2472 2466 … … 2755 2749 | attr_name 2756 2750 { $$ = DeclarationNode::newAttribute( $1 ); } 2757 | attr_name '(' argument_expression_list _opt')'2751 | attr_name '(' argument_expression_list ')' 2758 2752 { $$ = DeclarationNode::newAttribute( $1, $3 ); } 2759 2753 ;
Note:
See TracChangeset
for help on using the changeset viewer.