/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:51:36 by ljiriste #+# #+# */
-/* Updated: 2024/06/14 15:54:42 by ljiriste ### ########.fr */
+/* Updated: 2024/06/15 09:24:56 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
while (!ft_isspace(line[i]))
++i;
token.type = ft_strndup(line + j, i - j);
+ rule.result = token;
while (ft_isspace(line[i]))
++i;
if (!(line[i++] == '-' && line[i++] == '>'))
goto_rule = ft_atoi(condensed_line + i);
ft_vec_append(&state.gotos, &goto_rule);
}
+ free(condensed_line);
ft_vec_append(states, &state);
return (0);
}
+static t_vec parse_header(const char *header)
+{
+ t_vec tokens;
+ t_token token;
+ char *condensed_line;
+ size_t i;
+ size_t j;
+
+ condensed_line = ft_remove_space(header);
+ ft_vec_init(&tokens, sizeof(t_token));
+ token.str = NULL;
+ i = 0;
+ while (condensed_line[i] && condensed_line[i++] != ';');
+ while (condensed_line[i])
+ {
+ j = i;
+ while (condensed_line[i] && condensed_line[i] != ';')
+ ++i;
+ token.type = ft_strndup(condensed_line + j, i - j);
+ if (!token.type || ft_vec_append(&tokens, &token) != success)
+ {
+ free(token.type);
+ ft_vec_free(&tokens, free_token);
+ return (tokens);
+ }
+ }
+ return (tokens);
+}
+
t_parsing_table ft_load_parsing_table(const char *filename,
const char *rules_filename)
{
char *line;
t_parsing_table table;
+ ft_vec_init(&table.rules, sizeof(t_grammar_rule));
+ ft_vec_init(&table.states, sizeof(t_parser_state));
+ ft_vec_init(&table.tokens, sizeof(t_token));
if (load_rules(&table.rules, rules_filename))
return (table);
fd = open(filename, O_RDONLY);
/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/15 12:58:15 by ljiriste #+# #+# */
-/* Updated: 2023/12/11 10:17:16 by ljiriste ### ########.fr */
+/* Updated: 2024/06/15 09:05:22 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
# include "ft_io.h"
# include "ft_lst.h"
# include "ft_arr.h"
+# include "ft_parse.h"
#endif