Changeset d824715


Ignore:
Timestamp:
Mar 14, 2022, 4:52:35 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
33b7d49
Parents:
c7f2d9b
Message:

support reverse array subscript, 3[a] => a[3], 3abc? => "abc"[3]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    rc7f2d9b rd824715  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 25 17:54:56 2022
    13 // Update Count     : 5262
     12// Last Modified On : Mon Mar 14 16:35:29 2022
     13// Update Count     : 5276
    1414//
    1515
     
    652652                        // Historic, transitional: Disallow commas in subscripts.
    653653                        // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts.
    654                 // { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
    655654                        // Current: Commas in subscripts make tuples.
    656655                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
     
    661660                // equivalent to the old x[i,j].
    662661                { $$ = 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 ) ); }
    663666        | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call
    664667                {
Note: See TracChangeset for help on using the changeset viewer.