diff options
| author | 2026-11-08 08:19:44 +0000 | |
|---|---|---|
| committer | 2026-11-08 08:23:19 +0000 | |
| commit | 5be0e39d0ce97849d7722bd1ac98563c7014faf3 (patch) | |
| tree | 9dba821664337a6662a6da88dfe86291d269c36b /src/bnf-lexeme.h | |
| download | lab-05-5be0e39d0ce97849d7722bd1ac98563c7014faf3.tar.gz | |
Diffstat (limited to 'src/bnf-lexeme.h')
| -rw-r--r-- | src/bnf-lexeme.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bnf-lexeme.h b/src/bnf-lexeme.h new file mode 100644 index 0000000..8b01708 --- /dev/null +++ b/src/bnf-lexeme.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #ifndef INCLUDED_BNF_LEXEME_H | ||
| 2 | #define INCLUDED_BNF_LEXEME_H | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include "utils.h" | ||
| 7 | #include "string-view.h" | ||
| 8 | |||
| 9 | #define BNF_LEXEME_KINDS() \ | ||
| 10 | X (TERMINAL, "\"[^\"]*\"|'[^']*'") \ | ||
| 11 | X (NONTERMINAL, "<[^>]*>" ) \ | ||
| 12 | X (PROBABILITY, "[0-9]+" ) \ | ||
| 13 | X (SYMBOL_ALTERNATIVE, "\\|" ) \ | ||
| 14 | X (SYMBOL_IS_REPLACED_BY, "::=" ) \ | ||
| 15 | X (COMMENT, "#[^\n]*" ) | ||
| 16 | |||
| 17 | #define X(SYM, ...) BNF_LEXEME_KIND_##SYM, | ||
| 18 | enum bnf_lexeme_kind { | ||
| 19 | BNF_LEXEME_KINDS () | ||
| 20 | BNF_LEXEME_KIND_END_OF_LINE, | ||
| 21 | BNF_LEXEME_KIND_END_OF_FILE, | ||
| 22 | BNF_LEXEME_KIND_INVALID, | ||
| 23 | BNF_LEXEME_KIND_COUNT, | ||
| 24 | }; | ||
| 25 | #undef X | ||
| 26 | |||
| 27 | #define BNF_LEXEME_REGEX_COUNT (BNF_LEXEME_KIND_COUNT - 3) | ||
| 28 | |||
| 29 | struct bnf_lexeme { | ||
| 30 | struct string_view sv; | ||
| 31 | enum bnf_lexeme_kind kind; | ||
| 32 | }; | ||
| 33 | |||
| 34 | extern const char *bnf_lexeme_kind_names[BNF_LEXEME_KIND_COUNT]; | ||
| 35 | |||
| 36 | #endif // INCLUDED_BNF_LEXEME_H | ||
