3
conf-parse.y - Part of libsensors, a Linux library for reading sensor data.
4
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
#define YYERROR_VERBOSE
35
static void sensors_yyerror(const char *err);
36
static sensors_expr *malloc_expr(void);
38
static sensors_chip *current_chip = NULL;
40
#define bus_add_el(el) sensors_add_array_el(el,\
41
&sensors_config_busses,\
42
&sensors_config_busses_count,\
43
&sensors_config_busses_max,\
45
#define label_add_el(el) sensors_add_array_el(el,\
46
¤t_chip->labels,\
47
¤t_chip->labels_count,\
48
¤t_chip->labels_max,\
49
sizeof(sensors_label));
50
#define set_add_el(el) sensors_add_array_el(el,\
52
¤t_chip->sets_count,\
53
¤t_chip->sets_max,\
55
#define compute_add_el(el) sensors_add_array_el(el,\
56
¤t_chip->computes,\
57
¤t_chip->computes_count,\
58
¤t_chip->computes_max,\
59
sizeof(sensors_compute));
60
#define ignore_add_el(el) sensors_add_array_el(el,\
61
¤t_chip->ignores,\
62
¤t_chip->ignores_count,\
63
¤t_chip->ignores_max,\
64
sizeof(sensors_ignore));
65
#define chip_add_el(el) sensors_add_array_el(el,\
66
&sensors_config_chips,\
67
&sensors_config_chips_count,\
68
&sensors_config_chips_max,\
69
sizeof(sensors_chip));
71
#define fits_add_el(el,list) sensors_add_array_el(el,\
75
sizeof(sensors_chip_name));
83
sensors_chip_name_list chips;
86
sensors_chip_name chip;
87
sensors_config_line line;
90
%left <nothing> '-' '+'
91
%left <nothing> '*' '/'
93
%right <nothing> '^' '`'
101
%token <line> COMPUTE
105
%token <nothing> ERROR
107
%type <chips> chip_name_list
108
%type <expr> expression
110
%type <name> adapter_name
111
%type <name> function_name
113
%type <chip> chip_name
123
line: bus_statement EOL
124
| label_statement EOL
127
| compute_statement EOL
128
| ignore_statement EOL
132
bus_statement: BUS bus_id adapter_name
133
{ sensors_bus new_el;
141
label_statement: LABEL function_name string
142
{ sensors_label new_el;
144
sensors_yyerror("Label statement before first chip statement");
152
label_add_el(&new_el);
156
set_statement: SET function_name expression
157
{ sensors_set new_el;
159
sensors_yyerror("Set statement before first chip statement");
161
sensors_free_expr($3);
171
compute_statement: COMPUTE function_name expression ',' expression
172
{ sensors_compute new_el;
174
sensors_yyerror("Compute statement before first chip statement");
176
sensors_free_expr($3);
177
sensors_free_expr($5);
182
new_el.from_proc = $3;
184
compute_add_el(&new_el);
188
ignore_statement: IGNORE function_name
189
{ sensors_ignore new_el;
191
sensors_yyerror("Ignore statement before first chip statement");
197
ignore_add_el(&new_el);
201
chip_statement: CHIP chip_name_list
202
{ sensors_chip new_el;
204
new_el.labels = NULL;
206
new_el.computes = NULL;
207
new_el.ignores = NULL;
208
new_el.labels_count = new_el.labels_max = 0;
209
new_el.sets_count = new_el.sets_max = 0;
210
new_el.computes_count = new_el.computes_max = 0;
211
new_el.ignores_count = new_el.ignores_max = 0;
213
chip_add_el(&new_el);
214
current_chip = sensors_config_chips +
215
sensors_config_chips_count - 1;
219
chip_name_list: chip_name
222
$$.fits_count = $$.fits_max = 0;
225
| chip_name_list chip_name
232
{ $$ = malloc_expr();
234
$$->kind = sensors_kind_val;
237
{ $$ = malloc_expr();
239
$$->kind = sensors_kind_var;
242
{ $$ = malloc_expr();
243
$$->kind = sensors_kind_source;
245
| expression '+' expression
246
{ $$ = malloc_expr();
247
$$->kind = sensors_kind_sub;
248
$$->data.subexpr.op = sensors_add;
249
$$->data.subexpr.sub1 = $1;
250
$$->data.subexpr.sub2 = $3;
252
| expression '-' expression
253
{ $$ = malloc_expr();
254
$$->kind = sensors_kind_sub;
255
$$->data.subexpr.op = sensors_sub;
256
$$->data.subexpr.sub1 = $1;
257
$$->data.subexpr.sub2 = $3;
259
| expression '*' expression
260
{ $$ = malloc_expr();
261
$$->kind = sensors_kind_sub;
262
$$->data.subexpr.op = sensors_multiply;
263
$$->data.subexpr.sub1 = $1;
264
$$->data.subexpr.sub2 = $3;
266
| expression '/' expression
267
{ $$ = malloc_expr();
268
$$->kind = sensors_kind_sub;
269
$$->data.subexpr.op = sensors_divide;
270
$$->data.subexpr.sub1 = $1;
271
$$->data.subexpr.sub2 = $3;
273
| '-' expression %prec NEG
274
{ $$ = malloc_expr();
275
$$->kind = sensors_kind_sub;
276
$$->data.subexpr.op = sensors_negate;
277
$$->data.subexpr.sub1 = $2;
278
$$->data.subexpr.sub2 = NULL;
283
{ $$ = malloc_expr();
284
$$->kind = sensors_kind_sub;
285
$$->data.subexpr.op = sensors_exp;
286
$$->data.subexpr.sub1 = $2;
287
$$->data.subexpr.sub2 = NULL;
290
{ $$ = malloc_expr();
291
$$->kind = sensors_kind_sub;
292
$$->data.subexpr.op = sensors_log;
293
$$->data.subexpr.sub1 = $2;
294
$$->data.subexpr.sub2 = NULL;
299
{ int res = sensors_parse_bus_id($1,&$$);
302
sensors_yyerror("Parse error in bus id");
321
{ int res = sensors_parse_chip_name($1,&$$);
324
sensors_yyerror("Parse error in chip name");
332
void sensors_yyerror(const char *err)
334
if (sensors_lex_error[0]) {
335
sensors_parse_error_wfn(sensors_lex_error, sensors_yyfilename, sensors_yylineno);
336
sensors_lex_error[0] = '\0';
338
sensors_parse_error_wfn(err, sensors_yyfilename, sensors_yylineno);
341
sensors_expr *malloc_expr(void)
343
sensors_expr *res = malloc(sizeof(sensors_expr));
345
sensors_fatal_error(__func__, "Allocating a new expression");