aboutsummaryrefslogtreecommitdiff
path: root/src/bnf-parser.h
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 08:19:44 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 08:23:19 +0000
commit5be0e39d0ce97849d7722bd1ac98563c7014faf3 (patch)
tree9dba821664337a6662a6da88dfe86291d269c36b /src/bnf-parser.h
downloadlab-05-master.tar.gz
publishHEADmaster
Diffstat (limited to 'src/bnf-parser.h')
-rw-r--r--src/bnf-parser.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bnf-parser.h b/src/bnf-parser.h
new file mode 100644
index 0000000..8887a66
--- /dev/null
+++ b/src/bnf-parser.h
@@ -0,0 +1,52 @@
1#ifndef INCLUDED_BNF_PARSER_H
2#define INCLUDED_BNF_PARSER_H
3
4#include <stdint.h>
5#include <stdbool.h>
6#include "bnf-lexer.h"
7
8struct bnf_sequence {
9 union { struct bnf_lexeme *items, *terms; };
10 union { uint32_t count, term_count; };
11 uint32_t probability;
12 uint32_t capacity;
13};
14
15struct bnf_rule {
16 struct bnf_lexeme name;
17 struct {
18 union { struct bnf_sequence *items, *sequences; };
19 union { uint32_t count, sequence_count; };
20 uint32_t capacity;
21 } is_replaced_by;
22};
23
24struct bnf_syntax {
25 union { struct bnf_rule *items, *rules; };
26 union { uint32_t count, rule_count; };
27 uint32_t capacity;
28};
29
30// struct term_table {
31// union { struct bnf_lexeme *items, *terms; };
32// union { uint32_t count, term_count; };
33// uint32_t capacity;
34// };
35
36struct bnf_parser {
37 struct bnf_lexer lexer;
38};
39
40bool is_bnf_lexeme_valid (struct bnf_lexeme);
41bool is_bnf_sequence_valid (struct bnf_sequence);
42bool is_bnf_rule_valid (struct bnf_rule);
43
44bool bnf_check_syntax (struct bnf_lexer *, struct bnf_syntax);
45bool bnf_parse_lexeme (struct bnf_lexer *, enum bnf_lexeme_kind);
46struct bnf_lexeme bnf_parse_nonterminal (struct bnf_lexer *);
47struct bnf_lexeme bnf_parse_terminal (struct bnf_lexer *);
48struct bnf_sequence bnf_parse_sequence (struct bnf_lexer *);
49struct bnf_rule bnf_parse_rule (struct bnf_lexer *);
50struct bnf_syntax bnf_parse_syntax (struct bnf_lexer *);
51
52#endif // INCLUDED_BNF_PARSER_H