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