Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_touchstone.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_touchstone.y - parser for Touchstone files
6  *
7  * Copyright (C) 2003, 2005, 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_touchstone.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="touchstone_"
53 
54 %token InvalidCharacter
55 %token Float
56 %token Option
57 %token Eol
58 
59 %union {
60  char * ident;
61  double f;
62  qucs::vector * v;
63  qucs::strlist * list;
64 }
65 
66 %type <list> OptionList
67 %type <ident> Option
68 %type <f> Float
69 %type <v> DataLine Dataset
70 
71 %%
72 
73 Input:
74  OptionLine Dataset { /* describes a valid touchstone */ }
75 ;
76 
77 OptionLine: /* option line */
78  '#' OptionList 'R' Float OptionList Eol {
81  }
82  | '#' OptionList Eol {
85  }
86  | Eol OptionLine { /* skip this line */ }
87 ;
88 
89 OptionList: /* nothing */ { }
90  | Option OptionList {
91  if (touchstone_idents == NULL) touchstone_idents = new strlist ();
92  touchstone_idents->add ($1);
93  free ($1);
94  }
95 ;
96 
97 Dataset: /* nothing */ { }
98  | DataLine Eol Dataset { /* append vector lines */
99  $1->setNext (touchstone_vector);
100  touchstone_vector = $1;
101  }
102  | DataLine { /* last line, no trailing end-of-line */
103  $1->setNext (touchstone_vector);
104  touchstone_vector = $1;
105  logprint (LOG_ERROR, "line %d: no trailing end-of-line found, "
106  "continuing...\n", touchstone_lineno);
107  }
108  | Eol Dataset { /* skip this line */ }
109 ;
110 
111 DataLine:
112  Float Float Float {
113  /* 1-port start */
114  $$ = new vector ();
115  $$->add ($1);
116  $$->add ($2);
117  $$->add ($3);
118  }
120  /* noise parameters */
121  $$ = new vector ();
122  $$->add ($1);
123  $$->add ($2);
124  $$->add ($3);
125  $$->add ($4);
126  $$->add ($5);
127  }
129  /* 2-port and 4- to n-port start */
130  $$ = new vector ();
131  $$->add ($1);
132  $$->add ($2);
133  $$->add ($3);
134  $$->add ($4);
135  $$->add ($5);
136  $$->add ($6);
137  $$->add ($7);
138  $$->add ($8);
139  $$->add ($9);
140  }
142  /* 3-port start */
143  $$ = new vector ();
144  $$->add ($1);
145  $$->add ($2);
146  $$->add ($3);
147  $$->add ($4);
148  $$->add ($5);
149  $$->add ($6);
150  $$->add ($7);
151  }
153  /* 4- and n-port continued */
154  $$ = new vector ();
155  $$->add ($1);
156  $$->add ($2);
157  $$->add ($3);
158  $$->add ($4);
159  $$->add ($5);
160  $$->add ($6);
161  $$->add ($7);
162  $$->add ($8);
163  }
165  /* 3- and n-port continued */
166  $$ = new vector ();
167  $$->add ($1);
168  $$->add ($2);
169  $$->add ($3);
170  $$->add ($4);
171  $$->add ($5);
172  $$->add ($6);
173  }
174  | Float Float Float Float {
175  /* n-port continued */
176  $$ = new vector ();
177  $$->add ($1);
178  $$->add ($2);
179  $$->add ($3);
180  $$->add ($4);
181  }
182  | Float Float {
183  /* n-port continued */
184  $$ = new vector ();
185  $$->add ($1);
186  $$->add ($2);
187  }
188 ;
189 
190 %%
191 
192 int touchstone_error (const char * error) {
193  logprint (LOG_ERROR, "line %d: %s\n", touchstone_lineno, error);
194  return 0;
195 }
void add(char *)
Definition: strlist.cpp:65
name
Definition: parse_mdl.y:352
int touchstone_lineno
qucs::strlist * touchstone_idents
qucs::vector * touchstone_vector
char * ident
Definition: netdefs.h:42
free($1)
name prefix
Eol OptionLine
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
logprint(LOG_ERROR,"line %d: no trailing end-of-line found, ""continuing...\n", touchstone_lineno)
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
__BEGIN_DECLS struct touchstone_t touchstone_options
v
Definition: parse_zvr.y:141
DataLine
#define LOG_ERROR
Definition: logging.h:28
int touchstone_error(const char *)
Float Float Float Float Float
Eol Dataset