52 |
The rules themselves are described by several arrays: amongst which |
The rules themselves are described by several arrays: amongst which |
53 |
RITEM, and RULES. |
RITEM, and RULES. |
54 |
|
|
55 |
RULES is an array of struct rule_s, which members are: |
RULES is an array of rules, whose members are: |
56 |
|
|
57 |
RULES[R].lhs -- the symbol of the left hand side of rule R. |
RULES[R].lhs -- the symbol of the left hand side of rule R. |
58 |
|
|
113 |
extern int ntokens; |
extern int ntokens; |
114 |
extern int nvars; |
extern int nvars; |
115 |
|
|
116 |
typedef int item_number_t; |
typedef int item_number; |
117 |
# define ITEM_NUMBER_MAX ((item_number_t) INT_MAX) |
extern item_number *ritem; |
|
# define ITEM_NUMBER_MIN ((item_number_t) INT_MIN) |
|
|
extern item_number_t *ritem; |
|
118 |
extern unsigned int nritems; |
extern unsigned int nritems; |
119 |
|
|
120 |
/* There is weird relationship between OT1H item_number_t and OTOH |
/* There is weird relationship between OT1H item_number and OTOH |
121 |
symbol_number_t and rule_number_t: we store the latter in |
symbol_number and rule_number: we store the latter in |
122 |
item_number_t. symbol_number_t are stored as are, while |
item_number. symbol_number values are stored as-is, while |
123 |
the negation of (rule_number_t + 1) are stored. |
the negation of (rule_number + 1) is stored. |
124 |
|
|
125 |
Therefore, an symbol_number_t must be a valid item_number_t, and we |
Therefore, a symbol_number must be a valid item_number, and we |
126 |
sometimes have to perform the converse transformation. */ |
sometimes have to perform the converse transformation. */ |
127 |
# define symbol_number_as_item_number(Tok) ((item_number_t) (Tok)) |
# define symbol_number_as_item_number(Tok) ((item_number) (Tok)) |
128 |
# define item_number_as_symbol_number(Ite) ((symbol_number_t) (Ite)) |
# define item_number_as_symbol_number(Ite) ((symbol_number) (Ite)) |
129 |
|
|
130 |
extern symbol_number_t start_symbol; |
extern symbol_number start_symbol; |
131 |
|
|
132 |
/* Rules numbers. */ |
/* Rule numbers. */ |
133 |
typedef short rule_number_t; |
typedef short rule_number; |
134 |
# define RULE_NUMBER_MAX ((rule_number_t) SHRT_MAX) |
extern rule_number nrules; |
|
extern rule_number_t nrules; |
|
135 |
# define int_of_rule_number(RNum) ((int) (RNum)) |
# define int_of_rule_number(RNum) ((int) (RNum)) |
136 |
# define rule_number_as_item_number(RNum) ((item_number_t) (- RNum - 1)) |
# define rule_number_as_item_number(RNum) ((item_number) (- RNum - 1)) |
137 |
# define item_number_as_rule_number(INum) ((rule_number_t) (- INum - 1)) |
# define item_number_as_rule_number(INum) ((rule_number) (- INum - 1)) |
138 |
|
|
139 |
|
|
140 |
/*--------. |
/*--------. |
141 |
| Rules. | |
| Rules. | |
142 |
`--------*/ |
`--------*/ |
143 |
|
|
144 |
typedef struct rule_s |
typedef struct |
145 |
{ |
{ |
146 |
/* The number of the rule in the source. It is usually the index in |
/* The number of the rule in the source. It is usually the index in |
147 |
RULES too, except if there are useless rules. */ |
RULES too, except if there are useless rules. */ |
148 |
rule_number_t user_number; |
rule_number user_number; |
149 |
|
|
150 |
/* The index in RULES. Usually the rule number in the source, |
/* The index in RULES. Usually the rule number in the source, |
151 |
except if some rules are useless. */ |
except if some rules are useless. */ |
152 |
rule_number_t number; |
rule_number number; |
153 |
|
|
154 |
symbol_t *lhs; |
symbol *lhs; |
155 |
item_number_t *rhs; |
item_number *rhs; |
156 |
|
|
157 |
/* This symbol provides both the associativity, and the precedence. */ |
/* This symbol provides both the associativity, and the precedence. */ |
158 |
symbol_t *prec; |
symbol *prec; |
159 |
|
|
160 |
short dprec; |
short dprec; |
161 |
short merger; |
short merger; |
162 |
|
|
163 |
/* This symbol was attached to the rule via %prec. */ |
/* This symbol was attached to the rule via %prec. */ |
164 |
symbol_t *precsym; |
symbol *precsym; |
165 |
|
|
166 |
location_t location; |
location location; |
167 |
bool useful; |
bool useful; |
168 |
|
|
169 |
const char *action; |
const char *action; |
170 |
location_t action_location; |
location action_location; |
171 |
} rule_t; |
} rule; |
172 |
|
|
173 |
extern struct rule_s *rules; |
extern rule *rules; |
174 |
|
|
175 |
/* A function that selects a rule. */ |
/* A function that selects a rule. */ |
176 |
typedef bool (*rule_filter_t) (rule_t *r); |
typedef bool (*rule_filter) (rule *); |
177 |
|
|
178 |
/* Return true IFF the rule has a `number' smaller than NRULES. */ |
/* Return true IFF the rule has a `number' smaller than NRULES. */ |
179 |
bool rule_useful_p (rule_t *r); |
bool rule_useful_p (rule *r); |
180 |
|
|
181 |
/* Return true IFF the rule has a `number' higher than NRULES. */ |
/* Return true IFF the rule has a `number' higher than NRULES. */ |
182 |
bool rule_useless_p (rule_t *r); |
bool rule_useless_p (rule *r); |
183 |
|
|
184 |
/* Return true IFF the rule is not flagged as useful *and* is useful. |
/* Return true IFF the rule is not flagged as useful *and* is useful. |
185 |
In other words, it was discarded because of conflicts. */ |
In other words, it was discarded because of conflicts. */ |
186 |
bool rule_never_reduced_p (rule_t *r); |
bool rule_never_reduced_p (rule *r); |
187 |
|
|
188 |
/* Print this RULE's number and lhs on OUT. If a PREVIOUS_LHS was |
/* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was |
189 |
already displayed (by a previous call for another rule), avoid |
already displayed (by a previous call for another rule), avoid |
190 |
useless repetitions. */ |
useless repetitions. */ |
191 |
void rule_lhs_print (rule_t *rule, symbol_t *previous_lhs, FILE *out); |
void rule_lhs_print (rule *r, symbol *previous_lhs, FILE *out); |
192 |
|
|
193 |
/* Return the length of the RHS. */ |
/* Return the length of the RHS. */ |
194 |
int rule_rhs_length (rule_t *rule); |
int rule_rhs_length (rule *r); |
195 |
|
|
196 |
/* Print this RULE's RHS on OUT. */ |
/* Print this rule's RHS on OUT. */ |
197 |
void rule_rhs_print (rule_t *rule, FILE *out); |
void rule_rhs_print (rule *r, FILE *out); |
198 |
|
|
199 |
/* Print this RULE on OUT. */ |
/* Print this rule on OUT. */ |
200 |
void rule_print (rule_t *rule, FILE *out); |
void rule_print (rule *r, FILE *out); |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
/* Table of the symbols, indexed by the symbol number. */ |
/* Table of the symbols, indexed by the symbol number. */ |
206 |
extern symbol_t **symbols; |
extern symbol **symbols; |
207 |
|
|
208 |
/* TOKEN_TRANSLATION -- a table indexed by a token number as returned |
/* TOKEN_TRANSLATION -- a table indexed by a token number as returned |
209 |
by the user's yylex routine, it yields the internal token number |
by the user's yylex routine, it yields the internal token number |
210 |
used by the parser and throughout bison. */ |
used by the parser and throughout bison. */ |
211 |
extern symbol_number_t *token_translations; |
extern symbol_number *token_translations; |
212 |
extern int max_user_token_number; |
extern int max_user_token_number; |
213 |
|
|
214 |
|
|
233 |
/* Print the grammar's rules numbers from BEGIN (inclusive) to END |
/* Print the grammar's rules numbers from BEGIN (inclusive) to END |
234 |
(exclusive) on OUT under TITLE. */ |
(exclusive) on OUT under TITLE. */ |
235 |
void grammar_rules_partial_print (FILE *out, const char *title, |
void grammar_rules_partial_print (FILE *out, const char *title, |
236 |
rule_filter_t filter); |
rule_filter filter); |
237 |
|
|
238 |
/* Print the grammar's rules on OUT. */ |
/* Print the grammar's rules on OUT. */ |
239 |
void grammar_rules_print (FILE *out); |
void grammar_rules_print (FILE *out); |