ArcaneScript is a custom programming language developed to explore language design and interpretation. This project includes the development of both the ArcaneScript language and its online Runner.
This PR enhances the array access functionality in ArcaneScript by supporting expressions (including variables) as array indices instead of limiting it to numeric literals.
Fixes #1
Changes Made
Grammar Update: Modified ArcaneGrammar7.grm to replace NumberLiteral with <Expression> in array access rules.
ArrayAccess.java: Updated to process and evaluate expressions as indices, including type checking and error handling for invalid index types and out-of-bounds access.
ArrayValue.java: Introduced a new class to handle array access when used as a value, ensuring consistency in behavior.
Testing and Validation
Tested with array access scenarios involving numeric literals and variable-based indices.
Verified behavior with both value retrieval (e.g., println x[i]) and assignment scenarios (a = x[i]).
Rebuilt and deployed the ArcaneInterpreter and ArcaneHttpServer to ensure changes are correctly integrated.
Notes
Ensure all related grammar rules dealing with array access are updated to use <Expression> instead of NumberLiteral.
Example tested:
array x[2] = {0, 1};
for (i = 0; i < 2; i = i + 1;) {
println x[i];
}
This works as expected with both variable and literal indices.
Let me know if there are any questions or additional updates required!
Summary
This PR enhances the array access functionality in ArcaneScript by supporting expressions (including variables) as array indices instead of limiting it to numeric literals.
Fixes #1
Changes Made
Grammar Update: Modified
ArcaneGrammar7.grm
to replaceNumberLiteral
with<Expression>
in array access rules.<Value> ::= Identifier '[' <Expression> ']'
<Statement> ::= Identifier '=' Identifier '[' <Expression> ']' ';'
Code Modifications:
Testing and Validation
println x[i]
) and assignment scenarios (a = x[i]
).Notes
<Expression>
instead ofNumberLiteral
.This works as expected with both variable and literal indices.
Let me know if there are any questions or additional updates required!