// Implements a parser for an extended Backus-Naur form (BNF), producing the // binary context-free grammar format specified by whisper.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 "whisper.h" #include #include #include #include namespace grammar_parser { struct parse_state { std::map symbol_ids; std::vector> rules; std::vector c_rules() const; }; parse_state parse(const char * src); void print_grammar(FILE * file, const parse_state & state); }