Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_dataset.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_dataset.y - parser for the Qucs dataset
6  *
7  * Copyright (C) 2003, 2004, 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 10000000
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_dataset.h"
47 
48 using namespace qucs;
49 
50 %}
51 
52 %name-prefix="dataset_"
53 
54 %token InvalidCharacter
55 %token Identifier
56 %token REAL
57 %token IMAG
58 %token COMPLEX
59 %token Integer
60 %token Eol
61 %token IndepBegin
62 %token DepBegin
63 %token IndepEnd
64 %token DepEnd
65 %token Version
66 
67 %union {
68  char * ident;
69  double f;
70  struct {
71  double r;
72  double i;
73  } c;
74  long n;
75  qucs::vector * v;
77  qucs::strlist * list;
78 }
79 
80 %type <list> IdentifierList
81 %type <ident> Identifier
82 %type <f> REAL IMAG
83 %type <c> COMPLEX
84 %type <n> Integer
85 %type <v> FloatList
86 %type <data> VersionLine VariableList Variable
87 
88 %%
89 
90 Input:
91  VersionLine VariableList { /* describes a valid dataset */ }
92 ;
93 
94 VersionLine:
95  Version Eol { /* version line */
96  $$ = dataset_result = new dataset ();
97  }
98 ;
99 
100 VariableList: /* nothing */ { }
101  | Variable VariableList { /* dependent and independent variable vectors */ }
102  | Eol VariableList { /* skip to next line */ }
103 ;
104 
105 Variable:
106  '<' DepBegin Identifier IdentifierList '>' FloatList '<' DepEnd '>' {
107  /* dependent variable vector */
111  dataset_result->appendVariable (dataset_vector);
114  free ($3);
115  }
116  | '<' IndepBegin Identifier Integer '>' FloatList '<' IndepEnd '>' {
117  /* independent variable vector */
119  dataset_vector->setName ($3);
121  dataset_result->appendDependency (dataset_vector);
122  dataset_vector = NULL;
123  free ($3);
124  }
125 ;
126 
127 FloatList: /* nothing */ { $$ = dataset_vector = new vector (); }
129  dataset_vector->add ($1);
130  }
131  | COMPLEX FloatList {
132  dataset_vector->add (nr_complex_t ($1.r, $1.i));
133  }
134  | IMAG FloatList {
135  dataset_vector->add (nr_complex_t (0.0, $1));
136  }
137  | Eol FloatList { /* skip to next line */ }
138 ;
139 
140 IdentifierList: /* nothing */ { $$ = dataset_idents = new strlist (); }
142  dataset_idents->add ($1);
143  free ($1);
144  }
145 ;
146 
147 %%
148 
149 int dataset_error (const char * error) {
150  logprint (LOG_ERROR, "line %d: %s\n", dataset_lineno, error);
151  return 0;
152 }
void add(char *)
Definition: strlist.cpp:65
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
int dataset_lineno
name
Definition: parse_mdl.y:352
void reverse(void)
Definition: vector.cpp:903
Identifier
Definition: parse_csv.y:87
REAL FloatList
n
Definition: parse_citi.y:147
r
Definition: parse_mdl.y:515
void setDependencies(strlist *)
Definition: vector.cpp:143
i
Definition: parse_mdl.y:516
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
IMAG
void setName(const char *)
Definition: object.cpp:78
dataset * dataset_result
void setRequested(int n)
Definition: parse_citi.y:66
void add(nr_complex_t)
Definition: vector.cpp:151
name prefix
Definition: parse_dataset.y:52
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
qucs::vector * dataset_vector
int dataset_error(const char *)
qucs::strlist * dataset_idents
v
Definition: parse_zvr.y:141
free($3)
Identifier IdentifierList
vcd scopes ident
Definition: parse_vcd.y:124
#define LOG_ERROR
Definition: logging.h:28
void logprint(int level, const char *format,...)
Definition: logging.c:37
REAL
Definition: parse_vcd.y:236
data
Definition: parse_citi.y:117