controller_load_parser.y 6.08 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
/*
2
3
	Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2009, 2013
	Copyright Stichting C.A. Muller Radioastronomiestation, 2009, 2013
Jeroen Vreeken's avatar
Jeroen Vreeken committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

%{

#include <stdio.h>
#include <controller/controller_block.h>
#include <controller/controller_load.h>
#include <controller/controller_trace.h>
#include <controller/controller_sample.h>

Jeroen Vreeken's avatar
Jeroen Vreeken committed
28
#define YYERROR_VERBOSE
Jeroen Vreeken's avatar
Jeroen Vreeken committed
29

Jeroen Vreeken's avatar
Jeroen Vreeken committed
30
31
32
33
#include <controller/controller_load_parser.tab.h>
#include <controller/controller_load_parser.yy.h>

void yyerror(yyscan_t *scanner, char const *s);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
34
35
36

%}

Jeroen Vreeken's avatar
Jeroen Vreeken committed
37
38
39
40
41
%parse-param {yyscan_t scanner}
%lex-param {yyscan_t scanner}

%pure-parser

Jeroen Vreeken's avatar
Jeroen Vreeken committed
42
43
44
45
46
47
%start ctrllist

%token BRACEOPENSYM
%token BRACECLOSESYM
%token COMMASYM
%token <string> STRINGSYM
48
49
50
%token <string> VARIABLENAMESYM
%token <string> DOUBLEVARIABLESYM
%token <string> STRINGVARIABLESYM
Jeroen Vreeken's avatar
Jeroen Vreeken committed
51
52
53
54
55
56
57
58
59
%token <integer> BOOLSYM
%token <integer> INTSYM
%token <dbl> DOUBLESYM
%token <ul> UNSIGNEDLONGSYM
%token FREQUENCYSYM
%token BLOCKSSYM
%token LINKSSYM
%token TRACESSYM
%token PARAMSSYM
60
%token SETSYM
61
62
%token PARENTHESESOPENSYM
%token PARENTHESESCLOSESYM
63
%token INCLUDESYM
Jeroen Vreeken's avatar
Jeroen Vreeken committed
64

65
66
67
%token FUNC_DEG2RAD_SYM
%token FUNC_RPM2RADS_SYM

68
69
%token <dbl> CONST_PI_SYM

70
71
%left DUMMY_DOUBLEVAR
%left DUMMY_INTVAR
72
%left FLOATCASTSYM DOUBLECASTSYM INTCASTSYM BOOLCASTSYM
73
74
75
76
77
78
79

%left MINSYM
%left PLUSSYM
%left SLASHSYM
%left STARSYM
%left UMINUS

Jeroen Vreeken's avatar
Jeroen Vreeken committed
80
81
82
83
84
85
86
87
%union
{
	char *string;
	int integer;
	double dbl;
	unsigned long ul;
}

88
%type <string> stringvar
89
90
91
92
93
94
95
%type <dbl> doublevar
%type <integer> intvar
%type <ul> unsignedlongvar

%type <dbl> deg2rad
%type <dbl> rpm2rads

Jeroen Vreeken's avatar
Jeroen Vreeken committed
96
97
98
99
100
101
102
103
104
105
106
%%

ctrllist: ctrl
	| ctrl ctrllist
	;

ctrl	: frequency
	| links
	| blocks
	| traces
	| params
107
	| include
108
	| set
Jeroen Vreeken's avatar
Jeroen Vreeken committed
109
110
111
112
113
114
115
116
	;

frequency: FREQUENCYSYM DOUBLESYM
		{ controller_load_frequency($2); }
	| FREQUENCYSYM INTSYM
		{ controller_load_frequency($2); }
	;

117
include: INCLUDESYM STRINGSYM
118
119
120
121
122
123
		{ 
			if (controller_load_include($2)) {
				yyerror(scanner, "Failed to parse include");
				YYERROR;
			}
		}
124
125
	;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
126
127
128
129
130
131
132
133
134
135
136
blocks	: BLOCKSSYM BRACEOPENSYM blocklist BRACECLOSESYM

blocklist: block
	| block blocklist
	;

block	: BRACEOPENSYM
		STRINGSYM COMMASYM 
		STRINGSYM varlist
		BRACECLOSESYM
		{
137
			if(controller_load_block_create($2, $4, scanner)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
138
				yyerror(scanner, "Error creating block");
139
140
				YYERROR;
			}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
141
142
			free($2);
			free($4);
143
			controller_load_var_clear(scanner);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
		}
	;

params	: PARAMSSYM BRACEOPENSYM paramlist BRACECLOSESYM

paramlist: param
	| param paramlist
	;

param	: BRACEOPENSYM
		STRINGSYM COMMASYM
		STRINGSYM
		varlist
		BRACECLOSESYM
		{
159
			if (controller_load_block_param_set($2, $4, scanner)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
160
				yyerror(scanner, "Error setting parameter");
161
162
				YYERROR;
			}
163
			controller_load_var_clear(scanner);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
164
165
166
167
168
169
170
		}
	;

varlist	:	/* varlist may be emtpy */
	| COMMASYM var varlist
	;

171
var	: stringvar
172
		{ controller_load_var_add_str($1, scanner); }
173
	| doublevar %prec DUMMY_DOUBLEVAR
174
		{ controller_load_var_add_dbl($1, scanner); }
175
	| intvar %prec DUMMY_INTVAR
176
		{ controller_load_var_add_int($1, scanner); }
177
	| unsignedlongvar
178
		{ controller_load_var_add_ul($1, scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
179
	| FLOATCASTSYM 
180
		{ controller_load_var_add_float_array_start(scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
181
		BRACEOPENSYM floatlist BRACECLOSESYM
182
		{ controller_load_var_add_float_array_end(scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
183
184
	;

185
186
187
188
189
stringvar: STRINGSYM
	| STRINGVARIABLESYM
		{ controller_load_variable_string_get($1); }
	;

190
191
floatlist: floatlistvar
	| floatlistvar COMMASYM floatlist
Jeroen Vreeken's avatar
Jeroen Vreeken committed
192
193
	;

194
floatlistvar: doublevar
195
196
197
		{ controller_load_var_add_flt($1, scanner); }
	;

198
199
200
doublevar: DOUBLEVARIABLESYM
		{ $$ = controller_load_variable_double_get($1); }
	| DOUBLESYM
201
		{ $$ = $1; }
202
203
	| FLOATCASTSYM doublevar
		{ $$ = $2; }
204
205
	| DOUBLECASTSYM doublevar
		{ $$ = $2; }
206
	| FLOATCASTSYM intvar
207
		{ $$ = $2; }
208
	| DOUBLECASTSYM intvar
209
		{ $$ = $2; }
210
211
212
	| FLOATCASTSYM unsignedlongvar
		{ $$ = $2; }
	| DOUBLECASTSYM unsignedlongvar
213
214
215
216
217
218
219
220
221
		{ $$ = $2; }
	| doublevar MINSYM doublevar
		{ $$ = ($1) - ($3); }
	| doublevar PLUSSYM doublevar
		{ $$ = ($1) + ($3); }
	| doublevar SLASHSYM doublevar
		{ $$ = ($1) / ($3); }
	| doublevar STARSYM doublevar
		{ $$ = ($1) * ($3); }
222
223
224
225
	| deg2rad
		{ $$ = $1; }
	| rpm2rads
		{ $$ = $1; }
226
227
	| CONST_PI_SYM
		{ $$ = M_PI; }
228
229
	| MINSYM doublevar %prec UMINUS
		{ $$ = - $2 }
230
231
232
	;


233
deg2rad: FUNC_DEG2RAD_SYM PARENTHESESOPENSYM doublevar PARENTHESESCLOSESYM
234
235
236
		{ $$ = ($3) * M_PI / 180.0; }
	;

237
rpm2rads: FUNC_RPM2RADS_SYM PARENTHESESOPENSYM doublevar PARENTHESESCLOSESYM
238
239
240
241
242
243
244
		{ $$ = ($3) * 2.0 * M_PI / 60.0; }
	;

intvar: INTSYM
		{ $$ = $1; }
	| INTCASTSYM intvar
		{ $$ = $2; }
245
246
	| INTCASTSYM doublevar
		{ $$ = $2; }
247
248
249
250
	| BOOLSYM
		{ $$ = $1; }
	| BOOLCASTSYM intvar
		{ $$ = $2; }
251
252
	| MINSYM intvar %prec UMINUS
		{ $$ = - $2 }
253
254
255
256
257
	;

unsignedlongvar: UNSIGNEDLONGSYM
		{ $$ = $1; }
	;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
258

259
260
261
262
263
264
set:	SETSYM VARIABLENAMESYM doublevar
		{ controller_load_variable_double_set($2, $3) }
	| SETSYM VARIABLENAMESYM stringvar
		{ controller_load_variable_string_set($2, $3) }
	;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
links	: LINKSSYM BRACEOPENSYM linklist BRACECLOSESYM

linklist: link
	| link linklist
	;

link	: BRACEOPENSYM
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM
		BOOLSYM
		BRACECLOSESYM
		{
279
			if (controller_block_connect($2, $4, $6, $8, $10)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
280
				yyerror(scanner, "Error connecting blocks");
281
282
				YYERROR;
			}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
			free($2);
			free($4);
			free($6);
			free($8);
		}
	;

traces	: TRACESSYM BRACEOPENSYM tracelist BRACECLOSESYM

tracelist: trace
	| trace tracelist
	;

trace	: BRACEOPENSYM
		STRINGSYM COMMASYM
		STRINGSYM COMMASYM
		STRINGSYM COMMASYM
		STRINGSYM
		BRACECLOSESYM
		{
			struct controller_trace_name trace;
			
			trace.name = $2;
			trace.unit = $4;
			trace.blockname = $6;
			trace.termname = $8;

			controller_trace_list_add(&trace);
		}
	;