Changeset afe9e45


Ignore:
Timestamp:
Feb 25, 2022, 6:19:16 PM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
41870a5
Parents:
08ed947
Message:

add more detailed syntax-error messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r08ed947 rafe9e45  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Feb 19 09:47:20 2022
    13 // Update Count     : 5218
     12// Last Modified On : Fri Feb 25 17:54:56 2022
     13// Update Count     : 5262
    1414//
    1515
     
    610610        // | RESUME '(' comma_expression ')' compound_statement
    611611        //      { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; }
     612        | IDENTIFIER IDENTIFIER                                                         // syntax error
     613                {
     614                        SemanticError( yylloc, ::toString( "Adjacent identifiers are not meaningful in an expression. "
     615                                                                                           "Possible problem is identifier \"", *$1.str,
     616                                                                                           "\" is a misspelled typename or an incorrectly specified type name, "
     617                                                                                           "e.g., missing generic parameter or missing struct/union/enum before typename." ) );
     618                        $$ = nullptr;
     619                }
     620        | IDENTIFIER direct_type                                                        // syntax error
     621                {
     622                        SemanticError( yylloc, ::toString( "Identifier \"", *$1.str, "\" cannot appear before a type. "
     623                                                                                           "Possible problem is misspelled storage or CV qualifier." ) );
     624                        $$ = nullptr;
     625                }
    612626        ;
    613627
     
    10521066        identifier_or_type_name ':' attribute_list_opt statement
    10531067                { $$ = $4->add_label( $1, $3 ); }
    1054         | identifier_or_type_name ':' attribute_list_opt error
    1055                 { SemanticError( yylloc, "previous label must be associated with a statement (where a declaration is not a statement). Move the label or terminate with a semi-colon." ); $$ = nullptr; }
     1068        | identifier_or_type_name ':' attribute_list_opt error // syntax error
     1069                {
     1070                        SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, "
     1071                                                                                           "where a declaration, case, or default is not a statement. "
     1072                                                                                           "Move the label or terminate with a semi-colon." ) );
     1073                        $$ = nullptr;
     1074                }
    10561075        ;
    10571076
     
    10881107        | statement_list_nodecl statement
    10891108                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    1090         | statement_list_nodecl error
    1091                 { SemanticError( yylloc, "declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
     1109        | statement_list_nodecl error                                           // syntax error
     1110                { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
    10921111        ;
    10931112
     
    11161135                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    11171136                }
    1118         | SWITCH '(' comma_expression ')' '{' error '}'         // CFA
    1119                 { SemanticError( yylloc, "only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1137        | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, syntax error
     1138                { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    11201139        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    11211140                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
     
    11251144                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    11261145                }
    1127         | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA
    1128                 { SemanticError( yylloc, "only declarations can appear before the list of case clauses." ); $$ = nullptr; }
     1146        | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, syntax error
     1147                { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    11291148        ;
    11301149
     
    11651184
    11661185case_label:                                                                                             // CFA
    1167         CASE error
    1168                 { SemanticError( yylloc, "missing case list after case." ); $$ = nullptr; }
     1186        CASE error                                                                                      // syntax error
     1187                { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; }
    11691188        | CASE case_value_list ':'                                      { $$ = $2; }
    1170         | CASE case_value_list error
    1171                 { SemanticError( yylloc, "missing colon after case list." ); $$ = nullptr; }
     1189        | CASE case_value_list error                                            // syntax error
     1190                { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
    11721191        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
    11731192                // A semantic check is required to ensure only one default clause per switch/choose statement.
    1174         | DEFAULT error
    1175                 { SemanticError( yylloc, "missing colon after default." ); $$ = nullptr; }
     1193        | DEFAULT error                                                                         //  syntax error
     1194                { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; }
    11761195        ;
    11771196
     
    14101429        | when_clause_opt ELSE statement
    14111430                { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
    1412                 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1413         | when_clause_opt timeout statement WOR ELSE statement
     1431        // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1432        | when_clause_opt timeout statement WOR ELSE statement // syntax error
    14141433                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    14151434        | when_clause_opt timeout statement WOR when_clause ELSE statement
Note: See TracChangeset for help on using the changeset viewer.