This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar_parsing_table.c
65 lines (59 loc) · 2.15 KB
/
grammar_parsing_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* grammar_parsing_table.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/18 18:32:37 by mgautier #+# #+# */
/* Updated: 2018/01/18 18:32:37 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "grammar_defs.h"
#include "sym_interface.h"
#include <stddef.h>
static t_bool init_parse_row(void *sym, va_list args)
{
return (init_sym_parse_table(sym, va_arg(args, size_t)));
}
static t_bool fill_parse_row(void *sym, va_list args)
{
return (fill_sym_parse_table(sym, va_arg(args, char const**)));
}
t_bool compute_parsing_table(
t_grammar *gram, char const **tokens_names)
{
return (f_fifoiterr_va(gram->sym_list,
init_parse_row, ft_string_array_count(tokens_names) + 1)
&& f_fifoiterr_va(gram->sym_list,
fill_parse_row, tokens_names));
}
void const **create_tokens_table(
char const **tokens_name,
t_grammar const *gram)
{
size_t index;
void const **tokens_table;
index = ft_string_array_count(tokens_name) + 1;
tokens_table = malloc(sizeof(*tokens_table) * index);
if (tokens_table != NULL)
{
index = 0;
while (tokens_name[index] != NULL)
{
tokens_table[index] = find_sym_by_name(gram, tokens_name[index]);
if (tokens_table[index] == NULL)
{
free(tokens_table);
tokens_table = NULL;
return (tokens_table);
}
else
set_token_id((void*)tokens_table[index], index);
index++;
}
tokens_table[index] = find_sym_by_name(gram, "END_OF_INPUT");
set_token_id((void*)tokens_table[index], index);
}
return (tokens_table);
}