Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r253d0b4 ra8ced63  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 24 22:45:20 2024
    13 // Update Count     : 6684
     12// Last Modified On : Thu Jun 20 21:34:49 2024
     13// Update Count     : 6654
    1414//
    1515
     
    223223#define NEW_ONE  new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) )
    224224#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    225 #define MISSING_ANON_FIELD "illegal syntax, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
    226 #define MISSING_LOW "illegal syntax, missing low value for up-to range so index is uninitialized."
    227 #define MISSING_HIGH "illegal syntax, missing high value for down-to range so index is uninitialized."
    228 
    229 static ForCtrl * makeForCtrl( const CodeLocation & location, DeclarationNode * init, enum OperKinds compop,
    230                                                           ExpressionNode * comp, ExpressionNode * inc ) {
     225#define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
     226#define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized."
     227#define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized."
     228
     229static ForCtrl * makeForCtrl(
     230                const CodeLocation & location,
     231                DeclarationNode * init,
     232                enum OperKinds compop,
     233                ExpressionNode * comp,
     234                ExpressionNode * inc ) {
    231235        // Wrap both comp/inc if they are non-null.
    232236        if ( comp ) comp = new ExpressionNode( build_binary_val( location,
     
    245249ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    246250        if ( index->initializer ) {
    247                 SemanticError( yylloc, "illegal syntax, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     251                SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
    248252        } // if
    249253        if ( index->next ) {
    250                 SemanticError( yylloc, "illegal syntax, multiple loop indexes disallowed in for-loop declaration." );
     254                SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." );
    251255        } // if
    252256        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
     
    266270} // forCtrl
    267271
    268 #define MISSING_LOOP_INDEX "illegal syntax, only a single identifier or declaration allowed in initialization, e.g., for ( i; ... ) or for ( int i; ... ). Expression disallowed."
    269 
    270272ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    271273        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) {
    272274                return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
    273         // } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) {
    274         //      if ( auto identifier = commaExpr->arg2.as<ast::NameExpr>() ) {
    275         //              return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
    276         //      } else {
    277         //              SemanticError( yylloc, "illegal syntax, loop-index name missing. Expression disallowed." ); return nullptr;
    278         //      } // if
     275        } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) {
     276                if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
     277                        return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
     278                } else {
     279                        SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
     280                } // if
    279281        } else {
    280                 SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     282                SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    281283        } // if
    282284} // forCtrl
     
    284286ForCtrl * enumRangeCtrl( ExpressionNode * index_expr, ExpressionNode * range_over_expr ) {
    285287        if ( auto identifier = dynamic_cast<ast::NameExpr *>(index_expr->expr.get()) ) {
    286                 DeclarationNode * indexDecl = DeclarationNode::newName( new std::string(identifier->name) );
     288                DeclarationNode * indexDecl =
     289                        DeclarationNode::newName( new std::string(identifier->name) );
    287290                assert( range_over_expr );
    288                 return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
    289         // } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) {
    290         //      if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
    291         //              assert( range_over_expr );
    292         //              DeclarationNode * indexDecl = distAttr(
    293         //                      DeclarationNode::newTypeof( range_over_expr, true ),
    294         //                      DeclarationNode::newName( new std::string( identifier->name) ) );
    295         //              return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
    296         //      } else {
    297         //              SemanticError( yylloc, "illegal syntax, loop-index name missing. Comma expression disallowed." ); return nullptr;
    298         //      } // if
     291                auto node = new StatementNode( indexDecl ); // <- this cause this error
     292                return new ForCtrl( node, range_over_expr );
     293        } else if (auto commaExpr = dynamic_cast<ast::CommaExpr *>( index_expr->expr.get() )) {
     294                if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) {
     295                        assert( range_over_expr );
     296                        DeclarationNode * indexDecl = distAttr(
     297                                DeclarationNode::newTypeof( range_over_expr, true ),
     298                                DeclarationNode::newName( new std::string( identifier->name) ) );
     299                        return new ForCtrl( new StatementNode( indexDecl ), range_over_expr );
     300                } else {
     301                        SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
     302                } // if
    299303        } else {
    300                 SemanticError( yylloc, MISSING_LOOP_INDEX ); return nullptr;
     304                assert( false );
    301305        } // if
    302306} // enumRangeCtrl
    303307
    304308static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    305         SemanticError( yylloc, "illegal syntax, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n"
     309        SemanticError( yylloc, "syntax error, adjacent identifiers \"%s\" and \"%s\" are not meaningful in an %s.\n"
    306310                                   "Possible cause is misspelled type name or missing generic parameter.",
    307311                                   identifier1.c_str(), identifier2.c_str(), kind );
     
    309313
    310314static void IdentifierBeforeType( string & identifier, const char * kind ) {
    311         SemanticError( yylloc, "illegal syntax, identifier \"%s\" cannot appear before a %s.\n"
     315        SemanticError( yylloc, "syntax error, identifier \"%s\" cannot appear before a %s.\n"
    312316                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter.",
    313317                                   identifier.c_str(), kind );
     
    12831287                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    12841288        | statement_list_nodecl error                                           // invalid syntax rule
    1285                 { SemanticError( yylloc, "illegal syntax, declarations only allowed at the start of the switch body,"
     1289                { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body,"
    12861290                                                 " i.e., after the '{'." ); $$ = nullptr; }
    12871291        ;
     
    13441348                }
    13451349        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, invalid syntax rule
    1346                 { SemanticError( yylloc, "illegal syntax, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
     1350                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    13471351        ;
    13481352
     
    13761380case_label:                                                                                             // CFA
    13771381        CASE error                                                                                      // invalid syntax rule
    1378                 { SemanticError( yylloc, "illegal syntax, case list missing after case." ); $$ = nullptr; }
     1382                { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; }
    13791383        | CASE case_value_list ':'                                      { $$ = $2; }
    13801384        | CASE case_value_list error                                            // invalid syntax rule
    1381                 { SemanticError( yylloc, "illegal syntax, colon missing after case list." ); $$ = nullptr; }
     1385                { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; }
    13821386        | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
    13831387                // A semantic check is required to ensure only one default clause per switch/choose statement.
    13841388        | DEFAULT error                                                                         //  invalid syntax rule
    1385                 { SemanticError( yylloc, "illegal syntax, colon missing after default." ); $$ = nullptr; }
     1389                { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; }
    13861390        ;
    13871391
     
    14721476        | comma_expression ';' comma_expression_opt ';' comma_expression_opt
    14731477                {
    1474                         $$ = new ForCtrl( $1 ? new StatementNode( new ast::ExprStmt( yylloc, maybeMoveBuild( $1 ) ) ) : nullptr, $3, $5 );
     1478                        StatementNode * init = $1 ? new StatementNode( new ast::ExprStmt( yylloc, maybeMoveBuild( $1 ) ) ) : nullptr;
     1479                        $$ = new ForCtrl( init, $3, $5 );
    14751480                }
    14761481        | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';'
     
    15371542                {
    15381543                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1539                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1544                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15401545                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
    15411546                }
    15421547        | comma_expression ';' '@' updowneq '@'                         // CFA, invalid syntax rule
    1543                 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1548                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15441549
    15451550        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
     
    15531558                {
    15541559                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1555                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1560                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15561561                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 );
    15571562                }
     
    15661571                {
    15671572                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1568                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1573                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15691574                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr );
    15701575                }
    15711576        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
    1572                 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1577                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15731578
    15741579        | declaration comma_expression                                          // CFA
     
    15871592                {
    15881593                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1589                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1594                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15901595                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE );
    15911596                }
     
    16011606                {
    16021607                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1603                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1608                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    16041609                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 );
    16051610                }
     
    16141619                {
    16151620                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1616                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "illegal syntax, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1621                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    16171622                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr );
    16181623                }
    16191624        | declaration '@' updowneq '@' '~' '@'                          // CFA, invalid syntax rule
    1620                 { SemanticError( yylloc, "illegal syntax, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1625                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    16211626
    16221627        | comma_expression ';' enum_key                                         // CFA, enum type
     
    16271632                {
    16281633                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
    1629                                 SemanticError( yylloc, "illegal syntax, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
     1634                                SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
    16301635                        }
    16311636                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
     
    17321737        MUTEX '(' argument_expression_list_opt ')' statement
    17331738                {
    1734                         if ( ! $3 ) { SemanticError( yylloc, "illegal syntax, mutex argument list cannot be empty." ); $$ = nullptr; }
     1739                        if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; }
    17351740                        $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) );
    17361741                }
     
    17801785        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    17811786        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rule
    1782                 { SemanticError( yylloc, "illegal syntax, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1787                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17831788        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    17841789                { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); }
     
    21722177                        assert( $1->type );
    21732178                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
    2174                                 SemanticError( yylloc, "illegal syntax, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
     2179                                SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
    21752180                        }
    21762181                        // enums are never empty declarations because there must have at least one enumeration.
    21772182                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
    2178                                 SemanticError( yylloc, "illegal syntax, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
     2183                                SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
    21792184                        }
    21802185                }
     
    22092214        | sue_declaration_specifier invalid_types                       // invalid syntax rule
    22102215                {
    2211                         SemanticError( yylloc, "illegal syntax, expecting ';' at end of \"%s\" declaration.",
     2216                        SemanticError( yylloc, "syntax error, expecting ';' at end of \"%s\" declaration.",
    22122217                                                   ast::AggregateDecl::aggrString( $1->type->aggregate.kind ) );
    22132218                        $$ = nullptr;
     
    26872692        | type_specifier field_declaring_list_opt '}'           // invalid syntax rule
    26882693                {
    2689                         SemanticError( yylloc, "illegal syntax, expecting ';' at end of previous declaration." );
     2694                        SemanticError( yylloc, "syntax error, expecting ';' at end of previous declaration." );
    26902695                        $$ = nullptr;
    26912696                }
     
    27832788                {
    27842789                        if ( $3 == EnumHiding::Hide ) {
    2785                                 SemanticError( yylloc, "illegal syntax, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr;
     2790                                SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr;
    27862791                        } // if
    27872792                        $$ = DeclarationNode::newEnum( nullptr, $5, true, false )->addQualifiers( $2 );
     
    27902795                {
    27912796                        if ( $2 && ($2->storageClasses.val != 0 || $2->type->qualifiers.any()) ) {
    2792                                 SemanticError( yylloc, "illegal syntax, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2797                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    27932798                        }
    27942799                        if ( $4 == EnumHiding::Hide ) {
    2795                                 SemanticError( yylloc, "illegal syntax, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr;
     2800                                SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr;
    27962801                        } // if
    27972802                        $$ = DeclarationNode::newEnum( nullptr, $6, true, true, $2 )->addQualifiers( $3 );
     
    28082813                {
    28092814                        if ( $2 && ($2->storageClasses.any() || $2->type->qualifiers.val != 0) ) {
    2810                                 SemanticError( yylloc, "illegal syntax, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2815                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
    28112816                        }
    28122817                        typedefTable.makeTypedef( *$4, "enum_type 2" );
     
    33313336                {
    33323337                        if ( $1->type->qualifiers.any() ) {
    3333                                 SemanticError( yylloc, "illegal syntax, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3338                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    33343339                        }
    33353340                        if ( $1->type->forall ) forall = true;          // remember generic type
     
    33443349                {
    33453350                        if ( $1->type && $1->type->qualifiers.any() ) {
    3346                                 SemanticError( yylloc, "illegal syntax, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3351                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    33473352                        }
    33483353                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
     
    33573362                {
    33583363                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) {
    3359                                 SemanticError( yylloc, "illegal syntax, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3364                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
    33603365                        }
    33613366                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
     
    33893394                        $$ = $3; forall = false;
    33903395                        if ( $5 ) {
    3391                                 SemanticError( yylloc, "illegal syntax, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     3396                                SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
    33923397                                $$ = nullptr;
    33933398                        } // if
Note: See TracChangeset for help on using the changeset viewer.