-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement Basic Support for Arrays #175
Labels
Comments
KennyOliver
added
documentation
Improvements or additions to documentation
enhancement
New feature or request
labels
Jan 3, 2025
Proposed Arrays DesignI've thought about the design for my arrays and have come to this! Syntax DesignNote All array operations do not mutate original array to reduce confusion.
Reviewing the Discussion Points
|
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
- Rearranged sequence of logic to fix this, since `-` would indicate a number previously #175
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
- Restructured `assignment` node in `ASTNode` to have `lhs` & `rhs` #175
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 6, 2025
- 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
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
- 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
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 7, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
Reopening — GitHub auto closed this issue because the linked branch was merged, but I'm still working on it. |
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
- Can be used to run all tests in sequence #175
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
KennyOliver
added a commit
that referenced
this issue
Jan 8, 2025
- Running `run_tests.sh` may give something this: `flavor(77629,0x1f3df8840) malloc: nano zone abandoned due to inability to reserve vm space.`. - This only occurs only with this iterative script, but I don't get these warnings/errors/notices with `all.flv`, so this seems to be a 'non-issue'; at least for now. #175
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Implement Basic Support for Arrays
Description
I need to implement support for arrays to enable robust & versatile data handling. Arrays should act as ordered collections of elements, allowing for functional operations and seamless integration with the functional programming paradigm. With FlavorLang, I think that arrays should be treated as literals, with various functions provided in the standard library for handling them.
Features to Implement
1. Basic Operations
[1, 2, 3]
syntax.array[0]
).length(array)
in the standard library to return the size of the array.2. Array Manipulation
append(array, element)
— Adds an element to the end.prepend(array, element)
— Adds an element to the start.insert(array, index, element)
— Adds an element to the array after the specified index.array1 + array2
— Combines two arrays.[start:end:step]
syntax (e.g.,array[1:3]
,array[::-1]
).3. Transformation
array[::-1]
— Reverses the array.4. Error Handling
a[10]
).a[0:4:0]
).const
arrays cannot be modified.Future Feature Ideas
1. Functional Operations
map(array, function)
— Applies a function to each element.filter(array, function)
— Returns elements that satisfy a predicate.reduce(array, function)
— Combines elements into a single value.2. Search & Indexing
index_of(array, element)
— Finds the index of the first matching element.contains(array, element)
— Checks if an array contains a specific element.3. Transformation
sort(array, compareFunction?)
— Sorts elements in order.sum(array)
,min(array)
,max(array)
.Potential Syntax
[1, 2, 3]
a + b
orappend(array, element)
return new arrays.Tasks
length
, access).[start:end:step]
) with error handling for invalid cases.const
arrays.References / Inspiration
Array.prototype.map
, etc.).Vec
for immutability & deep copying.Discussion Points / Considerations
map
for performance reasons?The text was updated successfully, but these errors were encountered: