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