Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rd824715 rf135b50  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar 14 16:35:29 2022
    13 // Update Count     : 5276
     12// Last Modified On : Tue Feb  1 11:06:13 2022
     13// Update Count     : 5167
    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                 }
    626612        ;
    627613
     
    652638                        // Historic, transitional: Disallow commas in subscripts.
    653639                        // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
     640                // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    654641                        // Current: Commas in subscripts make tuples.
    655642                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
     
    660647                // equivalent to the old x[i,j].
    661648                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    662         | constant '[' assignment_expression ']'                        // 3[a], 'a'[a], 3.5[a]
    663                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
    664         | string_literal '[' assignment_expression ']'          // "abc"[3], 3["abc"]
    665                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }
    666649        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    667650                {
     
    10691052        identifier_or_type_name ':' attribute_list_opt statement
    10701053                { $$ = $4->add_label( $1, $3 ); }
    1071         | identifier_or_type_name ':' attribute_list_opt error // syntax error
    1072                 {
    1073                         SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, "
    1074                                                                                            "where a declaration, case, or default is not a statement. "
    1075                                                                                            "Move the label or terminate with a semi-colon." ) );
    1076                         $$ = nullptr;
    1077                 }
    10781054        ;
    10791055
     
    11101086        | statement_list_nodecl statement
    11111087                { assert( $1 ); $1->set_last( $2 ); $$ = $1; }
    1112         | statement_list_nodecl error                                           // syntax error
    1113                 { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }
    11141088        ;
    11151089
     
    11191093        | MUTEX '(' ')' comma_expression ';'
    11201094                { $$ = new StatementNode( build_mutex( nullptr, new StatementNode( build_expr( $4 ) ) ) ); }
     1095                // { SemanticError( yylloc, "Mutex expression is currently unimplemented." ); $$ = nullptr; }
    11211096        ;
    11221097
     
    11381113                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    11391114                }
    1140         | SWITCH '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1141                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    11421115        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    11431116                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
     
    11471120                        $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;
    11481121                }
    1149         | CHOOSE '(' comma_expression ')' '{' error '}'         // CFA, syntax error
    1150                 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; }
    11511122        ;
    11521123
     
    11871158
    11881159case_label:                                                                                             // CFA
    1189         CASE error                                                                                      // syntax error
    1190                 { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; }
    1191         | CASE case_value_list ':'                                      { $$ = $2; }
    1192         | CASE case_value_list error                                            // syntax error
    1193                 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; }
     1160        CASE case_value_list ':'                                        { $$ = $2; }
    11941161        | DEFAULT ':'                                                           { $$ = new StatementNode( build_default() ); }
    11951162                // A semantic check is required to ensure only one default clause per switch/choose statement.
    1196         | DEFAULT error                                                                         //  syntax error
    1197                 { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; }
    1198         ;
     1163        ;
     1164
     1165//label_list_opt:
     1166//      // empty
     1167//      | identifier_or_type_name ':'
     1168//      | label_list_opt identifier_or_type_name ':'
     1169//      ;
    11991170
    12001171case_label_list:                                                                                // CFA
     
    12261197                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
    12271198        | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA
     1199                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    12281200                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ), $7 ) ); }
    12291201        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
     
    12321204                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
    12331205        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
     1206                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    12341207                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ), $8 ) ); }
    12351208        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
     
    12381211                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
    12391212        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
     1213                // { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    12401214                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ), $7 ) ); }
    12411215        ;
     
    14321406        | when_clause_opt ELSE statement
    14331407                { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); }
    1434         // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
    1435         | when_clause_opt timeout statement WOR ELSE statement // syntax error
     1408                // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless)
     1409        | when_clause_opt timeout statement WOR ELSE statement
    14361410                { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }
    14371411        | when_clause_opt timeout statement WOR when_clause ELSE statement
     
    23032277        ;
    23042278
    2305 enum_type:                                                                                              // enum
     2279enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed );                                                                                         // enum
    23062280        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    2307                 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }
     2281                { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); }
    23082282        | ENUM attribute_list_opt identifier
    23092283                { typedefTable.makeTypedef( *$3 ); }
    23102284          '{' enumerator_list comma_opt '}'
    2311                 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     2285                { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); }
    23122286        | ENUM attribute_list_opt typedef_name                          // unqualified type name
    23132287          '{' enumerator_list comma_opt '}'
    2314                 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }
     2288                { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); }
    23152289        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}'
    23162290                {
    2317                         if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    2318                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
    2319                 }
    2320         | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt
     2291                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 )
     2292                        { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     2293                        // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2294
     2295                        $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 )  -> addEnumBase( $3 );
     2296                        // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 );
     2297                }
     2298        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier
    23212299                {
    23222300                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
     
    23252303          '{' enumerator_list comma_opt '}'
    23262304                {
    2327                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2305                        $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2306                        // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23282307                }
    23292308        | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}'
     
    23312310                        if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }
    23322311                        typedefTable.makeTypedef( *$6->name );
    2333                         SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr;
     2312                        $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 );
     2313                        // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 );
    23342314                }
    23352315        | enum_type_nobody
     
    23382318enum_type_nobody:                                                                               // enum - {...}
    23392319        ENUM attribute_list_opt identifier
    2340                 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }
     2320                { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }
    23412321        | ENUM attribute_list_opt type_name                                     // qualified type name
    2342                 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }
     2322                { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }
    23432323        ;
    23442324
     
    27552735        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    27562736                { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) ); }
    2757         | EXTERN STRINGliteral
    2758                 {
    2759                         linkageStack.push( linkage );                           // handle nested extern "C"/"Cforall"
    2760                         linkage = LinkageSpec::update( yylloc, linkage, $2 );
    2761                 }
    2762           up external_definition down
    2763                 {
    2764                         linkage = linkageStack.top();
    2765                         linkageStack.pop();
    2766                         $$ = $5;
    2767                 }
    27682737        | EXTERN STRINGliteral                                                          // C++-style linkage specifier
    27692738                {
Note: See TracChangeset for help on using the changeset viewer.