We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Based on the current syntax grammar, array and list elements are only accessible via the following rule in expr:
expr
expr // ... | assignable #AssignableExpression | literal #LiteralExpression ; assignable : ident #SimpleAssignable | ident LT expr GT #ListAssignable | ident LBRACKET expr RBRACKET #ArrayAssignable ;
This means that array and list elements cannot be accessed unless they are in the first dimension and their collection is a variable.
Test to see whether this problem actually exists. Do these scripts (1) compile? and (2) behave correctly?
() { int arr_elem = [ 6, 5, 3 ][1]; print(arr_elem); // expected: "5" char list_elem = < 'H', 'a', 't', 't', 'e', 'r' ><3>; print(list_elem); // expected: "t" }
() { int[][] matrix = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ] ]; print(matrix[2][2]); // expected: "11" }
expr // ... | expr LBRACKET expr RBRACKET #ArrayIndexExpression // new production | expr LT expr RT #ListIndexExpression // new production // ... | ident #VariableExpression // replaces #AssignableExpression | literal #LiteralExpression ;
assignable
#ArrayIndexExpression
#ListIndexExpression
The text was updated successfully, but these errors were encountered:
jbunke
No branches or pull requests
Problem
Based on the current syntax grammar, array and list elements are only accessible via the following rule in
expr
:This means that array and list elements cannot be accessed unless they are in the first dimension and their collection is a variable.
Tests
Test to see whether this problem actually exists. Do these scripts (1) compile? and (2) behave correctly?
Accessing an element of an explicit collection
Accessing a second-dimension collection element
Potential grammar fix
assignable
should remain unchanged, but only be used for assignmentsexpr
that#ArrayIndexExpression
and#ListIndexExpression
should goThe text was updated successfully, but these errors were encountered: