librdesc
Loading...
Searching...
No Matches
bc.h
Go to the documentation of this file.
1
22#ifndef BC_H
23#define BC_H
26#include "../../include/grammar.h"
27#include "../../include/rule_macros.h"
28
29
30#define BC_PRODUCTION_COUNT 12
31
32#define BC_MAX_ALTERNATIVE_COUNT 3
33
34#define BC_MAX_ALTERNATIVE_SIZE 4
35
36enum bc_tk {
37 TK_NUM = 1 /* exblex.h reserve token identifier 0 as NOTOKEN */, TK_DOT,
38 TK_MINUS, TK_PLUS, TK_MULT, TK_DIV,
39 TK_LPAREN, TK_RPAREN, TK_ENDSYM,
40
41 TK_DUMMY_AMBIGUITY_TRIGGER,
42};
43
44enum bc_nt {
45 NT_UNSIGNED_NUM,
46
47 NT_EXPR, NT_EXPR_REST, NT_EXPR_OP,
48 NT_TERM, NT_TERM_REST, NT_TERM_OP,
49 NT_FACTOR, NT_OPTSIGN,
50 NT_ATOM,
51
52 NT_STMT,
53};
54
55const char bc_tks[] = {
56 '\0', /* token ID 0 is reserved for exblex */
57 'd', '.',
58 '-', '+', '*', '/',
59 '(', ')', ';',
60 '?',
61
62 '\0' /* null-terminator required in exblex */
63};
64
65const char *const bc_nt_names[] = {
66 "unsigned", "optsign", "sign",
67
68 "expr", "expr_rest", "expr_op",
69 "term", "term_rest", "term_op",
70 "factor",
71
72 "stmt",
73};
74
75static const struct rdesc_grammar_symbol
76bc[BC_PRODUCTION_COUNT]
77 [BC_MAX_ALTERNATIVE_COUNT + 1 /* +1 for end of production sentinel */]
78 [BC_MAX_ALTERNATIVE_SIZE + 1 /* +1 for end of alternative sentinel */] = {
79 /* <unsigned_num> ::= */ r(
80 TK(NUM)
81 alt TK(DOT), TK(NUM)
82 alt TK(NUM), TK(DOT), TK(NUM)
83 ),
84
85 /* <expr> ::= */
86 rrr(EXPR, (NT(TERM)), (NT(EXPR_OP), NT(TERM))),
87 /* <expr_op> ::= */ r(
88 TK(PLUS)
89 alt TK(MINUS)
90 ),
91
92 /* <term> ::= */
93 rrr(TERM, (NT(FACTOR)), (NT(TERM_OP), NT(FACTOR))),
94 /* <term_op> ::= */ r(
95 TK(MULT)
96 alt TK(DIV)
97 ),
98
99 /* <factor> ::= */ r(
100 NT(OPTSIGN), NT(ATOM)
101 ),
102 /* <optsign> ::= */ r(
103 TK(MINUS)
104 alt TK(PLUS)
106 ),
107
108 /* <atom> ::= */ r(
109 NT(UNSIGNED_NUM)
110 alt TK(LPAREN), NT(EXPR), TK(RPAREN)
111 alt TK(LPAREN), NT(EXPR), TK(RPAREN), TK(DUMMY_AMBIGUITY_TRIGGER)
112 ),
113
114
115 /* <stmt> ::= */ r(
116 NT(EXPR), TK(ENDSYM)
117 )
118};
119
120
122#endif
#define EPSILON
Epsilon production (empty/null production). Use to represent an empty alternative that matches nothin...
Definition rule_macros.h:65
#define rrr(head, base, suffix)
Defines right-recursive list rules. base and suffix parameters should wrapped with parenthesis (()).
Definition rule_macros.h:121
#define NT(nt)
Macro to create a nonterminal production symbol.
Definition rule_macros.h:58
#define TK(tk)
Macro to create a terminal (token) production symbol.
Definition rule_macros.h:56
#define r(...)
Macro to define a grammar rule. Adds end of alternative and end of production body sentinels to gramm...
Definition rule_macros.h:72
#define alt
Separates grammar alternatives (alternative separator).
Definition rule_macros.h:133
A terminal or nonterminal representing the body (right side) of a production rule.
Definition grammar.h:87