librdesc
Loading...
Searching...
No Matches
grammar.h
1#ifndef PM_GRAMMAR_H
2#define PM_GRAMMAR_H
3
4#include <rdesc/rdesc.h>
5
6#include <stdint.h>
7#include <stdio.h>
8
10#include <rdesc/grammar.h>
11
12/* let's use `pm` as abbreviation for Pipe-Math. */
14#define PM_PRODUCTION_COUNT 9
16#define PM_MAX_ALTERNATIVE_COUNT 2
18#define PM_MAX_ALTERNATIVE_SIZE 4
19
20extern struct rdesc_grammar_symbol pm_grammar[PM_PRODUCTION_COUNT]
21 [PM_MAX_ALTERNATIVE_COUNT + 1]
22 [PM_MAX_ALTERNATIVE_SIZE + 1];
24
27enum pm_tk {
28 TK_NUM = 1, // ⟨Num⟩
29 TK_IDENT, // ⟨Identifier⟩
30 TK_LPAREN /* ( */, TK_RPAREN /* ) */,
31 TK_PIPE /* | */, TK_CARET /* ^ */,
32 TK_COMMA /* , */, TK_SEMI /* ; */,
33};
35
38enum pm_nt {
39 /* ⟨Stmt⟩, ⟨Expr⟩ */
40 NT_STMT, NT_EXPR,
41
42 /* ⟨Num⟩ (^ ⟨Num⟩)* */
43 NT_EXPONENTIATION_EXPR, NT_EXPONENTIATION_EXPR_REST,
44 /* ⟨FunctionCall⟩ (| ⟨FunctionCall⟩)* */
45 NT_PIPE_EXPR, NT_PIPE_EXPR_REST,
46
47 /* We will define ⟨PipeExpr⟩ as right-associative for now. Later, we
48 * will use flip function to convert pipe operator left-associative. */
49
50 /* ⟨Expr⟩ (, ⟨Expr⟩)* */
51 NT_FUNCTION_ARG_LS, NT_FUNCTION_ARG_LS_REST,
52
53 NT_FUNCTION_CALL,
54};
56
58extern const char *tk_names[];
59
61extern const char *nt_names[];
62
64extern const char exblex_tks[];
65
67void tk_destroyer(uint16_t id, void *);
68
70void node_printer(FILE *out, const struct rdesc_node *);
71
72
73#endif
A terminal or nonterminal representing the body (right side) of a production rule.
Definition grammar.h:89