Changeset 1d71208 for src/Parser


Ignore:
Timestamp:
Jun 23, 2021, 4:59:37 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
27434e9
Parents:
6448f7d
Message:

Implementing new-array subscripting syntax, in which a[x,y,z] now means the same as ax,y,z?.

This behaviour immediately replaces a syntax error that prohibits the -[-,-,-] syntax. The prior state showed that the C programs we compile don't use the C-compatible meaning of commas in subscripts.

This behaviour ultimately replaces the C-compatible interpretation in which a[x,y,z] means a[(x,y,z)] or, roughly, ({ x; y; a[z]; }).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/parser.yy

    r6448f7d r1d71208  
    635635postfix_expression:
    636636        primary_expression
    637         | postfix_expression '[' assignment_expression ',' comma_expression ']'
    638                 // { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_binary_val( OperKinds::Index, $3, $5 ) ) ) ); }
    639                 { SemanticError( yylloc, "New array subscript is currently unimplemented." ); $$ = nullptr; }
     637        | postfix_expression '[' assignment_expression ',' tuple_expression_list ']'
     638                        // Historic, transitional: Disallow commas in subscripts.
     639                        // 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; }
     641                        // Current: Commas in subscripts make tuples.
     642                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }
    640643        | postfix_expression '[' assignment_expression ']'
    641644                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
Note: See TracChangeset for help on using the changeset viewer.