Lukas Jiriste [Thu, 28 Nov 2024 11:11:19 +0000 (12:11 +0100)]
Break line in Makefile to fit in 80 chars
Lukas Jiriste [Thu, 28 Nov 2024 11:09:14 +0000 (12:09 +0100)]
Move g_empty_token and g_eof_token definition
This is done so that the actions.c file does not need its own
definition.
Lukas Jiriste [Thu, 28 Nov 2024 10:58:17 +0000 (11:58 +0100)]
Merge parsing_table_constructor into no_crash
Lukas Jiriste [Thu, 28 Nov 2024 10:32:54 +0000 (11:32 +0100)]
Align slashes in Makefile
I really should use spaces instead of tabs for alignment...
Lukas Jiriste [Thu, 28 Nov 2024 10:23:25 +0000 (11:23 +0100)]
Make this branch fully Norm compliant
I needed to split the main file a little yet. The grouping may not make
much sense, I did not want to spend any brain power on this anymore.
Lukas Jiriste [Thu, 28 Nov 2024 10:03:09 +0000 (11:03 +0100)]
Add -fPIE flag to Makefile
The -fPIE flag has something to do with position independent code. I
think I've encountered this problem before when using ft_printf, because
its ability to print pointer values (addresses).
Lukáš Jiřiště [Wed, 27 Nov 2024 10:33:23 +0000 (11:33 +0100)]
Refactor ft_parsing_table_generate.c
Lukáš Jiřiště [Tue, 26 Nov 2024 14:43:52 +0000 (15:43 +0100)]
Split functions too large to comply with the Norm
Lukáš Jiřiště [Tue, 26 Nov 2024 12:03:43 +0000 (13:03 +0100)]
Break long lines, fix indentation and g_var naming
Bring the code closer to compliance with the Norm.
Lukas Jiriste [Fri, 2 Aug 2024 13:09:59 +0000 (15:09 +0200)]
Improve Makefile debug functionality
Makefile now creates .debug file when "make debug" is executed.
This make Makefile able to remember the debug mode for futher builds
and rebuilds. The debug mode can be disabled by removing the .debug file
or by executing "make nodebug" which will also build the project.
Lukas Jiriste [Fri, 2 Aug 2024 12:14:20 +0000 (14:14 +0200)]
Extend the input possibilities for parsing table
This is done so that a parsing table may be included inside a source
file as a string.
Addition new (long) filename to Makefile lead to change of alignment
depth.
Lukas Jiriste [Fri, 2 Aug 2024 12:04:56 +0000 (14:04 +0200)]
Harden ft_split, provide ft_free_split
Lukas Jiriste [Thu, 1 Aug 2024 10:03:40 +0000 (12:03 +0200)]
Fix invalid read in ft_split
This read happens when the last word ends with the terminating '\0'.
After advancing the index to the '\0' it is then increased once more to
regions not accessible. This is fixed by simple skipping the ++i after a
word has been processed.
Lukas Jiriste [Sun, 21 Jul 2024 19:44:35 +0000 (21:44 +0200)]
Add ft_swap_int
Lukas Jiriste [Sun, 21 Jul 2024 18:26:51 +0000 (20:26 +0200)]
Merge some t_vec functions into no_crash
I dont want to merge parsing generator so that I don't have to make it
comply with the Norm yet.
Lukas Jiriste [Fri, 19 Jul 2024 11:57:12 +0000 (13:57 +0200)]
Add a function to save a table as a file
This file is then readable by ft_parsing_table_load.
Some lazy checks are written to check that something was written to the
file, but if only partial write happens, those will not notice.
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 [Fri, 5 Jul 2024 08:33:01 +0000 (10:33 +0200)]
Fix infinite loop
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 14:38:34 +0000 (16:38 +0200)]
Fix wrong malloc and infinite loop in ft_vec
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 [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 [Sun, 21 Jul 2024 16:57:01 +0000 (18:57 +0200)]
Harden the ft_strchr and ft_strrchr functions
This makes them return NULL when the haystack is NULL.
Lukas Jiriste [Sun, 21 Jul 2024 16:54:44 +0000 (18:54 +0200)]
Adapt the transplanted ft_split to libft
Lukas Jiriste [Sun, 21 Jul 2024 16:50:28 +0000 (18:50 +0200)]
Transplant a better split function to Libft
This function was created during the 42 Piscine.
Lukas Jiriste [Sun, 21 Jul 2024 06:42:32 +0000 (08:42 +0200)]
Remove structure comments that offend the Norm
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