From 6ecea40c849effd171c1d27c961f5c1ee100481f Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 09:02:38 +0300 Subject: publish --- src/bnf-parser.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bnf-parser.h (limited to 'src/bnf-parser.h') 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 @@ +#ifndef INCLUDED_BNF_PARSER_H +#define INCLUDED_BNF_PARSER_H + +#include +#include +#include "bnf-lexer.h" + +struct bnf_sequence { + union { struct bnf_lexeme *items, *terms; }; + union { uint32_t count, term_count; }; + uint32_t capacity; +}; + +struct bnf_rule { + struct bnf_lexeme name; + struct { + union { struct bnf_sequence *items, *sequences; }; + union { uint32_t count, sequence_count; }; + uint32_t capacity; + } is_replaced_by; +}; + +struct bnf_syntax { + union { struct bnf_rule *items, *rules; }; + union { uint32_t count, rule_count; }; + uint32_t capacity; +}; + +// struct term_table { +// union { struct bnf_lexeme *items, *terms; }; +// union { uint32_t count, term_count; }; +// uint32_t capacity; +// }; + +struct bnf_parser { + struct bnf_lexer lexer; +}; + +bool is_bnf_lexeme_valid (struct bnf_lexeme); +bool is_bnf_sequence_valid (struct bnf_sequence); +bool is_bnf_rule_valid (struct bnf_rule); + +bool bnf_check_syntax (struct bnf_lexer *, struct bnf_syntax); +bool bnf_parse_lexeme (struct bnf_lexer *, enum bnf_lexeme_kind); +struct bnf_lexeme bnf_parse_nonterminal (struct bnf_lexer *); +struct bnf_lexeme bnf_parse_terminal (struct bnf_lexer *); +struct bnf_sequence bnf_parse_sequence (struct bnf_lexer *); +struct bnf_rule bnf_parse_rule (struct bnf_lexer *); +struct bnf_syntax bnf_parse_syntax (struct bnf_lexer *); + +#endif // INCLUDED_BNF_PARSER_H -- cgit v1.3.1