controller_load_parser.y 5.49 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
48
49
50
51
52
53
54
55
56
%start ctrllist

%token BRACEOPENSYM
%token BRACECLOSESYM
%token COMMASYM
%token <string> STRINGSYM
%token <integer> BOOLSYM
%token <integer> INTSYM
%token <dbl> DOUBLESYM
%token <ul> UNSIGNEDLONGSYM
%token FREQUENCYSYM
%token BLOCKSSYM
%token LINKSSYM
%token TRACESSYM
%token PARAMSSYM
57
58
%token PARENTHESESOPENSYM
%token PARENTHESESCLOSESYM
Jeroen Vreeken's avatar
Jeroen Vreeken committed
59
%token INTCASTSYM
Jeroen Vreeken's avatar
Jeroen Vreeken committed
60
%token BOOLCASTSYM
61
%token INCLUDESYM
Jeroen Vreeken's avatar
Jeroen Vreeken committed
62

63
64
65
%token FUNC_DEG2RAD_SYM
%token FUNC_RPM2RADS_SYM

66
67
68
69
70
71
72
73
74
75
%left DUMMY_DOUBLEVAR
%left DUMMY_INTVAR
%left FLOATCASTSYM DOUBLECASTSYM

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

Jeroen Vreeken's avatar
Jeroen Vreeken committed
76
77
78
79
80
81
82
83
%union
{
	char *string;
	int integer;
	double dbl;
	unsigned long ul;
}

84
%type <dbl> doublevar
85
%type <dbl> double_castable
86
87
88
89
90
91
%type <integer> intvar
%type <ul> unsignedlongvar

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

Jeroen Vreeken's avatar
Jeroen Vreeken committed
92
93
94
95
96
97
98
99
100
101
102
%%

ctrllist: ctrl
	| ctrl ctrllist
	;

ctrl	: frequency
	| links
	| blocks
	| traces
	| params
103
	| include
Jeroen Vreeken's avatar
Jeroen Vreeken committed
104
105
106
107
108
109
110
111
	;

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

112
113
114
115
include: INCLUDESYM STRINGSYM
		{ controller_load_include($2); }
	;

Jeroen Vreeken's avatar
Jeroen Vreeken committed
116
117
118
119
120
121
122
123
124
125
126
blocks	: BLOCKSSYM BRACEOPENSYM blocklist BRACECLOSESYM

blocklist: block
	| block blocklist
	;

block	: BRACEOPENSYM
		STRINGSYM COMMASYM 
		STRINGSYM varlist
		BRACECLOSESYM
		{
127
			if(controller_load_block_create($2, $4, scanner)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
128
				yyerror(scanner, "Error creating block");
129
130
				YYERROR;
			}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
131
132
			free($2);
			free($4);
133
			controller_load_var_clear(scanner);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
		}
	;

params	: PARAMSSYM BRACEOPENSYM paramlist BRACECLOSESYM

paramlist: param
	| param paramlist
	;

param	: BRACEOPENSYM
		STRINGSYM COMMASYM
		STRINGSYM
		varlist
		BRACECLOSESYM
		{
149
			if (controller_load_block_param_set($2, $4, scanner)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
150
				yyerror(scanner, "Error setting parameter");
151
152
				YYERROR;
			}
153
			controller_load_var_clear(scanner);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
154
155
156
157
158
159
160
161
		}
	;

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

var	: STRINGSYM
162
		{ controller_load_var_add_str($1, scanner); }
163
	| doublevar %prec DUMMY_DOUBLEVAR
164
		{ controller_load_var_add_dbl($1, scanner); }
165
	| intvar %prec DUMMY_INTVAR
166
		{ controller_load_var_add_int($1, scanner); }
167
	| unsignedlongvar
168
		{ controller_load_var_add_ul($1, scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
169
	| FLOATCASTSYM 
170
		{ controller_load_var_add_float_array_start(scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
171
		BRACEOPENSYM floatlist BRACECLOSESYM
172
		{ controller_load_var_add_float_array_end(scanner); }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
173
174
	;

175
176
floatlist: floatlistvar
	| floatlistvar COMMASYM floatlist
Jeroen Vreeken's avatar
Jeroen Vreeken committed
177
178
	;

179
180
181
182
183
184
floatlistvar: double_castable
		{ controller_load_var_add_flt($1, scanner); }
	;

double_castable: doublevar
		{ $$ = $1; }
185
	| intvar
186
		{ $$ = $1; }
187
	| unsignedlongvar
188
		{ $$ = $1; }
Jeroen Vreeken's avatar
Jeroen Vreeken committed
189
	;
190

191
192
doublevar: DOUBLESYM
		{ $$ = $1; }
193
194
195
	| DOUBLECASTSYM doublevar
		{ $$ = $2; }
	| FLOATCASTSYM doublevar
196
		{ $$ = $2; }
197
	| DOUBLECASTSYM intvar
198
		{ $$ = $2; }
199
200
201
202
203
204
205
206
207
208
	| FLOATCASTSYM intvar
		{ $$ = $2; }
	| doublevar MINSYM doublevar
		{ $$ = ($1) - ($3); }
	| doublevar PLUSSYM doublevar
		{ $$ = ($1) + ($3); }
	| doublevar SLASHSYM doublevar
		{ $$ = ($1) / ($3); }
	| doublevar STARSYM doublevar
		{ $$ = ($1) * ($3); }
209
210
211
212
	| deg2rad
		{ $$ = $1; }
	| rpm2rads
		{ $$ = $1; }
213
214
	| MINSYM doublevar %prec UMINUS
		{ $$ = - $2 }
215
216
217
	;


218
deg2rad: FUNC_DEG2RAD_SYM PARENTHESESOPENSYM double_castable PARENTHESESCLOSESYM
219
220
221
		{ $$ = ($3) * M_PI / 180.0; }
	;

222
rpm2rads: FUNC_RPM2RADS_SYM PARENTHESESOPENSYM double_castable PARENTHESESCLOSESYM
223
224
225
226
227
228
229
230
231
232
233
		{ $$ = ($3) * 2.0 * M_PI / 60.0; }
	;

intvar: INTSYM
		{ $$ = $1; }
	| INTCASTSYM intvar
		{ $$ = $2; }
	| BOOLSYM
		{ $$ = $1; }
	| BOOLCASTSYM intvar
		{ $$ = $2; }
234
235
	| MINSYM intvar %prec UMINUS
		{ $$ = - $2 }
236
237
238
239
240
	;

unsignedlongvar: UNSIGNEDLONGSYM
		{ $$ = $1; }
	;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

links	: LINKSSYM BRACEOPENSYM linklist BRACECLOSESYM

linklist: link
	| link linklist
	;

link	: BRACEOPENSYM
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM 
		STRINGSYM COMMASYM
		BOOLSYM
		BRACECLOSESYM
		{
256
			if (controller_block_connect($2, $4, $6, $8, $10)) {
Jeroen Vreeken's avatar
Jeroen Vreeken committed
257
				yyerror(scanner, "Error connecting blocks");
258
259
				YYERROR;
			}
Jeroen Vreeken's avatar
Jeroen Vreeken committed
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
			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);
		}
	;