Change the way tokens are compared for zeroth rule
The zeroth rule contains a token which has NULL at type. Because the
function cmp_token_type is used when comparing rules (items) it has to
be able to handle this NULL.
The supporting changes consist of changing the ft_token_dup function to
take pointer to token as input. Taking global static token caused some
error but was solved by passing pointer.
Function to free structs now handle NULL gracefully. This was
encountered because not all used structures are initialized yet.
The zeroth rule is added to generate a table, that returns the original
first token as a root of the table. The type of NULL cannot be achieved
any other way inside the table.rules.
This commit mainly concerns itself with the construction of the closure
table - the closures and the "first" tokens.
The first tokens could be precalculated but I did not want to do that
as that would require to either have a function with some static
variable (which is meh to clean up) or I would have create another
structure and pass it everywhere. It can be added later on.
This function could have been named ft_vec_insert_unique,
but that would invoke the need for insertion index which
I wanted to avoid because of the usage a set.
Lukas Jiriste [Fri, 28 Jun 2024 11:51:06 +0000 (13:51 +0200)]
Add some set functions defined on t_vec
The functions are defined on t_vec instead of implementing t_set
because the t_set struct would not be very useful. The lack of
structure is easy to emulate wth t_vec. The only advantage would be
uniqueness of elements.
Lukas Jiriste [Fri, 21 Jun 2024 09:49:45 +0000 (11:49 +0200)]
Make ft_parse inputs const, move token_free
After playing a little with the functions I thought it stupid to have
all tokens have their own memory for types that repeat so much.
The token_free function I implemented frees both members of token
which leads to multi-frees when reusing a string for type.
This is why I think it will be better to hide token_free again
and the user can decide what to allocate and what to free.
For this to be possible I have guarantee the tokens vector is not
changed inside the ft_parse function, so I've rewriten it a little
to use const.
Lukas Jiriste [Fri, 21 Jun 2024 08:57:50 +0000 (10:57 +0200)]
Fix bug, where NULLs appear inside tree
This bug was caused because the tree nodes are filled from the end
when reducing. Instead of just inserting to the start it was inserting
at the final position.
When inserting to vector outside of range all the nonexistent entries
are initialized to 0. If another insertion happes after that, the
0 entries are not filled but moved to make space for the new entry.
Lukas Jiriste [Fri, 21 Jun 2024 07:43:38 +0000 (09:43 +0200)]
Fix the code to actually produce a tree
As the previous commit was only checked to compile there were some
minor defects. Notably the parser stack was not initialized properly.
It has to return state_num 0 when empty, which was solved by inserting
a dummy state 0 wih no node attached.
Lukas Jiriste [Thu, 20 Jun 2024 15:54:43 +0000 (17:54 +0200)]
Implement the ft_parse function
I did not yet try whether it actually functions (it probably does not).
Because managing ft_parse_inner.h was harder than I imagined
and I wanted to focus on the ft_parse function, I returned
almost everything to ft_parse.h.
Lukas Jiriste [Wed, 17 Jan 2024 13:56:09 +0000 (14:56 +0100)]
Improve matrix handling, remove VEC_INIT macro
Improve matrix insertion by patching bugs and adding bounds checking.
Insert VEC_INIT macro as it is forbidden by the Norm.
Add ft_mat_access as matrix analog to ft_vec_access.
Lukas Jiriste [Sun, 14 Jan 2024 16:16:47 +0000 (17:16 +0100)]
Add a macro for t_vec initialization
Add macro for static t_vec initialization, because it needs a
compilation-time constant, which functions cannot (?) achieve.
This macro resolves to compound literal and lacks a check but should
be good enough.
Lukas Jiriste [Sat, 23 Dec 2023 11:47:27 +0000 (12:47 +0100)]
Implement matrix t_mat as a wrapper around t_vec
Implement new struct for matrix and some basic utilities. Everything
passes strict compilation and norminette, but may contain bugs in logic.
Testing recommended (though it will probably happen when this is
needed).
Extract ft_vec_forget from ft_vec_erase which functions as ft_vec_erase
with free_el = NULL.
Lukas Jiriste [Mon, 11 Dec 2023 19:07:39 +0000 (20:07 +0100)]
Remove void* arithmetic, conform to the Norm
Add -Wpedantic option for compilation to Makefile to catch all mistakes.
Cast void* to char* for any arithmetic done.
Split lines that are too long to fit the 80 char limit of the 42 Norm.
Lukas Jiriste [Mon, 11 Dec 2023 09:27:36 +0000 (10:27 +0100)]
Add some t_vec functions and change name
Add functions for inserting and erasing multiple elements.
Rename dir ft_vec to ft_arr and rename ft_vec.h to ft_arr.h for future
implementation of other array structures (matrices).
Lukas Jiriste [Sat, 9 Dec 2023 14:56:42 +0000 (15:56 +0100)]
Enforce header inclusion rules
The following rules are (to be) used:
-Sort header inclusion from local to global
-Always include header which declares the functions in file
-Only include header when it is neccesary for compilation
Lukas Jiriste [Fri, 3 Nov 2023 16:03:35 +0000 (17:03 +0100)]
Change subproject handling, add advanced list funcs
Turn submodules into standard folder.
- Submodules were probably not the correct choice int the first place
- Makefile handling of submodules was bad and hacky
Turn list handling to subproject ft_lst, add advanced list handling.
Change Makefile and header accordingly.
Lukas Jiriste [Tue, 3 Oct 2023 16:46:16 +0000 (18:46 +0200)]
Added ft_printf as a submodule.
Quite some changes where made in Makefile to make it work
and it is not pretty.
Update to libft.h by the ft_printf function prototype.
This branch will contain functions that don't crash in cases in which the std functions probably crash.
This functionality may be useful but is held on separate branch in order to have "pure" std functionality also.
Changed the functions so that they pass the alelievr/libft-unit-test.
ft_strtrim needs to also handle empty strings and strings containing only chars from set.