librdesc
Loading...
Searching...
No Matches
pm_grammar.h
Go to the documentation of this file.
1
5#ifndef PM_GRAMMAR_H
6#define PM_GRAMMAR_H
7
8#include <rdesc/rdesc.h>
9
10#include <stdint.h>
11#include <stdio.h>
12
14#include <rdesc/grammar.h>
15
16/* let's use `pm` as abbreviation for Pipe Math. */
18#define PM_PRODUCTION_COUNT 9
20#define PM_MAX_ALTERNATIVE_COUNT 2
22#define PM_MAX_ALTERNATIVE_SIZE 4
23
33
35
36enum pm_tk {
37 TK_NUM = 1, // ⟨Num⟩
38 TK_IDENT, // ⟨Identifier⟩
39 TK_LPAREN /* ( */, TK_RPAREN /* ) */,
40 TK_PIPE /* | */, TK_CARET /* ^ */,
41 TK_COMMA /* , */, TK_SEMI /* ; */,
42};
44
46
47enum pm_nt {
48 /* ⟨Stmt⟩, ⟨Expr⟩ */
49 NT_STMT, NT_EXPR,
50
51 /* ⟨Num⟩ (^ ⟨Num⟩)* */
52 NT_EXPONENTIATION_EXPR, NT_EXPONENTIATION_EXPR_REST,
53 /* ⟨FunctionCall⟩ (| ⟨FunctionCall⟩)* */
54 NT_PIPE_EXPR, NT_PIPE_EXPR_REST,
55
56 /* We will define ⟨PipeExpr⟩ as right-associative for now. Later, we
57 * will use flip function to convert pipe operator left-associative. */
58
59 /* ⟨Expr⟩ (, ⟨Expr⟩)* */
60 NT_FUNCTION_ARG_LS, NT_FUNCTION_ARG_LS_REST,
61
62 NT_FUNCTION_CALL,
63};
65
67extern const char *tk_names[];
68
70extern const char *nt_names[];
71
73extern const char exblex_tks[];
74
76void tk_destroyer(uint16_t id, void *);
77
79void node_printer(FILE *out, const struct rdesc_node *);
80
81
82#endif
const char * nt_names[]
Definition pm_grammar.c:56
pm_nt
[Token definition]
Definition pm_grammar.h:47
#define PM_MAX_ALTERNATIVE_COUNT
Definition pm_grammar.h:20
const char * tk_names[]
[Nonterminal definition]
Definition pm_grammar.c:48
void node_printer(FILE *out, const struct rdesc_node *)
[Token destroyer]
Definition pm_grammar.c:98
struct rdesc_grammar_symbol pm_grammar[PM_PRODUCTION_COUNT][PM_MAX_ALTERNATIVE_COUNT+1][PM_MAX_ALTERNATIVE_SIZE+1]
Pipe-Math grammar definition.
Definition pm_grammar.c:13
void tk_destroyer(uint16_t id, void *)
[exblex tokens]
Definition pm_grammar.c:79
const char exblex_tks[]
[Nonterminal and terminal names]
Definition pm_grammar.c:69
#define PM_PRODUCTION_COUNT
[Grammar declaration]
Definition pm_grammar.h:18
#define PM_MAX_ALTERNATIVE_SIZE
Definition pm_grammar.h:22
pm_tk
[Grammar declaration]
Definition pm_grammar.h:36
A terminal or nonterminal representing the body (right side) of a production rule.
Definition grammar.h:89