Changeset 996c8ed


Ignore:
Timestamp:
Sep 26, 2022, 8:57:28 AM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
36cb4d9, f704974
Parents:
160f1aa
Message:

add better syntax error-messages for certain cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r160f1aa r996c8ed  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 27 13:21:28 2022
    13 // Update Count     : 5661
     12// Last Modified On : Mon Sep 26 08:45:53 2022
     13// Update Count     : 5704
    1414//
    1515
     
    247247        } // if
    248248} // forCtrl
     249
     250static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) {
     251        SemanticError( yylloc, ::toString( "Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"
     252                                   "Possible cause is misspelled type name or missing generic parameter." ) );
     253} // IdentifierBeforeIdentifier
     254
     255static void IdentifierBeforeType( string & identifier, const char * kind ) {
     256        SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"
     257                                   "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) );
     258} // IdentifierBeforeType
    249259
    250260bool forall = false;                                                                    // aggregate have one or more forall qualifiers ?
     
    651661        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
    652662        | IDENTIFIER IDENTIFIER                                                         // syntax error
    653                 {
    654                         SemanticError( yylloc, ::toString( "Adjacent identifiers are not meaningful in an expression. "
    655                                                                                            "Possible problem is identifier \"", *$1.str,
    656                                                                                            "\" is a misspelled typename or an incorrectly specified type name, "
    657                                                                                            "e.g., missing generic parameter or missing struct/union/enum before typename." ) );
    658                         $$ = nullptr;
    659                 }
    660         | IDENTIFIER direct_type                                                        // syntax error
    661                 {
    662                         SemanticError( yylloc, ::toString( "Identifier \"", *$1.str, "\" cannot appear before a type. "
    663                                                                                            "Possible problem is misspelled storage or CV qualifier." ) );
    664                         $$ = nullptr;
    665                 }
     663                { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; }
     664        | IDENTIFIER type_qualifier                                                     // syntax error
     665                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
     666        | IDENTIFIER storage_class                                                      // syntax error
     667                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
     668        | IDENTIFIER basic_type_name                                            // syntax error
     669                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
     670        | IDENTIFIER TYPEDEFname                                                        // syntax error
     671                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
     672        | IDENTIFIER TYPEGENname                                                        // syntax error
     673                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    666674        ;
    667675
     
    29933001                { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); }
    29943002        | declaration
     3003        | IDENTIFIER IDENTIFIER
     3004                { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; }
     3005        | IDENTIFIER type_qualifier                                                     // syntax error
     3006                { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; }
     3007        | IDENTIFIER storage_class                                                      // syntax error
     3008                { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; }
     3009        | IDENTIFIER basic_type_name                                            // syntax error
     3010                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
     3011        | IDENTIFIER TYPEDEFname                                                        // syntax error
     3012                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
     3013        | IDENTIFIER TYPEGENname                                                        // syntax error
     3014                { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; }
    29953015        | external_function_definition
    29963016        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
Note: See TracChangeset for help on using the changeset viewer.