kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

calc.h (1008B)


      1 /* calc.h — HAND-WRITTEN stand-in for what `gramgen calc.ebnf` would emit.
      2  *
      3  * Grammar (LL(1), EBNF):
      4  *   expr      = term { expr_tail } ;
      5  *   expr_tail = add_op term ;
      6  *   add_op    = "+" | "-" ;
      7  *   term      = factor { term_tail } ;
      8  *   term_tail = mul_op factor ;
      9  *   mul_op    = "*" | "/" ;
     10  *   factor    = [ "-" ] primary ;          (* optional unary minus *)
     11  *   primary   = NUMBER | "(" expr ")" ;
     12  */
     13 #ifndef CALC_H
     14 #define CALC_H
     15 
     16 #include <kit/gram_parse.h>
     17 
     18 /* terminals — the embedder's lexer produces these kinds */
     19 enum {
     20     TOK_EOF = 0, TOK_PLUS, TOK_MINUS, TOK_STAR, TOK_SLASH,
     21     TOK_NUMBER, TOK_LPAREN, TOK_RPAREN, TOK__COUNT
     22 };
     23 
     24 /* named rules only (synthetic rep/opt never surface here) */
     25 enum {
     26     R_expr = 0, R_expr_tail, R_add_op, R_term,
     27     R_term_tail, R_mul_op, R_factor, R_primary, R__COUNT
     28 };
     29 
     30 extern const KitGramGrammar calc_grammar;
     31 void calc_parser_init(KitGramParser *mem, const KitGramConfig *cfg);  /* wraps kit_gram_parser_init */
     32 
     33 #endif /* CALC_H */