Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scan_dataset.l
Go to the documentation of this file.
1 /* -*-c-*- */
2 
3 %{
4 /*
5  * scan_dataset.l - scanner for the Qucs dataset
6  *
7  * Copyright (C) 2003, 2004, 2005, 2006, 2008 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 #ifdef __MINGW32__
38 #include <io.h>
39 #endif
40 
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44 
45 #include "logging.h"
46 #include "complex.h"
47 #include "object.h"
48 #include "vector.h"
49 #include "dataset.h"
50 #include "check_dataset.h"
51 #include "tokens_dataset.h"
52 
53 using namespace qucs;
54 
55 %}
56 
57 WS [ \t\n\r]
58 IDENT1 [a-zA-Z_][a-zA-Z0-9_]*
59 IDENT2 [a-zA-Z_][a-zA-Z0-9_\[\],]*
60 IDENT3 [a-zA-Z0-9_][a-zA-Z0-9_]*
61 IDENT {IDENT1}|{IDENT2}
62 PIDENT {IDENT1}|{IDENT2}|{IDENT3}
63 SIMPLEID {IDENT}
64 POSTID "."{PIDENT}
65 ID {SIMPLEID}{POSTID}*
66 DIGIT [0-9]
67 EXPONENT [Ee][+-]?{DIGIT}+
68 RINT [+-]?{DIGIT}+
69 IINT [+-]?[ij]{1}{DIGIT}+
70 RFLOAT1 [+-]?{DIGIT}+{EXPONENT}
71 RFLOAT2 [+-]?{DIGIT}*"."{DIGIT}+({EXPONENT})?
72 IFLOAT1 [+-]?[ij]{1}{DIGIT}+{EXPONENT}
73 IFLOAT2 [+-]?[ij]{1}{DIGIT}*"."{DIGIT}+({EXPONENT})?
74 CREAL ({RFLOAT1}|{RFLOAT2}|{RINT})
75 CIMAG ({IFLOAT1}|{IFLOAT2}|{IINT})
76 COMPLEX {CREAL}{CIMAG}
77 SPACE [ \t]
78 VERSION "<Qucs Dataset "{DIGIT}+"."{DIGIT}+"."{DIGIT}+">"
79 DBEGIN "dep"
80 IBEGIN "indep"
81 DEND "/dep"
82 IEND "/indep"
83 
84 
85 %x COMMENT DESCRIPTION
86 %option yylineno noyywrap nounput prefix="dataset_"
87 
88 %%
89 
90 <INITIAL>{VERSION} {
91  return Version;
92  }
93 
94 <DESCRIPTION>{DBEGIN} {
95  return DepBegin;
96  }
97 
98 <DESCRIPTION>{IBEGIN} {
99  return IndepBegin;
100  }
101 
102 <DESCRIPTION>{DEND} {
103  return DepEnd;
104  }
105 
106 <DESCRIPTION>{IEND} {
107  return IndepEnd;
108  }
109 
110 <INITIAL,DESCRIPTION>{ID} { /* identify identifier */
111  dataset_lval.ident = strdup (dataset_text);
112  return Identifier;
113  }
114 
115 <INITIAL>{CREAL} { /* identify real float */
116  dataset_lval.f = strtod (dataset_text, NULL);
117  return REAL;
118  }
119 
120 <INITIAL>{CIMAG} { /* identify imaginary float */
121  if (dataset_text[0] == 'i' || dataset_text[0] == 'j')
122  dataset_text[0] = '0';
123  else
124  dataset_text[1] = '0';
125  dataset_lval.f = strtod (dataset_text, NULL);
126  return IMAG;
127  }
128 
129 <INITIAL>{COMPLEX} { /* identify complete complex number */
130  int i = 0;
131  while (dataset_text[i] != 'i' && dataset_text[i] != 'j') i++;
132  dataset_text[i] = dataset_text[i - 1];
133  dataset_text[i - 1] = '\0';
134  dataset_lval.c.r = strtod (dataset_text, NULL);
135  dataset_lval.c.i = strtod (&dataset_text[i], NULL);
136  return COMPLEX;
137  }
138 
139 <DESCRIPTION>{RINT} { /* identify integer */
140  dataset_lval.n = strtol (dataset_text, NULL, 10);
141  return Integer;
142  }
143 
144 <INITIAL>"<" { /* pass the '<' to the parser */
145  BEGIN(DESCRIPTION);
146  return '<';
147  }
148 <DESCRIPTION>">" { /* pass the '>' to the parser */
149  BEGIN(INITIAL);
150  return '>';
151  }
152 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
153 
154 <*>{SPACE}|\\\r?\n /* skip spaces and the trailing '\' */
155 
156 <INITIAL>"#" { /* leave these characters */
157  BEGIN(COMMENT);
158  }
159 <INITIAL,DESCRIPTION>. { /* any other character in invalid */
161  "line %d: syntax error, unrecognized character: `%s'\n",
162  dataset_lineno, dataset_text);
163  return InvalidCharacter;
164  }
165 
166 <COMMENT>. { /* skip any character in here */ }
167 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ }
168 
169 %%
Identifier
Definition: parse_csv.y:87
t
Definition: parse_vcd.y:290
int dataset_lineno
n
Definition: parse_citi.y:147
r
Definition: parse_mdl.y:515
i
Definition: parse_mdl.y:516
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
IMAG
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
#define Z_(r, c)
Definition: hbsolver.cpp:689
x
Definition: parse_mdl.y:498
name prefix
Definition: parse_spice.y:131
WS[\t\n\r] SIMPLEID *[a-zA-Z_][a-zA-Z0-9_] POSTID[a-zA-Z0-9_] ID
Definition: scan_netlist.l:581
#define LOG_ERROR
Definition: logging.h:28
void logprint(int level, const char *format,...)
Definition: logging.c:37
#define Z0
Wave impedance in vacuum ( )
Definition: constants.h:53
REAL
Definition: parse_vcd.y:236