Changeset 55266c7 for src/Parser


Ignore:
Timestamp:
Jun 7, 2023, 2:19:12 PM (12 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ast-experimental, master
Children:
918e4165
Parents:
77afbb4
Message:

harmonize semantic error messages with yacc error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r77afbb4 r55266c7  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 26 16:45:37 2023
    13 // Update Count     : 6330
     12// Last Modified On : Tue Jun  6 22:37:59 2023
     13// Update Count     : 6340
    1414//
    1515
     
    108108        assert( declList );
    109109        // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout );
    110         DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec );
     110        DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec );
    111111        // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout );
    112112        // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name;
    113113
    114         for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
     114        for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {
    115115                cl->cloneBaseType( cur );
    116116        } // for
     
    206206#define NEW_ONE  new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) )
    207207#define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right)
    208 #define MISSING_ANON_FIELD "Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
    209 #define MISSING_LOW "Missing low value for up-to range so index is uninitialized."
    210 #define MISSING_HIGH "Missing high value for down-to range so index is uninitialized."
     208#define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."
     209#define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized."
     210#define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized."
    211211
    212212static ForCtrl * makeForCtrl(
     
    232232ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {
    233233        if ( index->initializer ) {
    234                 SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
     234                SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );
    235235        } // if
    236236        if ( index->next ) {
    237                 SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." );
     237                SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." );
    238238        } // if
    239239        DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) );
     
    260260                        return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc );
    261261                } else {
    262                         SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     262                        SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr;
    263263                } // if
    264264        } else {
    265                 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr;
     265                SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr;
    266266        } // if
    267267} // forCtrl
    268268
    269269static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
    270         SemanticError( yylloc, ::toString( "Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
     270        SemanticError( yylloc, ::toString( "syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
    271271                                   "Possible cause is misspelled type name or missing generic parameter." ) );
    272272} // IdentifierBeforeIdentifier
    273273
    274274static void IdentifierBeforeType( string & identifier, const char * kind ) {
    275         SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
     275        SemanticError( yylloc, ::toString( "syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
    276276                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
    277277} // IdentifierBeforeType
     
    11541154        | identifier_or_type_name ':' attribute_list_opt error // syntax error
    11551155                {
    1156                         SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, "
     1156                        SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, "
    11571157                                                                                           "where a declaration, case, or default is not a statement. "
    11581158                                                                                           "Move the label or terminate with a semi-colon." ) );
     
    11941194                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    11951195        | statement_list_nodecl error                                           // syntax error
    1196                 { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
     1196                { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
    11971197        ;
    11981198
     
    12201220                }
    12211221        | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1222                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1222                { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    12231223        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    12241224                { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); }
     
    12291229                }
    12301230        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1231                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1231                { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; }
    12321232        ;
    12331233
     
    12691269case_label:                                                                                             // CFA
    12701270        CASE error                                                                                      // syntax error
    1271                 { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; }
     1271                { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; }
    12721272        | CASE case_value_list ':'                                      { $$ = $2; }
    12731273        | CASE case_value_list error                                            // syntax error
    1274                 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
     1274                { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; }
    12751275        | DEFAULT ':'                                                           { $$ = new ClauseNode( build_default( yylloc ) ); }
    12761276                // A semantic check is required to ensure only one default clause per switch/choose statement.
    12771277        | DEFAULT error                                                                         //  syntax error
    1278                 { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; }
     1278                { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; }
    12791279        ;
    12801280
     
    14311431                {
    14321432                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1433                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1433                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14341434                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE );
    14351435                }
    14361436        | comma_expression ';' '@' updowneq '@'                         // CFA, error
    1437                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1437                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14381438
    14391439        | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA
     
    14471447                {
    14481448                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1449                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1449                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14501450                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 );
    14511451                }
     
    14601460                {
    14611461                        if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1462                         else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1462                        else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14631463                        else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr );
    14641464                }
    14651465        | comma_expression ';' '@' updowneq '@' '~' '@' // CFA
    1466                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1466                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    14671467
    14681468        | declaration comma_expression                                          // CFA
     
    14811481                {
    14821482                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1483                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1483                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14841484                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE );
    14851485                }
     
    14951495                {
    14961496                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1497                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1497                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    14981498                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 );
    14991499                }
     
    15081508                {
    15091509                        if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; }
    1510                         else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
     1510                        else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }
    15111511                        else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr );
    15121512                }
    15131513        | declaration '@' updowneq '@' '~' '@'                          // CFA, error
    1514                 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
     1514                { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }
    15151515
    15161516        | comma_expression ';' TYPEDEFname                                      // CFA, array type
     
    15211521        | comma_expression ';' downupdowneq TYPEDEFname         // CFA, array type
    15221522                {
    1523                         if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; }
     1523                        if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) {
     1524                                SemanticError( yylloc, "All enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr;
     1525                        }
    15241526                        SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr;
    15251527                }
     
    16161618        MUTEX '(' argument_expression_list_opt ')' statement
    16171619                {
    1618                         if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; }
     1620                        if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; }
    16191621                        $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) );
    16201622                }
     
    16651667        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    16661668        | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    1667                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1669                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    16681670        | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    16691671                { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); }
     
    17101712        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    17111713        | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error
    1712                 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
     1714                { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    17131715        | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement
    17141716                { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1,
     
    20652067                        assert( $1->type );
    20662068                        if ( $1->type->qualifiers.any() ) {                     // CV qualifiers ?
    2067                                 SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr;
     2069                                SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;
    20682070                        }
    20692071                        // enums are never empty declarations because there must have at least one enumeration.
    20702072                        if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ?
    2071                                 SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
     2073                                SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;
    20722074                        }
    20732075                }
     
    21022104        | sue_declaration_specifier invalid_types
    21032105                {
    2104                         SemanticError( yylloc, ::toString( "Missing ';' after end of ",
     2106                        SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ",
    21052107                                $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ),
    2106                                 " declaration" ) );
     2108                                " declaration." ) );
    21072109                        $$ = nullptr;
    21082110                }
     
    25842586                        // } // for
    25852587                }
     2588        | type_specifier field_declaring_list_opt '}'
     2589                {
     2590                        SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) );
     2591                        $$ = nullptr;
     2592                }
    25862593        | EXTENSION type_specifier field_declaring_list_opt ';' // GCC
    25872594                { $$ = fieldDecl( $2, $3 ); distExt( $$ ); }
     
    26822689        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    26832690                {
    2684                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() )
    2685                         { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    2686 
     2691                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) {
     2692                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2693                        }
    26872694                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 );
    26882695                }
     
    26932700        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
    26942701                {
    2695                         if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2702                        if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) {
     2703                                SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." );
     2704                        }
    26962705                        typedefTable.makeTypedef( *$6 );
    26972706                }
     
    32093218        | type_qualifier_list
    32103219                {
    3211                         if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3220                        if ( $1->type->qualifiers.any() ) {
     3221                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3222                        }
    32123223                        if ( $1->type->forall ) forall = true;          // remember generic type
    32133224                }
     
    32203231        | declaration_qualifier_list
    32213232                {
    3222                         if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3233                        if ( $1->type && $1->type->qualifiers.any() ) {
     3234                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3235                        }
    32233236                        if ( $1->type && $1->type->forall ) forall = true; // remember generic type
    32243237                }
     
    32313244        | declaration_qualifier_list type_qualifier_list
    32323245                {
    3233                         if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     3246                        if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) {
     3247                                SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." );
     3248                        }
    32343249                        if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type
    32353250                }
     
    32623277                        $$ = $3; forall = false;
    32633278                        if ( $5 ) {
    3264                                 SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
     3279                                SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );
    32653280                                $$ = nullptr;
    32663281                        } // if
Note: See TracChangeset for help on using the changeset viewer.