Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    ra025ea8 rc744563a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct 24 08:21:14 2020
    13 // Update Count     : 4624
     12// Last Modified On : Fri Feb 21 14:47:29 2020
     13// Update Count     : 4468
    1414//
    1515
     
    204204                        return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );
    205205                } 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;
    207207                } // if
    208208        } 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;
    210210        } // if
    211211} // forCtrl
     
    278278%token OTYPE FTYPE DTYPE TTYPE TRAIT                                    // CFA
    279279%token SIZEOF OFFSETOF
    280 // %token RESUME                                                                                        // CFA
    281 %token SUSPEND                                                                                  // CFA
     280// %token SUSPEND RESUME                                                                        // CFA
    282281%token ATTRIBUTE EXTENSION                                                              // GCC
    283282%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
     
    329328%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    330329%type<en> comma_expression                              comma_expression_opt
    331 %type<en> argument_expression_list_opt  argument_expression                     default_initialize_opt
     330%type<en> argument_expression_list              argument_expression                     default_initialize_opt
    332331%type<ifctl> if_control_expression
    333332%type<fctl> for_control_expression              for_control_expression_list
     
    370369%type<decl> assertion assertion_list assertion_list_opt
    371370
    372 %type<en> bit_subrange_size_opt bit_subrange_size
     371%type<en>   bit_subrange_size_opt bit_subrange_size
    373372
    374373%type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type
     
    624623                // equivalent to the old x[i,j].
    625624                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    626         | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
     625        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    627626                {
    628627                        Token fn;
     
    630629                        $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );
    631630                }
    632         | postfix_expression '(' argument_expression_list_opt ')'
     631        | postfix_expression '(' argument_expression_list ')'
    633632                { $$ = new ExpressionNode( build_func( $1, $3 ) ); }
    634633        | postfix_expression '`' identifier                                     // CFA, postfix call
     
    662661        | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
    663662                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    664         | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call
     663        | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call
    665664                {
    666665                        Token fn;
     
    670669        ;
    671670
    672 argument_expression_list_opt:
     671argument_expression_list:
    673672        // empty
    674673                { $$ = nullptr; }
    675674        | argument_expression
    676         | argument_expression_list_opt ',' argument_expression
     675        | argument_expression_list ',' argument_expression
    677676                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    678677        ;
     
    793792        | '(' aggregate_control '&' ')' cast_expression         // CFA
    794793                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
     794                // VIRTUAL cannot be opt because of look ahead issues
    795795        | '(' VIRTUAL ')' cast_expression                                       // CFA
    796796                { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); }
     
    918918        conditional_expression
    919919        | 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 ) ); }
    927921        | unary_expression '=' '{' initializer_list_opt comma_opt '}'
    928922                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
     
    965959
    966960tuple_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
    971963                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
    972         | tuple_expression_list ',' '@'
    973                 { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
    974964        ;
    975965
     
    10801070        IF '(' if_control_expression ')' statement                      %prec THEN
    10811071                // 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 ) ); }
    10831073        | 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 ) ); }
    10851075        ;
    10861076
     
    11301120
    11311121case_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 ) ) ); }
    11331123        ;
    11341124
     
    11481138iteration_statement:
    11491139        WHILE '(' push if_control_expression ')' statement pop
    1150                 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); }
     1140                { $$ = new StatementNode( build_while( $4, $6 ) ); }
    11511141        | 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 ) ); }
    11531143        | DO statement WHILE '(' comma_expression ')' ';'
    1154                 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
     1144                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
    11551145        | 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 ) ); }
    11571147        | 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 ) ); }
    11591149        | 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 ) ); }
    11611151        ;
    11621152
     
    11951185                { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11961186                                                OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1197         | '=' comma_expression                                                          // CFA
     1187        | '=' comma_expression                                                                  // CFA
    11981188                { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    11991189                                                OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12021192        | comma_expression inclexcl comma_expression '~' comma_expression // CFA
    12031193                { $$ = 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 ); }
    12061194        | comma_expression ';' comma_expression                         // CFA
    12071195                { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12081196                                                OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
    1209         | comma_expression ';' '=' comma_expression                     // CFA
     1197        | comma_expression ';' '=' comma_expression                             // CFA
    12101198                { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ),
    12111199                                                OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); }
     
    12711259        | RETURN '{' initializer_list_opt comma_opt '}' ';'
    12721260                { 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; }
    12851265        | THROW assignment_expression_opt ';'                           // handles rethrow
    12861266                { $$ = new StatementNode( build_throw( $2 ) ); }
     
    13051285// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
    13061286mutex_statement:
    1307         MUTEX '(' argument_expression_list_opt ')' statement
     1287        MUTEX '(' argument_expression_list ')' statement
    13081288                { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }
    13091289        ;
     
    13221302        WAITFOR '(' cast_expression ')'
    13231303                { $$ = $3; }
    1324 //      | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'
     1304//      | WAITFOR '(' cast_expression ',' argument_expression_list ')'
    13251305//              { $$ = (ExpressionNode *)$3->set_last( $5 ); }
    1326         | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'
     1306        | WAITFOR '(' cast_expression_list ':' argument_expression_list ')'
    13271307                { $$ = (ExpressionNode *)($3->set_last( $5 )); }
    13281308        ;
     
    13311311        cast_expression
    13321312        | 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 )); }
    13351314        ;
    13361315
     
    13411320waitfor_clause:
    13421321        when_clause_opt waitfor statement                                       %prec THEN
    1343                 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); }
     1322                { $$ = build_waitfor( $2, $3, $1 ); }
    13441323        | 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 ); }
    13461325        | when_clause_opt timeout statement                                     %prec THEN
    1347                 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); }
     1326                { $$ = build_waitfor_timeout( $2, $3, $1 ); }
    13481327        | when_clause_opt ELSE statement
    1349                 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
     1328                { $$ = build_waitfor_timeout( nullptr, $3, $1 ); }
    13501329                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    13511330        | when_clause_opt timeout statement WOR ELSE statement
    13521331                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    13531332        | 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 ); }
    13551334        ;
    13561335
     
    16751654
    16761655typedef_expression:
    1677                 // deprecated GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
     1656                // GCC, naming expression type: typedef name = exp; gives a name to the type of an expression
    16781657        TYPEDEF identifier '=' assignment_expression
    16791658                {
    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;
    16811661                }
    16821662        | typedef_expression pop ',' push identifier '=' assignment_expression
    16831663                {
    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//      ;
    16871690
    16881691c_declaration:
     
    16901693                { $$ = distAttr( $1, $2 ); }
    16911694        | typedef_declaration
    1692         | typedef_expression                                                            // deprecated GCC, naming expression type
     1695        | typedef_expression                                                            // GCC, naming expression type
    16931696        | sue_declaration_specifier
    16941697        ;
     
    20692072                { yyy = true; $$ = AggregateDecl::Union; }
    20702073        | EXCEPTION                                                                                     // CFA
    2071                 // { yyy = true; $$ = AggregateDecl::Exception; }
    2072                 { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2074                { yyy = true; $$ = AggregateDecl::Exception; }
    20732075        ;
    20742076
    20752077aggregate_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; }
    20842080        | COROUTINE
    20852081                { yyy = true; $$ = AggregateDecl::Coroutine; }
    2086         | MUTEX COROUTINE
    2087                 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
     2082        | MONITOR
     2083                { yyy = true; $$ = AggregateDecl::Monitor; }
    20882084        | THREAD
    20892085                { yyy = true; $$ = AggregateDecl::Thread; }
    2090         | MUTEX THREAD
    2091                 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }
    20922086        ;
    20932087
     
    24122406// Overloading: function, data, and operator identifiers may be overloaded.
    24132407//
    2414 // Type declarations: "otype" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
     2408// Type declarations: "type" is used to generate new types for declaring objects. Similarly, "dtype" is used for object
    24152409//     and incomplete types, and "ftype" is used for function types. Type declarations with initializers provide
    24162410//     definitions of new types. Type declarations with storage class "extern" provide opaque types.
     
    24412435        type_class identifier_or_type_name
    24422436                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    2443         type_initializer_opt assertion_list_opt
     2437          type_initializer_opt assertion_list_opt
    24442438                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    24452439        | type_specifier identifier_parameter_declarator
     
    24682462        assertion
    24692463        | assertion_list assertion
    2470                 { $$ = $1->appendList( $2 ); }
     2464                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    24712465        ;
    24722466
     
    27552749        | attr_name
    27562750                { $$ = DeclarationNode::newAttribute( $1 ); }
    2757         | attr_name '(' argument_expression_list_opt ')'
     2751        | attr_name '(' argument_expression_list ')'
    27582752                { $$ = DeclarationNode::newAttribute( $1, $3 ); }
    27592753        ;
Note: See TracChangeset for help on using the changeset viewer.