Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_citi.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_citi.y - parser for CITIfiles
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 
36 #define YYERROR_VERBOSE 42
37 #define YYDEBUG 1
38 #define YYMAXDEPTH 1000000
39 
40 #include "logging.h"
41 #include "complex.h"
42 #include "object.h"
43 #include "vector.h"
44 #include "dataset.h"
45 #include "strlist.h"
46 #include "check_citi.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="citi_"
53 
55 %token Float
56 %token Eol
57 %token DATA
58 %token VAR
59 %token NAME
60 %token Begin
61 %token End
62 %token Version
63 %token Identifier
64 %token Integer
65 %token CITIFILE
66 %token VarType
67 %token SegListBegin
68 %token VarListBegin
69 %token SegListEnd
70 %token VarListEnd
71 %token COMMENT
72 %token CONSTANT
73 %token SEG
74 
75 %union {
76  char * ident;
77  double f;
78  int d;
79  qucs::vector * v;
80  struct citi_package_t * p;
81  struct citi_header_t * h;
82 }
83 
84 %type <p> Package PackageList
85 %type <h> HeaderLine Header HeaderList
86 %type <d> Integer
87 %type <f> Float
88 %type <ident> Identifier VarType
89 %type <v> List VarList Data FloatList DataList
90 
91 %%
92 
93 Input:
94  PackageList {
95  citi_root = $1; /* describes a valid CITIfile */
96  }
97 ;
98 
99 PackageList: /* nothing */ { $$ = NULL; }
100  | Package PackageList {
101  if ($1) {
102  $1->next = $2;
103  $$ = $1;
104  } else {
105  $$ = $2;
106  }
107  }
108  | Eol PackageList {
109  $$ = $2;
110  }
111 ;
112 
113 Package:
114  Header DataList {
115  $$ = (struct citi_package_t *) calloc (sizeof (struct citi_package_t), 1);
116  $$->head = $1;
117  $$->data = $2;
118  }
119 ;
120 
121 Header:
122  CITIFILE Version Eol HeaderList {
123  $$ = $4;
124  }
125 ;
126 
127 HeaderList: { $$ = NULL; }
129  if ($1) {
130  $1->next = $2;
131  $$ = $1;
132  } else {
133  $$ = $2;
134  }
135  }
136 ;
137 
138 HeaderLine:
139  NAME Identifier Eol {
140  $$ = (struct citi_header_t *) calloc (sizeof (struct citi_header_t), 1);
141  $$->package = $2;
142  }
143  | VAR Identifier VarType Integer Eol {
144  $$ = (struct citi_header_t *) calloc (sizeof (struct citi_header_t), 1);
145  $$->var = $2;
146  $$->type = $3;
147  $$->n = $4;
148  $$->i1 = $$->i2 = -1;
149  }
150  | DATA Identifier VarType Eol {
151  $$ = (struct citi_header_t *) calloc (sizeof (struct citi_header_t), 1);
152  $$->var = $2;
153  $$->type = $3;
154  $$->n = $$->i1 = $$->i2 = -1;
155  }
156  | DATA Identifier '[' Integer ',' Integer ']' VarType Eol {
157  $$ = (struct citi_header_t *) calloc (sizeof (struct citi_header_t), 1);
158  $$->var = $2;
159  $$->i1 = $4;
160  $$->i2 = $6;
161  $$->type = $8;
162  $$->n = -1;
163  }
164  | DATA Identifier '[' Integer ']' VarType Eol {
165  $$ = (struct citi_header_t *) calloc (sizeof (struct citi_header_t), 1);
166  $$->var = $2;
167  $$->i1 = $4;
168  $$->type = $6;
169  $$->n = $$->i2 = -1;
170  }
172  /* ignore constants */
173  }
174 ;
175 
176 ValueList: /* nothing */ { }
177  | Float ValueList {
178  }
179 ;
180 
181 List:
182  SegListBegin Eol SEG Float Float Float Eol SegListEnd Eol {
183  $$ = new vector (qucs::linspace ($5, $4, (int) $6));
184  }
185  | VarListBegin Eol VarList VarListEnd Eol {
186  $$ = $3;
187  }
188 ;
189 
190 DataList: { $$ = NULL; }
191  | Data DataList {
192  if ($1) {
193  $1->setNext ($2);
194  $$ = $1;
195  } else {
196  $$ = $2;
197  }
198  }
199 ;
200 
201 Data:
202  Begin Eol FloatList End Eol {
203  $$ = $3;
204  }
205  | List {
206  $$ = $1;
207  }
208 ;
209 
210 FloatList: { $$ = new vector (); }
212  $3->add ($1);
213  $$ = $3;
214  }
215  | Float ',' Float Eol FloatList {
216  $5->add (nr_complex_t ($1, $3));
217  $$ = $5;
218  }
219 ;
220 
221 VarList: { $$ = new vector (); }
223  $3->add ($1);
224  $$ = $3;
225  }
226 ;
228 %%
229 
230 int citi_error (const char * error) {
231  logprint (LOG_ERROR, "line %d: %s\n", citi_lineno, error);
232  return 0;
233 }
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
int citi_lineno
Definition: parse_citi.y:53
Data DataList
Definition: parse_citi.y:191
name
Definition: parse_mdl.y:352
Package PackageList
Definition: parse_citi.y:100
name prefix
Definition: parse_citi.y:52
Identifier
Definition: parse_csv.y:87
Float Eol VarList
Definition: parse_citi.y:222
h
Definition: parse_vcd.y:214
List
Definition: parse_citi.y:205
Value ValueList
Definition: parse_spice.y:864
VAR Identifier VarType Integer Eol
Definition: parse_citi.y:143
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
qucs::vector linspace(nr_double_t, nr_double_t, int)
Definition: vector.cpp:950
Float
Definition: parse_citi.y:213
int citi_error(const char *error)
Definition: parse_citi.y:230
HeaderLine HeaderList
Definition: parse_citi.y:128
#define LOG_ERROR
struct citi_package_t * citi_root
Definition: check_citi.cpp:49
v
Definition: parse_zvr.y:141
Float Eol FloatList
Definition: parse_citi.y:211
vcd scopes ident
Definition: parse_vcd.y:124
Eol HeaderLine
Definition: parse_csv.y:105
void logprint(int level, const char *format,...)
Definition: logging.c:37