Fix initialization and formatting of output
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 20 Jun 2024 06:56:32 +0000 (08:56 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 20 Jun 2024 07:32:40 +0000 (09:32 +0200)
ft_parse/ft_parse.c
ft_parse/ft_print_parsing_table.c

index 968e2ce70e9a0a5df34403bf5c3af11b9b679fc3..a1eb5758631599daa35c56d117c2ab56f2ce43aa 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/20 20:51:36 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/06/16 10:26:21 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/06/16 18:27:16 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -211,6 +211,7 @@ static int  add_line(t_vec *states, const char *line, size_t lookahead_size)
 
        condensed_line = ft_remove_space(line);
        state.lookahead = parse_lookahead(condensed_line, lookahead_size);
+       i = 0;
        while (lookahead_size > 0)
        {
                while (condensed_line[i] && condensed_line[i] != ';')
@@ -250,13 +251,13 @@ static t_vec      parse_header(const char *header)
        i = 0;
        while (condensed_line[i] && condensed_line[i] != ';')
                ++i;
-       if (condensed_line[i])
-               ++i;
        while (condensed_line[i])
        {
+               ++i;
                token.type = get_token_type(condensed_line + i);
+               while (condensed_line[i] && condensed_line[i] != ';')
+                       ++i;
                ft_vec_append(&tokens, &token);
-               ++i;
        }
        free(condensed_line);
        return (tokens);
index e864b7ebdab56b7c6ed7d42183f3e5aed4dd6f49..a13915e6f4520f19eb7f5c3ea2dabae90cb2add6 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/16 07:19:50 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/06/16 08:17:46 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/06/16 18:20:37 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -47,7 +47,7 @@ static void   print_state(t_parser_state *state,
        t_vec   *vec;
        ssize_t *gt;
 
-       ft_printf("%-*u ", column_width, state_num);
+       ft_printf("%-5u ", state_num);
        vec = &state->lookahead;
        i = 0;
        while (i < vec->size)
@@ -77,9 +77,9 @@ void  ft_print_parsing_table(t_parsing_table *table,
        while (i < table->rules.size)
                print_rule(ft_vec_access(&table->rules, i++), column_width);
        i = 0;
-       ft_printf("\n%-*s ", column_width, "State");
+       ft_printf("\n%-5s ", "State");
        while (i < table->tokens.size)
-               ft_printf("%-*s ", column_width,
+               ft_printf("%-*s ", column_width - 1,
                        ((t_token *)ft_vec_access(&table->tokens, i++))->type);
        ft_printf("\n");
        i = 0;