Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_mdl.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_mdl.y - parser for an IC-CAP MDL data file
6  *
7  * Copyright (C) 2006 Stefan Jahn <stefan@lkcc.org>
8  *
9  * This is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This software is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this package; see the file COPYING. If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  * $Id$
25  *
26  */
27 
28 #if HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36 
37 #define YYERROR_VERBOSE 42
38 #define YYDEBUG 1
39 #define YYMAXDEPTH 1000000
40 
41 #define __NOEXTENSIONS__ 1
42 
43 #include "object.h"
44 #include "complex.h"
45 #include "vector.h"
46 #include "check_mdl.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="mdl_"
53 
54 %token LINK
55 %token Identifier
56 %token String
57 %token InvalidCharacter
58 %token Real
59 %token t_LINK
60 %token t_VIEW
61 %token t_TABLE
62 %token t_PSTABLE
63 %token t_CNTABLE
64 %token t_OPTIMEDIT
65 %token t_BLKEDIT
66 %token t_HYPTABLE
67 %token t_ELEMENT
68 %token t_DATA
69 %token t_DATASET
70 %token t_DATASIZE
71 %token t_POINT
72 %token t_MEMBER
73 %token t_LIST
74 %token t_PLOTOPTIMIZEROPT
75 %token t_PLOTOPTIMIZERTRACESET
76 %token t_PLOTOPTIMIZERTRACEREGSET
77 %token t_PLOTOPTIMIZERTRACENATREGSET
78 %token t_PLOTERROR
79 %token t_TYPE
80 %token t_CIRCUITDECK
81 %token t_PARAM
82 %token t_RANGE
83 %token t_CONNPAIR
84 %token t_CALDATA
85 %token t_CALSET
86 %token t_TERM
87 %token t_APPLIC
88 %token t_SUBAPP
89 %token t_EDITSIZE
90 %token t_PLOTSIZE
91 %token t_OPTRANGE
92 
93 %union {
94  char * ident;
95  double f;
96  struct mdl_point_t * point;
97  struct mdl_dataset_t * dset;
98  struct mdl_datasize_t * dsize;
99  struct mdl_link_t * link;
100  struct mdl_data_t * data;
101  struct mdl_dcontent_t * dcontent;
102  struct mdl_lcontent_t * lcontent;
103  struct mdl_element_t * element;
104  struct mdl_hyptable_t * hyptable;
105  struct mdl_table_t * table;
106 }
107 
108 %type <ident> Identifier t_LINK String TYPE_Line
109 %type <point> POINT_Line PointList Point
110 %type <f> Real
111 %type <dset> DSContent DATASET_Definition
112 %type <link> LINK_Definition LinkList
113 %type <lcontent> LinkContent LinkContentList
114 %type <dcontent> DataContent DataContentList
115 %type <data> DATA_Definition
116 %type <dsize> DATASIZE_Line
117 %type <element> ELEMENT_Line HypTableContent HypTableContentList
118 %type <element> TableContent TableContentList
119 %type <hyptable> HYPTABLE_Definition
120 %type <table> TABLE_Definition
121 
122 %%
123 
124 Input:
125  LinkList {
126  mdl_root = $1;
127  }
128 ;
129 
130 LinkList: /* nothing */ { $$ = NULL; }
132  $1->next = $2;
133  $$ = $1;
134  }
135 ;
136 
137 TableContent:
138  VIEW_Line {
139  $$ = NULL;
140  }
142  $$ = $1;
143  }
145  $$ = NULL;
146  }
147 ;
148 
149 TableContentList: /* nothing */ { $$ = NULL; }
150  | TableContent TableContentList {
151  if ($1) {
152  $1->next = $2;
153  $$ = $1;
154  } else {
155  $$ = $2;
156  }
157  }
158 ;
159 
160 HypTableContent:
161  VIEW_Line {
162  $$ = NULL;
163  }
164  | ELEMENT_Line {
165  $$ = $1;
166  }
167 ;
168 
169 HypTableContentList: /* nothing */ { $$ = NULL; }
170  | HypTableContent HypTableContentList {
171  if ($1) {
172  $1->next = $2;
173  $$ = $1;
174  } else {
175  $$ = $2;
176  }
177  }
178 ;
179 
180 ConnTableContent:
181  CONNPAIR_Line
182 ;
183 
184 ConnTableContentList: /* nothing */ { }
185  | ConnTableContent ConnTableContentList {
186  }
187 ;
188 
189 OptEditContent:
190  VIEW_Line
192 ;
193 
194 OptEditContentList: /* nothing */ { }
195  | OptEditContent OptEditContentList {
196  }
197 ;
198 
199 LinkContent:
200  VIEW_Line {
201  $$ = NULL;
202  }
204  $$ = NULL;
205  }
207  $$ = NULL;
208  }
210  $$ = NULL;
211  }
213  $$ = NULL;
214  }
215  | TABLE_Definition {
216  $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
217  $$->type = t_TABLE;
218  $$->table = $1;
219  }
221  $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
222  $$->type = t_LINK;
223  $$->link = $1;
224  }
226  $$ = (struct mdl_lcontent_t *) calloc (sizeof (struct mdl_lcontent_t), 1);
227  $$->type = t_DATA;
228  $$->data = $1;
229  }
230 ;
231 
232 LinkContentList: /* nothing */ { $$ = NULL; }
233  | LinkContent LinkContentList {
234  if ($1) {
235  $1->next = $2;
236  $$ = $1;
237  } else {
238  $$ = $2;
239  }
240  }
241 ;
242 
243 DataContent:
244  PLOTOPTIMIZEROPT_Line {
245  $$ = NULL;
246  }
248  $$ = NULL;
249  }
251  $$ = NULL;
252  }
254  $$ = NULL;
255  }
257  $$ = NULL;
258  }
260  $$ = NULL;
261  }
263  $$ = NULL;
264  }
265  | TABLE_Definition {
266  $$ = NULL;
267  }
269  $$ = NULL;
270  }
272  $$ = NULL;
273  }
275  $$ = NULL;
276  }
278  $$ = NULL;
279  }
281  $$ = (struct mdl_dcontent_t *) calloc (sizeof (struct mdl_dcontent_t), 1);
282  $$->type = t_HYPTABLE;
283  $$->hyptable = $1;
284  }
286  $$ = (struct mdl_dcontent_t *) calloc (sizeof (struct mdl_dcontent_t), 1);
287  $$->type = t_DATASET;
288  $$->data = $1;
289  }
291  $$ = NULL;
292  }
294  $$ = NULL;
295  }
296 ;
297 
298 DataContentList: /* nothing */ { $$ = NULL; }
299  | DataContent DataContentList {
300  if ($1) {
301  $1->next = $2;
302  $$ = $1;
303  } else {
304  $$ = $2;
305  }
306  }
307 ;
308 
309 PSContent:
310  PARAM_Line
311  | RANGE_Line
312  | OPTRANGE_Line
313 ;
314 
315 PSContentList: /* nothing */ { }
316  | PSContent PSContentList {
317  }
318 ;
319 
320 DSContent:
321  DATASIZE_Line TYPE_Line PointList {
322  $$ = (struct mdl_dataset_t *) calloc (sizeof (struct mdl_dataset_t), 1);
323  $$->dsize = $1;
324  $$->type1 = $2;
325  $$->data1 = $3;
326  }
327  | DATASIZE_Line TYPE_Line PointList TYPE_Line PointList {
328  $$ = (struct mdl_dataset_t *) calloc (sizeof (struct mdl_dataset_t), 1);
329  $$->dsize = $1;
330  $$->type1 = $2;
331  $$->data1 = $3;
332  $$->type2 = $4;
333  $$->data2 = $5;
334  }
335 ;
336 
337 Point:
338  POINT_Line
339 ;
340 
341 PointList: /* nothing */ { $$ = NULL; }
342  | Point PointList {
343  $1->next = $2;
344  $$ = $1;
345  }
346 ;
347 
349  t_ELEMENT Real String String String {
350  $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
351  $$->number = (int) $2;
352  $$->name = $3;
353  $$->value = $4;
354  $$->attr = $5;
355  }
356  | t_ELEMENT Real String String {
357  $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
358  $$->number = (int) $2;
359  $$->name = $3;
360  $$->value = $4;
361  }
362  | t_ELEMENT String String {
363  $$ = (struct mdl_element_t *) calloc (sizeof (struct mdl_element_t), 1);
364  $$->name = $2;
365  $$->value = $3;
366  }
367 ;
368 
369 VIEW_Line:
370  t_VIEW Identifier Real String {
371  free ($2);
372  free ($4);
373  }
374 ;
375 
377  t_TABLE String '{' TableContentList '}' {
378  $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
379  $$->name = $2;
380  $$->data = $4;
381  }
382  | t_TABLE String Real '{' TableContentList '}' {
383  $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
384  $$->name = $2;
385  $$->data = $5;
386  }
387  | t_TABLE '{' '}' {
388  $$ = (struct mdl_table_t *) calloc (sizeof (struct mdl_table_t), 1);
389  }
390 ;
391 
393  LINK t_LINK String '{' LinkContentList '}' {
394  $$ = (struct mdl_link_t *) calloc (sizeof (struct mdl_link_t), 1);
395  $$->name = $3;
396  $$->type = $2;
397  $$->content = $5;
398  }
399 ;
400 
402  t_DATA '{' DataContentList '}' {
403  $$ = (struct mdl_data_t *) calloc (sizeof (struct mdl_data_t), 1);
404  $$->content = $3;
405  }
406 ;
407 
409  t_PSTABLE String '{' PSContentList '}' {
410  free ($2);
411  }
412 ;
413 
415  t_CIRCUITDECK '{' '}'
416 ;
417 
419  t_BLKEDIT String '{' '}' {
420  free ($2);
421  }
422 ;
423 
425  t_CNTABLE String '{' ConnTableContentList '}' {
426  free ($2);
427  }
428 ;
429 
431  t_OPTIMEDIT '{' OptEditContentList '}' {
432  }
433 ;
434 
436  t_CALSET String '{' CalSetContent '}' {
437  free ($2);
438  }
439 ;
440 
441 CalSetContent:
443  CALDATA_Definition {
444  }
445 ;
446 
447 CALDATA_Definition:
448  t_CALDATA '{' CalDataContentList '}' {
449  }
450 ;
451 
452 CalDataContentList: /* nothing */ { }
453  | CalDataContent CalDataContentList {
454  }
455 ;
456 
457 CalDataContent:
458  TERM_Line PointList {
459  }
460 ;
461 
462 TERM_Line:
463  t_TERM Real {
464  }
465 ;
466 
468  t_APPLIC String Real Real Real {
469  free ($2);
470  }
471 ;
472 
474  t_SUBAPP String Real {
475  free ($2);
476  }
477 ;
478 
480  t_HYPTABLE String '{' HypTableContentList '}' {
481  $$ = (struct mdl_hyptable_t *) calloc (sizeof (struct mdl_hyptable_t), 1);
482  $$->name = $2;
483  $$->data = $4;
484  }
485 ;
486 
488  t_DATASET '{' DSContent '}' {
489  $$ = $3;
490  }
491 ;
492 
493 DATASIZE_Line:
494  t_DATASIZE Identifier Real Real Real {
495  $$ = (struct mdl_datasize_t *) calloc (sizeof (struct mdl_datasize_t), 1);
496  $$->type = $2;
497  $$->size = (int) $3;
498  $$->x = (int) $4;
499  $$->y = (int) $5;
500  }
501 ;
502 
503 TYPE_Line:
504  t_TYPE Identifier {
505  $$ = $2;
506  }
507 ;
508 
509 POINT_Line:
510  t_POINT Real Real Real Real Real {
511  $$ = (struct mdl_point_t *) calloc (sizeof (struct mdl_point_t), 1);
512  $$->n = (int) $2;
513  $$->x = (int) $3;
514  $$->y = (int) $4;
515  $$->r = $5;
516  $$->i = $6;
517  }
518 ;
519 
520 LIST_Line:
521  t_LIST t_LINK String {
522  free ($2);
523  free ($3);
524  }
525 ;
526 
527 PLOTOPTIMIZEROPT_Line:
528  t_PLOTOPTIMIZEROPT Identifier Real {
529  free ($2);
530  }
531 ;
532 
534  t_PLOTOPTIMIZERTRACESET String String String {
535  free ($2);
536  free ($3);
537  free ($4);
538  }
539  | t_PLOTOPTIMIZERTRACESET String String {
540  free ($2);
541  free ($3);
542  }
543 ;
544 
546  t_PLOTOPTIMIZERTRACEREGSET String Real String String String String {
547  free ($2);
548  free ($4);
549  free ($5);
550  free ($6);
551  free ($7);
552  }
553 ;
554 
556  t_PLOTOPTIMIZERTRACENATREGSET String Real String String String String {
557  free ($2);
558  free ($4);
559  free ($5);
560  free ($6);
561  free ($7);
562  }
563 ;
564 
566  t_PLOTERROR Identifier Real {
567  free ($2);
568  }
569 ;
570 
572  t_EDITSIZE Real Real {
573  }
574 ;
575 
577  t_PLOTSIZE Real Real {
578  }
579 ;
580 
582  t_MEMBER t_LINK String {
583  free ($2);
584  free ($3);
585  }
586 ;
587 
588 PARAM_Line:
589  t_PARAM Identifier String {
590  free ($2);
591  free ($3);
592  }
593 ;
594 
595 RANGE_Line:
596  t_RANGE Identifier String String {
597  free ($2);
598  free ($3);
599  free ($4);
600  }
601 ;
602 
603 OPTRANGE_Line:
604  t_OPTRANGE Identifier String String {
605  free ($2);
606  free ($3);
607  free ($4);
608  }
609 ;
610 
611 CONNPAIR_Line:
612  t_CONNPAIR String String {
613  free ($2);
614  free ($3);
615  }
616 ;
617 
618 %%
619 
620 int mdl_error (const char * error) {
621  fprintf (stderr, "line %d: %s\n", mdl_lineno, error);
622  return 0;
623 }
CIRCUITDECK_Definition
Definition: parse_mdl.y:293
TABLE_Definition
Definition: parse_mdl.y:144
name prefix
Definition: parse_mdl.y:52
APPLIC_Line
Definition: parse_mdl.y:203
DATASET_Definition
Definition: parse_mdl.y:285
name
Definition: parse_mdl.y:352
Identifier
Definition: parse_csv.y:87
PSTABLE_Definition
Definition: parse_mdl.y:268
t_ELEMENT Real String String
Definition: parse_mdl.y:356
PLOTSIZE_Line
Definition: parse_mdl.y:262
LinkContent LinkContentList
Definition: parse_mdl.y:233
LIST_Line
Definition: parse_mdl.y:209
LINK_Definition LinkList
Definition: parse_mdl.y:131
OPTIMEDIT_Definition
Definition: parse_mdl.y:274
PLOTERROR_Line
Definition: parse_mdl.y:256
struct mdl_link_t * mdl_root
Definition: check_mdl.cpp:53
int mdl_error(const char *)
Definition: parse_mdl.y:620
CNTABLE_Definition
Definition: parse_mdl.y:271
DataContent DataContentList
Definition: parse_mdl.y:299
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
table
Definition: parse_mdl.y:218
int mdl_lineno
BLKEDIT_Definition
Definition: parse_mdl.y:290
t_TABLE String Real
Definition: parse_mdl.y:382
hyptable
Definition: parse_mdl.y:283
DATASIZE_Line TYPE_Line PointList TYPE_Line PointList
Definition: parse_mdl.y:327
LINK_Definition
Definition: parse_mdl.y:220
PLOTOPTIMIZERTRACESET_Line
Definition: parse_mdl.y:247
MEMBER_Line
Definition: parse_mdl.y:212
SUBAPP_Line
Definition: parse_mdl.y:206
DATA_Definition
Definition: parse_mdl.y:225
TableContent TableContentList
Definition: parse_mdl.y:150
HYPTABLE_Definition
Definition: parse_mdl.y:280
List int
Definition: parse_citi.y:183
DSContent dsize
Definition: parse_mdl.y:323
PLOTOPTIMIZERTRACENATREGSET_Line
Definition: parse_mdl.y:253
vcd scopes ident
Definition: parse_vcd.y:124
HypTableContent HypTableContentList
Definition: parse_mdl.y:170
CALSET_Definition
Definition: parse_mdl.y:277
PLOTOPTIMIZERTRACEREGSET_Line
Definition: parse_mdl.y:250
ELEMENT_Line
Definition: parse_mdl.y:141
free($4)
EDITSIZE_Line
Definition: parse_mdl.y:259
link
Definition: parse_mdl.y:223
data
Definition: parse_mdl.y:228