48 #include "tokens_netlist.h"
52 # define strrchr rindex
59 while (isspace (scale[0])) scale++;
61 case 'E': factor = 1e+18;
break;
62 case 'P': factor = 1e+15;
break;
63 case 'T': factor = 1e+12;
break;
64 case 'G': factor = 1e+09;
break;
65 case 'M': factor = 1e+06;
break;
66 case 'k': factor = 1e+03;
break;
68 if (scale[1] ==
'i' && scale[2] ==
'l')
73 case 'u': factor = 1e-06;
break;
74 case 'n': factor = 1e-09;
break;
75 case 'p': factor = 1e-12;
break;
82 case 'a': factor = 1e-18;
break;
84 if (scale[1] ==
'B') {
88 else if (scale[2] ==
'u')
107 SIMPLEID [a-zA-
Z_][a-zA-
Z0-9_]*
108 POSTID
"."[a-zA-
Z0-9_]+
109 ID {SIMPLEID}{POSTID}*
115 EXPONENT [Ee][+-]?{DIGIT}+
116 PFX1 ("E"|"P
"|"T
"|"G
"|"M"|"k
"|"m
"|"u
"|"n"|"p
"|"f
"|"a
")
117 PFX2 ("mil
"|"in
"|"ft
"|"yd
")
118 PFX3 ("dBu
"|"dBm
"|"dB")
120 UNT ("Ohm
"|"S"|"s"|"K"|"H
"|"F
"|"Hz
"|"V"|"A"|"W
"|"m
")
122 SU ({PFX}|{UNT}|{PFX}{UNT}|{EXCEPT})
125 IINT [+-]?[ij]{1}{DIGIT}*
126 RFLOAT1 [+-]?{DIGIT}+{EXPONENT}
127 RFLOAT2 [+-]?{DIGIT}*".
"{DIGIT}+({EXPONENT})?
128 IFLOAT1 [+-]?[ij]{1}{DIGIT}+{EXPONENT}
129 IFLOAT2 [+-]?[ij]{1}{DIGIT}*".
"{DIGIT}+({EXPONENT})?
130 CREAL ({RFLOAT1}|{RFLOAT2}|{RINT})
131 CIMAG ({IFLOAT1}|{IFLOAT2}|{IINT})
132 COMPLEX {CREAL}{CIMAG}
134 UIINT [ij]{1}{DIGIT}*
135 URFLOAT1 {DIGIT}+{EXPONENT}
136 URFLOAT2 {DIGIT}*".
"{DIGIT}+({EXPONENT})?
137 UIFLOAT1 [ij]{1}{DIGIT}+{EXPONENT}
138 UIFLOAT2 [ij]{1}{DIGIT}*".
"{DIGIT}+({EXPONENT})?
139 UCREAL ({URFLOAT1}|{URFLOAT2}|{URINT})({SPACE})*({PFX})?
140 UCIMAG ({UIFLOAT1}|{UIFLOAT2}|{UIINT})({SPACE})*({PFX})?
141 UCOMPLEX {UCREAL}{UCIMAG}
145 %option yylineno noyywrap nounput prefix="netlist_
"
149 <INITIAL,STR>{SU} { /* identify scale and/or unit */
150 netlist_lval.str = strdup (netlist_text);
153 <INITIAL>"Eqn
" { /* special equation case */
157 <INITIAL>".
"{SPACE}*"Def
"{SPACE}*":
" {
158 /* subcircuit definition begins */
161 <INITIAL>".
"{SPACE}*"Def
"{SPACE}*":
"{SPACE}*"End
" {
162 /* subcircuit definition ends */
165 <INITIAL,STR>{ID} { /* identify identifier */
166 netlist_lval.ident = strdup (netlist_text);
169 <INITIAL>{NODE} { /* identify node identifier */
170 netlist_lval.ident = strdup (netlist_text);
173 <INITIAL,STR>{FILE} { /* identify file reference */
174 char * p = strrchr (netlist_text, '}'); *p = '\0';
175 netlist_lval.ident = strdup (&netlist_text[1]);
178 <INITIAL,STR>{CREAL} { /* identify (signed) real float */
179 netlist_lval.d = strtod (netlist_text, NULL);
182 <INITIAL,STR>{CIMAG} { /* identify (signed) imaginary float */
183 if (netlist_text[0] == 'i' || netlist_text[0] == 'j')
184 netlist_text[0] = (netlist_text[1] == '\0') ? '1' : '0';
186 netlist_text[1] = '0';
187 netlist_lval.d = strtod (netlist_text, NULL);
190 <INITIAL,STR>{COMPLEX} { /* identify complete (signed) complex number */
192 while (netlist_text[i] != 'i' && netlist_text[i] != 'j') i++;
193 netlist_text[i] = netlist_text[i - 1];
194 netlist_text[i - 1] = '\0';
195 netlist_lval.c.r = strtod (netlist_text, NULL);
196 netlist_lval.c.i = strtod (&netlist_text[i], NULL);
199 <INITIAL,EQN>{ID}{SPACE}*=[^=] { /* identify 'identifier =' assign */
200 int len = netlist_leng - 3;
201 while (isspace (netlist_text[len])) len--;
202 netlist_lval.ident = (char *) calloc (len + 2, 1);
203 memcpy (netlist_lval.ident, netlist_text, len + 1);
204 yyless (netlist_leng - 1); /* push back last character */
208 <INITIAL,STR>"[
" { /* special token for the value list */ return '['; }
209 <INITIAL,STR>"]
" { /* special token for the value list */ return ']'; }
210 <INITIAL,STR>";
" { /* special token for the value list */ return ';'; }
212 <INITIAL>".
" { /* pass the '.' to the parser */ return '.'; }
213 <INITIAL>":
" { /* pass the ':' to the parser */ return ':'; }
214 <INITIAL>"=
" { /* pass the '=' to the parser */ return '='; }
215 <INITIAL>\r?\n { /* detect end of line */ return Eol; }
217 <INITIAL,EQN>{SPACE}|\\\r?\n /* skip spaces and the trailing '\' */
219 <INITIAL>"#
" { /* leave these characters */
222 <INITIAL>\" { /* string constant starts here */
226 <INITIAL>. { /* any other character in invalid */
228 "line %d: syntax error, unrecognized character: `%s'\n",
229 netlist_lineno, netlist_text);
230 return InvalidCharacter;
233 <COMMENT>. { /* skip any character in here */ }
234 <COMMENT>\r?\n { BEGIN(INITIAL); /* skipping ends here */ }
236 <STR>\" { /* string constant ends here */
240 <STR>\r?\n { /* string in a single line only */
242 "line %d: syntax error, unterminated string constant\n",
246 <STR,EQN>{SPACE} /* skip spaces */
248 <STR>. { /* any other character is invalid */
250 "line %d: syntax error, unrecognized character: `%s'\n",
251 netlist_lineno, netlist_text);
252 return InvalidCharacter;
255 <EQN>[-+*/%(),^:\"\[\]\?] { /* return operators unchanged */
256 return netlist_text[0];
259 <EQN>">=
" { return GreaterOrEqual; }
260 <EQN>"<=
" { return LessOrEqual; }
261 <EQN>"!=
" { return NotEqual; }
262 <EQN>"==
" { return Equal; }
263 <EQN>"&&
" { return And; }
264 <EQN>"||
" { return Or; }
265 <EQN>"<
" { return Less; }
266 <EQN>">
" { return Greater; }
267 <EQN>"!
" { return Not; }
269 <EQN>[,;] { /* special tokens for vectors / matrices */
270 return netlist_text[0];
273 <EQN>{UCREAL} { /* identify unsigned real float */
274 char * endptr = NULL;
275 netlist_lval.d = strtod (netlist_text, &endptr);
276 netlist_lval.d = netlist_evaluate_scale (netlist_lval.d, endptr);
279 <EQN>{UCIMAG} { /* identify unsigned imaginary float */
280 if (netlist_text[0] == 'i' || netlist_text[0] == 'j')
281 netlist_text[0] = (netlist_text[1] == '\0') ? '1' : '0';
283 netlist_text[1] = '0';
284 char * endptr = NULL;
285 netlist_lval.d = strtod (netlist_text, &endptr);
286 netlist_lval.d = netlist_evaluate_scale (netlist_lval.d, endptr);
289 <EQN>{ID} { /* identify identifier */
290 netlist_lval.ident = strdup (netlist_text);
294 netlist_lval.chr = netlist_text[1];
298 netlist_lval.str = strdup (&netlist_text[1]);
299 netlist_lval.str[strlen (netlist_lval.str) - 1] = '\0';
302 <EQN>\r?\n { /* detect end of line */ BEGIN(INITIAL); return Eol; }
304 <EQN>. { /* any other character in invalid */
306 "line %
d: syntax error, unrecognized character: `%
s'\n",
307 netlist_lineno, netlist_text);
308 return InvalidCharacter;
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
#define K
Absolute 0 in centigrade.
nr_double_t dB(const nr_complex_t z)
Magnitude in dB Compute .
static double netlist_evaluate_scale(double val, char *scale)
WS[\t\n\r] SIMPLEID *[a-zA-Z_][a-zA-Z0-9_] POSTID[a-zA-Z0-9_] ID
#define Z0
Wave impedance in vacuum ( )