librdesc
Loading...
Searching...
No Matches
bc.h
Go to the documentation of this file.
1
23#ifndef BC_H
24#define BC_H
25
26#include "../../include/cfg.h"
27
28#define PREFIX_TK(tk) TK_ ## tk
29#define PREFIX_NT(nt) NT_ ## nt
30
31#include "../../include/bnf_dsl.h"
32
33
34#define BC_TK_COUNT 11
35
36#define BC_NT_COUNT 9
37#define BC_NT_VARIANT_COUNT 4
38#define BC_NT_BODY_LENGTH 5
39
40enum bc_tk {
41 TK_NOTOKEN,
42 TK_NUM, TK_DOT,
43 TK_MINUS, TK_PLUS, TK_MULT, TK_DIV,
44 TK_LPAREN, TK_RPAREN, TK_ENDSYM,
45
46 TK_DUMMY_AMBIGUITY_TRIGGER,
47};
48
49enum bc_nt {
50 NT_UNSIGNED, NT_OPTSIGN, NT_SIGNED,
51
52 NT_EXPR, NT_EXPR_REST,
53 NT_TERM, NT_TERM_REST,
54 NT_FACTOR,
55
56 NT_STMT,
57};
58
59const char bc_tks[BC_TK_COUNT] = {
60 '\0',
61 'd', '.',
62 '-', '+', '*', '/',
63 '(', ')', ';',
64 '?',
65};
66
67const char *const bc_nt_names[BC_NT_COUNT] = {
68 "unsigned", "optsign", "sign",
69
70 "expr", "expr_rest",
71 "term", "term_rest",
72 "factor",
73
74 "stmt",
75};
76
77static const struct rdesc_cfg_symbol
78bc[BC_NT_COUNT][BC_NT_VARIANT_COUNT][BC_NT_BODY_LENGTH] = {
79 /* <unsigned> ::= */ r(
80 TK(NUM),
81 alt TK(DOT), TK(NUM),
82 alt TK(NUM), TK(DOT), TK(NUM),
83 ),
84 /* <optsign> ::= */ r(
85 TK(MINUS),
86 alt TK(PLUS),
88 ),
89 /* <signed> ::= */ r(
90 NT(OPTSIGN), NT(UNSIGNED),
91 ),
92
93
94 /* <expr> ::= */ r(
95 NT(TERM), NT(EXPR_REST),
96 ),
97 /* <expr_rest> ::= */ r(
98 TK(PLUS), NT(EXPR),
99 alt TK(MINUS), NT(EXPR),
100 alt EPSILON,
101 ),
102
103 /* <term> ::= */ r(
104 NT(FACTOR), NT(TERM_REST),
105 ),
106 /* <term_rest> ::= */ r(
107 TK(MULT), NT(TERM),
108 alt TK(DIV), NT(TERM),
109 alt EPSILON,
110 ),
111
112 /* <factor> ::= */ r(
113 NT(SIGNED),
114 alt TK(LPAREN), NT(EXPR), TK(RPAREN),
115 alt TK(LPAREN), NT(EXPR), TK(RPAREN), TK(DUMMY_AMBIGUITY_TRIGGER),
116 ),
117
118
119 /* <stmt> ::= */ r(
120 NT(EXPR), TK(ENDSYM),
121 ),
122};
123
124
125#endif
#define EPSILON
Macro to create an epsilon production symbol.
Definition: bnf_dsl.h:65
#define NT(nt)
Macro to create a non-terminal production symbol.
Definition: bnf_dsl.h:63
#define TK(tk)
Macro to create a terminal (token) production symbol.
Definition: bnf_dsl.h:61
#define r(...)
Macro to define a grammar rule. Adds end-of-body and construct sentinels to grammar rules.
Definition: bnf_dsl.h:72
#define alt
Macro for syntactic sugar to separate non-terminal alternatives.
Definition: bnf_dsl.h:106
A terminal/non-terminal to describe body (right side) of a production rule.
Definition: cfg.h:45