Changeset 99fc978


Ignore:
Timestamp:
May 21, 2025, 1:38:02 PM (4 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
1a40870
Parents:
d92bc97
Message:

fix parsing problem with array bound and assertion list, set up parsing dimension/subscript for new arrays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rd92bc97 r99fc978  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 18 15:23:42 2025
    13 // Update Count     : 7283
     12// Last Modified On : Wed May 21 11:25:13 2025
     13// Update Count     : 7295
    1414//
    1515
     
    777777postfix_expression:
    778778        primary_expression
    779         | postfix_expression '[' assignment_expression ',' tuple_expression_list ']'
     779        | postfix_expression '[' tuple_expression_list ']' // CFA
    780780                // Historic, transitional: Disallow commas in subscripts.
    781781                // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
    782782                // Current: Commas in subscripts make tuples.
    783                 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, new ExpressionNode( build_tuple( yylloc, $3->set_last( $5 ) ) ) ) ); }
    784         | postfix_expression '[' assignment_expression ']'
    785                 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    786                 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    787                 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    788                 // equivalent to the old x[i,j].
    789                 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
     783                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, new ExpressionNode( build_tuple( yylloc, $3 ) ) ) ); }
    790784        | constant '[' assignment_expression ']'                        // 3[a], 'a'[a], 3.5[a]
    791785                { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }
     
    31323126          type_initializer_opt assertion_list_opt
    31333127                { $$ = DeclarationNode::newTypeParam( $2, $1 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
    3134         | '[' identifier_or_type_name ']'
     3128        | '[' identifier_or_type_name ']' assertion_list_opt
    31353129                {
    31363130                        typedefTable.addToScope( *$2, TYPEDIMname, "type_parameter 3" );
    3137                         $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dimension, $2 );
     3131                        $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dimension, $2 )->addAssertions( $4 );
    31383132                }
    31393133        // | type_specifier identifier_parameter_declarator
     
    40354029                { $$ = DeclarationNode::newArray( nullptr, nullptr, false )->addArray( $3 ); }
    40364030                // Cannot use constant_expression because of tuples => semantic check
     4031        | '[' assignment_expression ',' ']'                                     // CFA
     4032                { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
     4033                // { $$ = DeclarationNode::newArray( $2, nullptr, false ); }
    40374034        | '[' assignment_expression ',' comma_expression ']' // CFA
    4038                 { $$ = DeclarationNode::newArray( $2, nullptr, false )->addArray( DeclarationNode::newArray( $4, nullptr, false ) ); }
    4039                 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
     4035                { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; }
     4036                // { $$ = DeclarationNode::newArray( $2, nullptr, false )->addArray( DeclarationNode::newArray( $4, nullptr, false ) ); }
    40404037
    40414038                // If needed, the following parses and does not use comma_expression, so the array structure can be built.
Note: See TracChangeset for help on using the changeset viewer.