-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.y
351 lines (340 loc) · 12.6 KB
/
parser.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
%{
#include <stdio.h>
#include <stdlib.h>
#include "log.h"
#include "parser.h"
extern int yylex();
extern void yyerror();
%}
%union{
char *sv;
double dv;
int iv;
}
%token <sv> RE_T CE_T LE_T EE_T FE_T GE_T HE_T VE_T IE_T ELM_T
%token <iv> INT_T
%token <dv> DEC_T PREF_T
%token TS_T DS_T AS_T G2_T END_T DC_T AC_T SINE_T PULSE_T RAMP_T STEP_T PLT_T IC_T
%type <dv> value
%define parse.error verbose
%%
netlist:
| netlist statement
| netlist END_T
;
statement:
| element '\n'
| control '\n'
| element YYEOF
| '\n'
;
control:
dc
| tran
| ac
| plot
;
element:
resistor
| capacitor
| inductor
| current_source
| voltage_source
| voltage_controled_voltage_source
| voltage_controled_current_source
| current_controled_voltage_source
| current_controled_current_source
;
resistor:
RE_T INT_T INT_T value {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,1,0);
log_trace("Resistor : %s ,node %d --> %d ,value = %.16f OHM.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| RE_T INT_T INT_T value G2_T {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,2,0);
log_trace("Resistor : %s ,node %d --> %d ,value = %.16f OHM.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
;
capacitor:
CE_T INT_T INT_T value {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,1,0);
log_trace("Capacitor : %s ,node %d --> %d ,value = %.16f FARAD.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| CE_T INT_T INT_T value IC_T value {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,1,$6);
log_trace("Capacitor : %s ,node %d --> %d ,value = %.16f FARAD, Ic = %f",$1,$2,$3,$4,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| CE_T INT_T INT_T value G2_T {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,2,0);
log_trace("Capacitor : %s ,node %d --> %d ,value = %.16f FARAD.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| CE_T INT_T INT_T value G2_T IC_T value{
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,2,$7);
log_trace("Capacitor : %s ,node %d --> %d ,value = %.16f FARAD, Ic = %f",$1,$2,$3,$4,$7);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
;
inductor:
LE_T INT_T INT_T value {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,2,0);
log_trace("Inductor : %s ,node %d --> %d ,value = %.16f Henry.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| LE_T INT_T INT_T value IC_T value {
add_node($2);
add_node($3);
add_RLC($1,$2,$3,$4,2,$6);
log_trace("Inductor : %s ,node %d --> %d ,value = %.16f Henry, Ic = %f",$1,$2,$3,$4,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
;
current_source:
IE_T INT_T INT_T value {
add_node($2);
add_node($3);
add_I($1,$2,$3,$4,1);
log_trace("DC Current Source : %s ,node %d --> %d ,value = %.16f A.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T DC_T value {
add_node($2);
add_node($3);
add_I($1,$2,$3,$5,1);
log_trace("DC Current Source : %s ,node %d --> %d ,value = %.16f A.",$1,$2,$3,$5);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T AC_T value value {
add_node($2);
add_node($3);
add_ac_i($1,$2,$3,$5,$6,1);
log_trace("AC Current Source : %s ,node %d --> %d ,amp = %f A, phase = %f deg.",$1,$2,$3,$5,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T SINE_T '(' value value value value value value ')' {
add_node($2);
add_node($3);
add_sine_i($1,$2,$3,$6,$7,$8,$9,$10,$11,1);
log_trace("SINE Current Source : %s ,node %d --> %d ,freq = %f, amp = %f, offset = %f, phase = %f, delay = %f A.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T PULSE_T '(' value value value value value value value ')' {
add_node($2);
add_node($3);
add_pulse_i($1,$2,$3,$6,$7,$8,$9,$10,$11,$12,1);
log_trace("PULSE Current Source : %s ,node %d --> %d ,Voff = %f, Von = %f, Ton = %f, Tperiod = %f, delay = %f A.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T RAMP_T '(' value ')' {
add_node($2);
add_node($3);
add_ramp_i($1,$2,$3,$6,1);
log_trace("RAMP Current Source : %s ,node %d --> %d ,delay = %f s.",$1,$2,$3,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T STEP_T '(' value value ')' {
add_node($2);
add_node($3);
add_step_i($1,$2,$3,$6,$7,1);
log_trace("DC Current Source : %s ,node %d --> %d ,Von = %f A, delay = %f s.",$1,$2,$3,$6,$7);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T value G2_T {
add_node($2);
add_node($3);
add_I($1,$2,$3,$4,2);
log_trace("DC Current Source : %s ,node %d --> %d ,value = %.16f A.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T DC_T value G2_T {
add_node($2);
add_node($3);
add_I($1,$2,$3,$5,2);
log_trace("DC Current Source : %s ,node %d --> %d ,value = %.16f A.",$1,$2,$3,$5);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T AC_T value value G2_T {
add_node($2);
add_node($3);
add_ac_i($1,$2,$3,$5,$6,2);
log_trace("AC Current Source : %s ,node %d --> %d ,amp = %f A, phase = %f deg.",$1,$2,$3,$5,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T SINE_T '(' value value value value value value ')' G2_T {
add_node($2);
add_node($3);
add_sine_i($1,$2,$3,$6,$7,$8,$9,$10,$11,2);
log_trace("SINE Current Source : %s ,node %d --> %d ,freq = %f, amp = %f, offset = %f, phase = %f, delay = %f A.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T PULSE_T '(' value value value value value value value ')' G2_T{
add_node($2);
add_node($3);
add_pulse_i($1,$2,$3,$6,$7,$8,$9,$10,$11,$12,2);
log_trace("PULSE Current Source : %s ,node %d --> %d ,Voff = %f, Von = %f, Ton = %f, Tperiod = %f, delay = %f A.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T RAMP_T '(' value ')' G2_T {
add_node($2);
add_node($3);
add_ramp_i($1,$2,$3,$6,2);
log_trace("RAMP Current Source : %s ,node %d --> %d ,delay = %f s.",$1,$2,$3,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| IE_T INT_T INT_T STEP_T '(' value value ')' G2_T {
add_node($2);
add_node($3);
add_step_i($1,$2,$3,$6,$7,2);
log_trace("DC Current Source : %s ,node %d --> %d ,Von = %f A, delay = %f s.",$1,$2,$3,$6,$7);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
;
voltage_source:
VE_T INT_T INT_T value {
add_node($2);
add_node($3);
add_V($1,$2,$3,$4);
log_trace("DC Voltage Source : %s ,node %d --> %d ,value = %.16f V.",$1,$2,$3,$4);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T DC_T value {
add_node($2);
add_node($3);
add_V($1,$2,$3,$5);
log_trace("DC Voltage Source : %s ,node %d --> %d ,value = %.16f V.",$1,$2,$3,$5);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T AC_T value value {
add_node($2);
add_node($3);
add_ac_v($1,$2,$3,$5,$6);
log_trace("AC Voltage Source : %s ,node %d --> %d ,amp = %f V, phase = %f deg.",$1,$2,$3,$5,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T SINE_T '(' value value value value value value ')' {
add_node($2);
add_node($3);
add_sine_v($1,$2,$3,$6,$7,$8,$9,$10,$11);
log_trace("SINE Voltage Source : %s ,node %d --> %d ,freq = %f, amp = %f, offset = %f, phase = %f, delay = %f V.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T PULSE_T '(' value value value value value value value ')' {
add_node($2);
add_node($3);
add_pulse_v($1,$2,$3,$6,$7,$8,$9,$10,$11,$12);
log_trace("PULSE Voltage Source : %s ,node %d --> %d ,Voff = %f, Von = %f, Ton = %f, Tperiod = %f, delay = %f V.",$1,$2,$3,$6,$7,$8,$9,$10);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T RAMP_T '(' value ')' {
add_node($2);
add_node($3);
add_ramp_v($1,$2,$3,$6);
log_trace("RAMP Voltage Source : %s ,node %d --> %d ,delay = %f s.",$1,$2,$3,$6);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
| VE_T INT_T INT_T STEP_T '(' value value ')' {
add_node($2);
add_node($3);
add_step_v($1,$2,$3,$6,$7);
log_trace("STEP Voltage Source : %s ,node %d --> %d ,Von = %f V, delay = %f s.",$1,$2,$3,$6,$7);
free($1); //DeAllocating sv memory which we allocatd in lexer
}
;
voltage_controled_voltage_source:
EE_T INT_T INT_T INT_T INT_T value {
add_node($2);
add_node($3);
add_node($4);
add_node($5);
add_VCVS($1, $2, $3, $4, $5, $6, 2);
log_trace("VCVS : %s ,control : %d --> %d ,out : %d --> %d ,value = %.16f",$1, $2, $3, $4, $5, $6);
free($1);
}
voltage_controled_current_source:
GE_T INT_T INT_T INT_T INT_T value {
add_node($2);
add_node($3);
add_node($4);
add_node($5);
add_VCCS($1, $2, $3, $4, $5, $6, 1);
log_trace("VCCS : %s ,control : %d --> %d ,out : %d --> %d ,value = %.16f",$1, $2, $3, $4, $5, $6);
free($1);
}
current_controled_voltage_source:
HE_T INT_T INT_T ELM_T value {
if($4[0] != 'V'){
log_fatal("A voltage source must be enterd!");
exit(EXIT_FAILURE);
}
add_node($2);
add_node($3);
add_CCCS($1, $4, $2, $3, $5, 2);
log_trace("CCVS : %s ,control : %s ,out : %d --> %d ,value = %.16f",$1 ,$4 ,$2 ,$3 ,$5);
free($1);
free($4);
}
current_controled_current_source:
FE_T INT_T INT_T ELM_T value {
if($4[0] != 'V'){
log_fatal("A voltage source must be enterd!");
exit(EXIT_FAILURE);
}
add_node($2);
add_node($3);
add_CCCS($1, $4, $2, $3, $5, 1);
log_trace("CCCS : %s ,control : %s ,out : %d --> %d ,value = %.16f",$1 ,$4 ,$2 ,$3 ,$5);
free($1);
free($4);
}
dc:
DS_T {
log_trace("DC Analysis Detected!");
set_simultaor_dc();
}
;
tran:
TS_T value value {
log_trace("Transient Analysis Detected!,stop time = %.16f, step = %.16f", $2, $3);
set_simultaor_tran($2, $3);
}
;
ac:
AS_T value {
log_trace("AC Analysis Detected! Frequency = %f", $2);
set_simulator_ac($2);
}
;
plot:
PLT_T INT_T {
char buff[20];
sprintf(buff, "%d",$2);
set_output(buff);
}
| PLT_T ELM_T{
set_output($2);
free($2);
}
value:
INT_T {$$ = (double)$1;}
| DEC_T
| DEC_T PREF_T {$$ = $1 * $2;}
;
%%