Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r6cebfef refc8f3e  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 20 22:03:04 2021
    13 // Update Count     : 5031
     12// Last Modified On : Fri Oct 15 09:20:17 2021
     13// Update Count     : 5163
    1414//
    1515
     
    3131// from ANSI90 to ANSI11 C are marked with the comment "C99/C11".
    3232
    33 // This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions All of the
     33// This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions. All of the
    3434// syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall (CFA), which
    3535// fixes several of C's outstanding problems and extends C with many modern language concepts. All of the syntactic
     
    6969        // 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
    7070        //    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
    71         //    i.e., u"a" U"b" L"c" is disallowed.
     71        //    e.g., u"a" U"b" L"c" is disallowed.
    7272
    7373        if ( from[0] != '"' ) {                                                         // encoding ?
     
    185185                type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
    186186        } // if
     187//      type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) );
    187188        return new ForCtrl(
    188189                distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
     
    309310%token ATassign                                                                                 // @=
    310311
    311 %type<tok> identifier
    312 %type<tok> identifier_or_type_name  attr_name
     312%type<tok> identifier                                   identifier_at                           identifier_or_type_name         attr_name
    313313%type<tok> quasi_keyword
    314314%type<constant> string_literal
     
    326326%type<en> conditional_expression                constant_expression                     assignment_expression           assignment_expression_opt
    327327%type<en> comma_expression                              comma_expression_opt
    328 %type<en> argument_expression_list_opt  argument_expression                     default_initializer_opt
     328%type<en> argument_expression_list_opt  argument_expression_list        argument_expression                     default_initializer_opt
    329329%type<ifctl> if_control_expression
    330330%type<fctl> for_control_expression              for_control_expression_list
     
    558558        IDENTIFIER
    559559        | quasi_keyword
     560        ;
     561
     562identifier_at:
     563        identifier
    560564        | '@'                                                                                           // CFA
    561565                { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
     
    692696        // empty
    693697                { $$ = nullptr; }
    694         | argument_expression
     698        | argument_expression_list
     699        ;
     700
     701argument_expression_list:
     702        argument_expression
    695703        | argument_expression_list_opt ',' argument_expression
    696704                { $$ = (ExpressionNode *)($1->set_last( $3 )); }
     
    730738        | FLOATINGconstant fraction_constants_opt
    731739                { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
    732         | identifier fraction_constants_opt
     740        | identifier_at fraction_constants_opt                          // CFA, allow anonymous fields
    733741                {
    734742                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
     
    10831091        comma_expression_opt ';'
    10841092                { $$ = new StatementNode( build_expr( $1 ) ); }
     1093        | MUTEX '(' ')' comma_expression ';'
     1094                { $$ = new StatementNode( build_mutex( nullptr, new StatementNode( build_expr( $4 ) ) ) ); }
     1095                // { SemanticError( yylloc, "Mutex expression is currently unimplemented." ); $$ = nullptr; }
    10851096        ;
    10861097
     
    11811192
    11821193iteration_statement:
    1183         WHILE '(' push if_control_expression ')' statement pop
    1184                 { $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); }
    1185         | WHILE '(' ')' statement                                                       // CFA => while ( 1 )
     1194        WHILE '(' ')' statement                                                         // CFA => while ( 1 )
    11861195                { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
    1187         | DO statement WHILE '(' comma_expression ')' ';'
    1188                 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
     1196        | WHILE '(' if_control_expression ')' statement         %prec THEN
     1197                { $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
     1198        | WHILE '(' if_control_expression ')' statement ELSE statement // CFA
     1199                { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    11891200        | DO statement WHILE '(' ')' ';'                                        // CFA => do while( 1 )
    11901201                { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
    1191         | FOR '(' push for_control_expression_list ')' statement pop
    1192                 { $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 ) ) ); }
     1202        | DO statement WHILE '(' comma_expression ')' ';'       %prec THEN
     1203                { $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
     1204        | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
     1205                { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    11931206        | FOR '(' ')' statement                                                         // CFA => for ( ;; )
    11941207                { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
     1208        | FOR '(' for_control_expression_list ')' statement     %prec THEN
     1209                { $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
     1210        | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
     1211                { SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
    11951212        ;
    11961213
     
    13381355with_statement:
    13391356        WITH '(' tuple_expression_list ')' statement
    1340                 {
    1341                         $$ = new StatementNode( build_with( $3, $5 ) );
    1342                 }
     1357                { $$ = new StatementNode( build_with( $3, $5 ) ); }
    13431358        ;
    13441359
    13451360// If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
    13461361mutex_statement:
    1347         MUTEX '(' argument_expression_list_opt ')' statement
     1362        MUTEX '(' argument_expression_list ')' statement
    13481363                { $$ = new StatementNode( build_mutex( $3, $5 ) ); }
    13491364        ;
     
    24452460        | simple_assignment_operator initializer        { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); }
    24462461        | '=' VOID                                                                      { $$ = new InitializerNode( true ); }
     2462        | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
    24472463        ;
    24482464
     
    24582474        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    24592475        | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2460         | initializer_list_opt ',' designation initializer
    2461                 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
     2476        | initializer_list_opt ',' designation initializer { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
    24622477        ;
    24632478
     
    24742489designation:
    24752490        designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    2476         | identifier ':'                                                                        // GCC, field name
     2491        | identifier_at ':'                                                                     // GCC, field name
    24772492                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    24782493        ;
     
    24862501
    24872502designator:
    2488         '.' identifier                                                                          // C99, field name
     2503        '.' identifier_at                                                                       // C99, field name
    24892504                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    24902505        | '[' push assignment_expression pop ']'                        // C99, single array element
     
    29182933
    29192934paren_identifier:
    2920         identifier
     2935        identifier_at
    29212936                { $$ = DeclarationNode::newName( $1 ); }
    29222937        | '(' paren_identifier ')'                                                      // redundant parenthesis
Note: See TracChangeset for help on using the changeset viewer.