Lukas Jiriste [Thu, 18 Jul 2024 11:32:26 +0000 (13:32 +0200)]
Fix infinite recursion
The previous commit solved some wierd things around the add_first
function. These were created because of my misunderstanding of the
process but also (almost) prevented infinite recursion.
The infinite recurson is caused when a search for a first (nonterminal)
tokens encounteres the original token, because then it searches for it
again and is able to again find the token along the search.
The solution is to make the algorithm log what nonterminals it already
went through so that it does not try to find their first tokens during
the search for their first tokens.
Lukas Jiriste [Thu, 18 Jul 2024 09:49:55 +0000 (11:49 +0200)]
Repair some oddities in finding the first tokens
Lukas Jiriste [Thu, 11 Jul 2024 20:44:57 +0000 (22:44 +0200)]
Make ft_parse ablle to follow rule to empty token
Lukas Jiriste [Thu, 11 Jul 2024 18:16:11 +0000 (20:16 +0200)]
Remove collapse_closure function and attributes
The collapse_closure is not needed for correct function. It may be added
later on as an memory optimization.
Lukas Jiriste [Thu, 11 Jul 2024 18:08:39 +0000 (20:08 +0200)]
Fix handling if the zeroth rule
Removing the zeroth rule before the translation makes all the items
point one rule ahaed. So instead the rule number is decreased by one
the zeroth rule reduce is converted to accept.
Lukas Jiriste [Thu, 11 Jul 2024 17:58:27 +0000 (19:58 +0200)]
Add empty token recognition in translation to table
Lukas Jiriste [Wed, 10 Jul 2024 19:36:35 +0000 (21:36 +0200)]
Fix initialization of table rows
The initialization was caused by an inappropriate use of
ft_vec_insert_range. I was not sure whether it fills the range with the
single element or whether it insert range and I misread the source code
Lukas Jiriste [Wed, 10 Jul 2024 18:41:35 +0000 (20:41 +0200)]
Fix wrong pointer depth and gotos offset
The translation function accessed t_generator_state * instead of the
correct t_generator_state**.
The gotos vector in the table rows is indexed from 0 but uses the tokens
after the eof_token hence the index needs to be offset.
Lukas Jiriste [Wed, 10 Jul 2024 17:34:30 +0000 (19:34 +0200)]
Add the translation from state graph to table
This compiles but crashes.
Lukas Jiriste [Tue, 9 Jul 2024 09:08:27 +0000 (11:08 +0200)]
Free item copy in fill_closure
Lukas Jiriste [Mon, 8 Jul 2024 07:21:58 +0000 (09:21 +0200)]
Fix segmentation fault in fill_closure
When the add_predictions inside fill_closure has to enlarge closure to
add a new item, the original item pointer points to freed memory.
This is solved by making a copy.
Lukas Jiriste [Sun, 7 Jul 2024 07:48:11 +0000 (09:48 +0200)]
Make the generator count the terminal symbols
Lukas Jiriste [Sun, 7 Jul 2024 07:18:47 +0000 (09:18 +0200)]
Fix double free
Because the goto_tokens used tokens from table instead of their copies
and were freed when generator states were cleared, the table tokens
then contained pointers to freed memory which were to be used.
There are two ways to fix this. Either not free the tokens in
goto_tokens or append copies. I opted for the latter because every part
of the generator code uses copies too. It may be rewritten to use the
table tokens later on to save memory.
Lukas Jiriste [Fri, 5 Jul 2024 10:23:05 +0000 (12:23 +0200)]
Fix function freeing the parsing generator states
This function was made under wrong assumptions.
Lukas Jiriste [Fri, 5 Jul 2024 10:18:09 +0000 (12:18 +0200)]
Fix index reset before new loop
Lukas Jiriste [Fri, 5 Jul 2024 10:16:03 +0000 (12:16 +0200)]
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.
Lukas Jiriste [Fri, 5 Jul 2024 10:13:52 +0000 (12:13 +0200)]
Fix accessing generator states
This part was written under the assumption that t_vec states holds
t_generator_state instead of the t_generator_state*
Lukas Jiriste [Fri, 5 Jul 2024 07:41:49 +0000 (09:41 +0200)]
Fix wrong element insertion
Instead of a copy the original token was inserted. This caused the
elements sharing a token to be changed when only one shoud have been
changed.
Lukas Jiriste [Thu, 4 Jul 2024 15:03:13 +0000 (17:03 +0200)]
Fix some aspects of fill_closure function
Lukas Jiriste [Thu, 4 Jul 2024 12:45:37 +0000 (14:45 +0200)]
Change the code to accommodate the zeroth rule
Lukas Jiriste [Thu, 4 Jul 2024 12:25:53 +0000 (14:25 +0200)]
Implement is_at_mark
I've probably just forgotten to implement this function earlier.
Lukas Jiriste [Thu, 4 Jul 2024 11:27:40 +0000 (13:27 +0200)]
Implement token_categorize
This function fills the tokens t_vec with the language tokens.
It first lists terminal tokens, then end of file token, then
nonterminal tokens.
Lukas Jiriste [Thu, 4 Jul 2024 10:32:26 +0000 (12:32 +0200)]
Add first kernel construction and its support
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.
Lukas Jiriste [Thu, 4 Jul 2024 08:28:43 +0000 (10:28 +0200)]
Implement another part of the generator
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.
Lukáš Jiřiště [Thu, 27 Jun 2024 18:50:02 +0000 (20:50 +0200)]
Implement a big part of the parsing table generator
Lukas Jiriste [Fri, 5 Jul 2024 08:33:01 +0000 (10:33 +0200)]
Fix infinite loop
Lukas Jiriste [Thu, 4 Jul 2024 14:38:34 +0000 (16:38 +0200)]
Fix wrong malloc and infinite loop in ft_vec
Lukas Jiriste [Thu, 4 Jul 2024 08:24:45 +0000 (10:24 +0200)]
Add the ft_vec_setinsert
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 12:13:22 +0000 (14:13 +0200)]
Add function for equating two t_vecs
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, 28 Jun 2024 10:35:06 +0000 (12:35 +0200)]
Add a function to deep copy a t_vec
Lukas Jiriste [Thu, 27 Jun 2024 07:13:43 +0000 (09:13 +0200)]
Print also the contents of tokens
This makes debugging easier, though the output is harder to read
Lukas Jiriste [Fri, 21 Jun 2024 14:47:58 +0000 (16:47 +0200)]
Change function names to prevent naming colision
Lukas Jiriste [Fri, 21 Jun 2024 13:51:15 +0000 (15:51 +0200)]
Add tags to .gitignore
Lukas Jiriste [Fri, 21 Jun 2024 13:49:15 +0000 (15:49 +0200)]
Improve the documentation of limitations
Lukas Jiriste [Fri, 21 Jun 2024 13:44:09 +0000 (15:44 +0200)]
Refactor ft_parse.c to comply with the Norm
Lukas Jiriste [Fri, 21 Jun 2024 13:24:52 +0000 (15:24 +0200)]
Fix indentation
Lukas Jiriste [Fri, 21 Jun 2024 13:23:51 +0000 (15:23 +0200)]
Refactor functions to comply with the Norm
Lukas Jiriste [Fri, 21 Jun 2024 12:08:22 +0000 (14:08 +0200)]
Refactor to better comply with the Norm
Lukas Jiriste [Fri, 21 Jun 2024 11:09:19 +0000 (13:09 +0200)]
Make ft_parse_tree_print comply with the Norm
Lukas Jiriste [Fri, 21 Jun 2024 11:03:35 +0000 (13:03 +0200)]
Improve formatting of ft_parsing_table_printf
The token names in the output header are now limitedr
to the column width.
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 09:48:16 +0000 (11:48 +0200)]
Add const version of ft_vec_access
Lukas Jiriste [Fri, 21 Jun 2024 09:22:40 +0000 (11:22 +0200)]
Fix memory leak
This leak was caused by carelessness when working with malloc and t_vec
at the same time.
Lukas Jiriste [Fri, 21 Jun 2024 09:09:49 +0000 (11:09 +0200)]
Make ft_parse_tree_print handle NULLs gracefully
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 08:34:09 +0000 (10:34 +0200)]
Implement printing function for parsing tree
This is mainly done for debugging. This does not scale to arbitrary
large trees automatically - the output will be garbled.
Lukas Jiriste [Fri, 21 Jun 2024 07:48:48 +0000 (09:48 +0200)]
Fix forward declaration to be usable by user
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 [Thu, 20 Jun 2024 15:50:54 +0000 (17:50 +0200)]
Add a stack structure
Add a classic FILO stack with push, top, pop and some other functions.
It is basically just a wrapper for t_vec.
It is added into a new directory ft_struct. I should have made it
instead of the ft_arr dir. I may later move t_vec and t_mat to
ft_struct.
Lukas Jiriste [Thu, 20 Jun 2024 11:58:48 +0000 (13:58 +0200)]
Fix indentation
Lukas Jiriste [Thu, 20 Jun 2024 11:57:51 +0000 (13:57 +0200)]
Refactor parsing table loading
Lukas Jiriste [Thu, 20 Jun 2024 11:19:52 +0000 (13:19 +0200)]
Align the ft_parse style with that of f_arr
Lukas Jiriste [Thu, 20 Jun 2024 08:48:40 +0000 (10:48 +0200)]
Add comment about the parsing table structure
Parsing table shoud not contain any non-ASCII whitespace as
getting rid of multi-character whitespace is more challeging.
I mention it as I have encountered this problem and it was
somewhat difficult to find the cause.
Lukas Jiriste [Thu, 20 Jun 2024 08:47:16 +0000 (10:47 +0200)]
Fix logic bug
Lukas Jiriste [Thu, 20 Jun 2024 06:56:32 +0000 (08:56 +0200)]
Fix initialization and formatting of output
Lukas Jiriste [Sun, 16 Jun 2024 08:27:37 +0000 (10:27 +0200)]
Refactor to make functions comply with 42 Norm
Lukas Jiriste [Sun, 16 Jun 2024 06:18:32 +0000 (08:18 +0200)]
Add printing for parsing table, fix formatting
The ft_print_parsing_table is useful for debugging.
Lukas Jiriste [Sun, 16 Jun 2024 05:16:08 +0000 (07:16 +0200)]
Fix interpretting the end of row as 0
Lukas Jiriste [Sat, 15 Jun 2024 12:34:03 +0000 (14:34 +0200)]
Fix some bugs
These bugs include:
infinite loop
not freeing alocated memory
not initializing a struct before it may be returned
Lukas Jiriste [Sat, 15 Jun 2024 08:17:54 +0000 (10:17 +0200)]
Fix a logic bug
Lukas Jiriste [Sat, 15 Jun 2024 07:39:27 +0000 (09:39 +0200)]
Implement parse_header, minor fixes
Lukas Jiriste [Sat, 15 Jun 2024 07:37:30 +0000 (09:37 +0200)]
Implement ft_remove_space function
Lukas Jiriste [Fri, 14 Jun 2024 13:57:01 +0000 (15:57 +0200)]
Implement most of parsing table loading
Also change Makefile to include ft_parse.c in compilation.
Minor changes to ft_parse.h.
Lukas Jiriste [Fri, 14 Jun 2024 10:36:31 +0000 (12:36 +0200)]
Add description of the format of parsing table
Lukas Jiriste [Thu, 30 May 2024 04:49:03 +0000 (06:49 +0200)]
An draft of some parsing functions and structures
Lukas Jiriste [Mon, 20 May 2024 18:47:35 +0000 (20:47 +0200)]
Make ft_strlen return 0 when NULL is an argument
Lukas Jiriste [Mon, 6 May 2024 18:59:51 +0000 (20:59 +0200)]
Fix ft_mat_insert_col by switching comparison sign
The function has to increase capacity in the case the matrix has
insufficient capacity (not the other way around...).
Lukas Jiriste [Fri, 12 Apr 2024 15:27:05 +0000 (17:27 +0200)]
Fix ft_mat_fill by swapping rows and columns
Lukas Jiriste [Thu, 2 May 2024 09:01:39 +0000 (11:01 +0200)]
Add ft_strcat_alloc
This function behaves in similar way to ft_strncat_alloc. The difference
is that it concatenates the whole (null terminated) src string.
Lukas Jiriste [Thu, 25 Apr 2024 09:17:47 +0000 (11:17 +0200)]
Fix for "0" input to be recognized as valid int
Lukas Jiriste [Wed, 10 Apr 2024 11:25:14 +0000 (13:25 +0200)]
Merge branch 'isint' into no_crash
I've forgotten to pull the repo and made changes.
Then I was lazy to recreate them after pull and I thought
it would be easier to merge the changes.
Lukas Jiriste [Wed, 10 Apr 2024 11:20:46 +0000 (13:20 +0200)]
Add ft_isint function
Lukas Jiriste [Fri, 5 Apr 2024 08:07:59 +0000 (10:07 +0200)]
Add function for filling a matrix
Lukas Jiriste [Tue, 2 Apr 2024 09:29:44 +0000 (11:29 +0200)]
Add function for filling matrix with zeros
It has to be handed an empty (just initialized) matrix as I did not
think about non-empty matrices.
Lukas Jiriste [Fri, 8 Mar 2024 23:13:13 +0000 (00:13 +0100)]
Change string writting functions to accept const
This change is done because the writting functions do not (to my
knowledge) change the input string so it can as well be const.
Lukas Jiriste [Tue, 5 Mar 2024 08:24:30 +0000 (09:24 +0100)]
Add ft_dprintf for outputing to file descriptor
Lukas Jiriste [Thu, 29 Feb 2024 16:22:45 +0000 (17:22 +0100)]
Fix incorect memmove
Lukas Jiriste [Fri, 23 Feb 2024 08:08:45 +0000 (09:08 +0100)]
Add ft_min and ft_max functions for int and size_t
Lukas Jiriste [Fri, 16 Feb 2024 23:10:04 +0000 (00:10 +0100)]
Make get_next_line able to free all its memory
Passing negative fd to get_next_line now signalizes to it that it should
close (free) every buffer.
Lukas Jiriste [Tue, 30 Jan 2024 17:10:13 +0000 (18:10 +0100)]
Fix indentation of ft_sgn
Lukas Jiriste [Thu, 18 Jan 2024 09:56:04 +0000 (10:56 +0100)]
Add ft_sgn signum function
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, 13 Jan 2024 14:00:45 +0000 (15:00 +0100)]
Patch the issues of previous commit.
Patch ft_strcmp.c so that it actually compiles...
Add ft_strcmp to header file and the Makefile so that it is usable and
compiles to libft.a.
Lukas Jiriste [Sat, 13 Jan 2024 13:50:39 +0000 (14:50 +0100)]
Add ft_strcmp function.
Add ft_strcmp as it may be more ergonomic than ft_strncmp.
Add *.swp rule to .gitignore so that those won't bother me while vim is
opened.
Lukas Jiriste [Fri, 12 Jan 2024 20:27:38 +0000 (21:27 +0100)]
Add functions for finding element in vector
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 [Sun, 10 Dec 2023 14:01:59 +0000 (15:01 +0100)]
Improve ft_vec_erase and ft_vec_free
Add function for freeing element to ft_vec_erase and ft_vec_free for the
ability to handle advanced elements (elements which may point to heap).
Lukas Jiriste [Sat, 9 Dec 2023 17:26:53 +0000 (18:26 +0100)]
Add a ft_vec module for vector struct
Add vector struct and operations on it that are somewhat similar to C++
std::vector.
Lukas Jiriste [Sat, 9 Dec 2023 17:03:13 +0000 (18:03 +0100)]
Move all "public" header files to ./inc directory
This makes compiling easier, as only one directory has to be given
through the -I compiler option.
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 [Sat, 9 Dec 2023 14:15:32 +0000 (15:15 +0100)]
Set e-mail in the 42 header to the correct one
Change e-mail address in 42 header to ljiriste@student.42prague.com
instead of marvin@42.fr that was the default.
Lukas Jiriste [Sat, 9 Dec 2023 12:43:15 +0000 (13:43 +0100)]
Change file structure of this library
Separate source files (functions) to folders by topic.
Create separate header file each folder.
Adjust Makefile and libft.h accordingly.
Lukas Jiriste [Thu, 7 Dec 2023 09:26:34 +0000 (10:26 +0100)]
Patch ft_lst_sorted_insert to actually insert
Lukas Jiriste [Wed, 6 Dec 2023 09:45:45 +0000 (10:45 +0100)]
Add long and long long versions of ft_atoi.
Add the functions ft_atol and ft_atoll to the file ft_atoi.c.
Add prototypes of these functions to libft.h.
Lukas Jiriste [Sun, 3 Dec 2023 20:28:28 +0000 (21:28 +0100)]
Change permissions of files added in previous commit
Remove execute permission from ft_strncat_alloc.c and get_next_line.c as
source files are not executable.