Skip to content
New issue

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

Issue 175: Added Support for Arrays (1D) #183

Merged
merged 43 commits into from
Jan 8, 2025
Merged

Issue 175: Added Support for Arrays (1D) #183

merged 43 commits into from
Jan 8, 2025

Conversation

KennyOliver
Copy link
Owner

- Rearranged sequence of logic to fix this, since `-` would indicate a number previously

#175
- Restructured `assignment` node in `ASTNode` to have `lhs` & `rhs`

#175
- Looking through the debugging output for the lexer, I realized that negative numbers were being tokenized as `-` followed by the positive version of the number.
- Updated `scan_array` to detect and correctly handle negative numbers (`-`) within array slices, ensuring that `-1` is tokenized as a single `TOKEN_INTEGER` instead of separate tokens for `-` and `1`.
- Modified `scan_number` to construct lexemes for negative numbers properly, including the `-` sign.
- Added conditions to differentiate between negative numbers and array operators (`^-`, `-^`) based on context.
- Included debug statements to verify lexeme capture during tokenization.
- Verified fixes with test cases for array slicing scenarios, including `[::-1]`, `[-5:-1:2]`, and mixed positive/negative indices.
- These changes now resolves issues where the lexer misinterpreted `-` in slices, leading to parsing errors like "Expected expression (found `-`)."

#175
- Refactored `ASTNode` to separate fields for distinct node types, preventing memory conflicts.
- Updated parser functions to use correct `ASTNodeType` for declarations and assignments.
- Fixed crash in `print_ast` caused by uninitialized or overlapping fields.
- Ensured proper memory initialization using calloc for zero-initialized nodes.
- Enhanced debugging and error handling for better resilience against invalid memory access.

#175
- Fixed `array[::-1]` returning empty array by correcting `end_index` logic for negative steps.
- Enhanced debug logs for slicing operations.

#175
- Prevented mutations on constant arrays by preserving the `is_constant` flag in `add_variable`.
- Enhanced `get_variable` to correctly handle and debug `TYPE_ARRAY` variables.
- Refactored `interpret_assignment` to delegate array operations to `interpret_array_operation` for consistent immutability enforcement.
- Verified fixes with test scripts and added debug logs for better diagnostics.

#175
- Fixed by passing correct node (`lhs_node`) to `interpret_array_operation` in `interpret_assigment`.

#175
@KennyOliver KennyOliver self-assigned this Jan 8, 2025
@KennyOliver KennyOliver linked an issue Jan 8, 2025 that may be closed by this pull request
4 tasks
@KennyOliver KennyOliver merged commit 51955b0 into main Jan 8, 2025
4 checks passed
@KennyOliver KennyOliver added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Basic Support for Arrays
1 participant