diff options
author | aditya <bluenerd@protonmail.com> | 2023-08-10 12:32:35 +0530 |
---|---|---|
committer | aditya <bluenerd@protonmail.com> | 2023-08-10 12:32:35 +0530 |
commit | a9ff78b3f48dc9f81943c41531c4959ce7e2ae9d (patch) | |
tree | 49ee8c3c9148038f04112802265d928ef1aba428 /examples/grammar-parser.h | |
parent | 2516af4cd61f509c995b4f78fdf123cba33f3509 (diff) | |
parent | 916a9acdd0a411426690400ebe2bb7ce840a6bba (diff) |
resolve merge conflict
Diffstat (limited to 'examples/grammar-parser.h')
-rw-r--r-- | examples/grammar-parser.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/grammar-parser.h b/examples/grammar-parser.h new file mode 100644 index 0000000..9037d72 --- /dev/null +++ b/examples/grammar-parser.h @@ -0,0 +1,29 @@ +// Implements a parser for an extended Backus-Naur form (BNF), producing the +// binary context-free grammar format specified by llama.h. Supports character +// ranges, grouping, and repetition operators. As an example, a grammar for +// arithmetic might look like: +// +// root ::= expr +// expr ::= term ([-+*/] term)* +// term ::= num | "(" space expr ")" space +// num ::= [0-9]+ space +// space ::= [ \t\n]* + +#pragma once +#include "llama.h" +#include <vector> +#include <map> +#include <cstdint> +#include <string> + +namespace grammar_parser { + struct parse_state { + std::map<std::string, uint32_t> symbol_ids; + std::vector<std::vector<llama_grammar_element>> rules; + + std::vector<const llama_grammar_element *> c_rules(); + }; + + parse_state parse(const char * src); + void print_grammar(FILE * file, const parse_state & state); +} |