46 #include "tokens_spice.h"
50 # define strrchr rindex
54 static void spice_fix_identifier (
char *
ident) {
56 for (p = ident; *p !=
'\0'; p++)
58 case '+': *p =
'P';
break;
59 case '-': *p =
'N';
break;
60 case '/': *p =
'_';
break;
67 TITLE [* \t0-9
A-Za-z][
A-Za-z0-9\-
\t;#:=()/\.,*\\]*\
r*\
n
70 IDENT [
A-Za-z_][
A-Za-z0-9_\-/]*
71 IDENT2 [
A-Za-z0-9_][
A-Za-z0-9_\-/]*
72 FILE [/
A-Za-z0-9_][/\\:
A-Za-z0-9_\.]*
74 EXPONENT [Ee][+-]?{DIGIT}+
76 FLOAT1 [+-]?{DIGIT}+{EXPONENT}
77 FLOAT2 [+-]?{DIGIT}*
"."{DIGIT}+({EXPONENT})?
78 FLOAT3 [+-]?{DIGIT}+
"."
79 NUMBER ({
INT}|{FLOAT1}|{FLOAT2}|{FLOAT3}){SFX}?{UNIT}?
80 SFX ([tT]|[gG]|[mM]|[kK]|[uU]|[nN]|[pP]|[fF]|[mM][iI][lL]|[mM][eE][gG])
81 UNIT ([sS]|[vV]|[aA]|[oO][hH][mM]|[mM][hH][oO]|[fF]|[hH])
82 NODE ([
A-Za-z0-9_
#\+-]+|[\+]|[-])
87 FUN1 ([dD][eE][cC]|[lL][iI][nN]|[oO][cC][tT]|[dD][cC]|[aA][cC])
88 FUN2 ([sS][iI][nN]|[pP][uU][lL][sS][eE]|[pP][wW][lL]|[eE][xX][pP])
89 FUN3 ([dD][iI][sS][tT][oO][fF][12])
90 FUNCTION ({FUN1}|{FUN2}|{FUN3})
93 MODEL1 ([rR]|[cC]|[sS][wW]|[cC][sS][wW]|[uU][rR][cC]|[lL][tT][rR][aA])
94 MODEL2 ([dD]|[nN][pP][nN]|[pP][nN][pP]|[nN][jJ][fF]|[pP][jJ][fF])
95 MODEL3 ([nN][mM][oO][sS]|[pP][mM][oO][sS]|[nN][mM][fF]|[pP][mM][fF])
96 MODEL4 ([rR][eE][sS]|[vV][sS][wW][iI][tT][cC][hH])
97 MODEL ({MODEL1}|{MODEL2}|{MODEL3}|{MODEL4})
100 VFUN ([vV]|[vV][rR]|[vV][iI]|[vV][mM]|[vV][pP]|[vV][dD][bB])
103 OPT1 ([aA][cC][cC][tT]|[lL][iI][sS][tT]|[nN][oO][mM][oO][dD])
104 OPT2 ([nN][oO][pP][aA][gG][eE]|[nN][oO][dD][eE]|[oO][pP][tT][sS])
105 OPT3 ([tT][rR][yY][tT][oO][cC][oO][mM][pP][aA][cC][tT])
106 OPT4 ([kK][eE][eE][pP][oO][pP][iI][nN][fF][oO]|[bB][aA][dD][mM][oO][sS]3)
107 OPT5 ([pP][oO][sS][tT]|[tT][rR][aA][nN][sS])
108 OPTS ({OPT1}|{OPT2}|{OPT3}|{OPT4}|{OPT5})
111 MOD1 ([nN][oO][cC][oO][nN][tT][rR][oO][lL])
112 MOD2 ([sS][tT][eT][pP][lL][iI][mM][iI][tT])
113 MOD3 ([qQ][uU][aA][dD][iI][nN][tT][eE][rR][pP])
114 MOD4 ([nN][oO][pP][rR][iI][nN][tT])
115 MODS ({MOD1}|{MOD2}|{MOD3}|{MOD4})
118 SIM1 ([aA][cC]|[dD][cC]|[tT][rR][aA][nN]|[nN][oO][iI][sS][eE])
119 SIM2 ([dD][iI][sS][tT][oO]|[pP][zZ])
123 MOS1 ([lL]|[wW]|[aA][dDsS]|[pP][dDsS]|[nN][rR][dDsS]|[dD][eE][bB][uU][gG])
124 MOS2 ([rR][gG][eE][oO][mM][oO][dD]|[tT][sSdD]|[mM])
128 TABLE [tT][aA][bB][lL][eE]
129 VALUE [vV][aA][lL][uU][eE]
130 FREQ [fF][rR][eE][qQ]
131 LAPLACE [lL][aA][pP][lL][aA][cC][eE]
132 POLY [pP][oO][lL][yY]
134 %
x COMMENT IVREF DEVPROP LREF MODREF1 MODREF2 IGNORE FUNREF FILEREF VREF
135 %
x STARTUP VSINGLE ISWITCH VSWITCH CONTROL GEVALS INLINE SUBCKT TLPROP RLCPROP
137 %option yylineno noyywrap nounput
prefix=
"spice_"
142 spice_lval.str = strdup (spice_text);
147 <STARTUP,INITIAL>^{SPACE}+ {
151 <STARTUP,INITIAL>^
"*" {
155 <STARTUP,INITIAL,IVREF,DEVPROP,LREF,MODREF1,MODREF2,IGNORE,FUNREF,
156 FILEREF,VREF,VSINGLE,ISWITCH,VSWITCH,CONTROL,GEVALS,INLINE,SUBCKT,
157 TLPROP,RLCPROP,FHVALS>[\*\$] {
162 <STARTUP,INITIAL>^
"."[cC][oO][nN][tT][rR][oO][lL] {
170 <CONTROL>^
"."[eE][nN][dD][cC] {
174 <STARTUP,INITIAL>\x1a {
178 <STARTUP,INITIAL>^
"."[sS][uU][bB][cC][kK][tT] {
180 spice_lval.ident = strdup (&spice_text[1]);
182 return SUBCKT_Action;
185 <STARTUP>^
"."[eE][nN][dD][sS] {
190 <STARTUP,INITIAL>^[rRlLcC]{CSFX} {
191 spice_lval.ident = strdup (spice_text);
196 <STARTUP,INITIAL>^[kK]{CSFX} {
197 spice_lval.ident = strdup (spice_text);
202 <STARTUP,INITIAL>^[iIvV]{CSFX} {
204 spice_lval.ident = strdup (spice_text);
209 <STARTUP,INITIAL>^[gGeE]{CSFX} {
211 spice_lval.ident = strdup (spice_text);
216 <STARTUP,INITIAL>^[fFhH]{CSFX} {
218 spice_lval.ident = strdup (spice_text);
223 <STARTUP,INITIAL>^[bB]{CSFX} {
225 spice_lval.ident = strdup (spice_text);
230 <STARTUP,INITIAL>^[xX]{CSFX} {
231 spice_lval.ident = strdup (spice_text);
236 <STARTUP,INITIAL>^[oO]{CSFX} {
237 spice_lval.ident = strdup (spice_text);
242 <STARTUP,INITIAL>^[tT]{CSFX} {
243 spice_lval.ident = strdup (spice_text);
248 <STARTUP,INITIAL>^[uU]{CSFX} {
249 spice_lval.ident = strdup (spice_text);
254 <STARTUP,INITIAL>^[sS]{CSFX} {
255 spice_lval.ident = strdup (spice_text);
260 <STARTUP,INITIAL>^[wW]{CSFX} {
261 spice_lval.ident = strdup (spice_text);
266 <STARTUP,INITIAL>^
"."[mM][oO][dD][eE][lL] {
267 spice_lval.ident = strdup (&spice_text[1]);
272 <STARTUP,INITIAL>^
"."[tT][rR][aA][nN] {
273 spice_lval.ident = strdup (&spice_text[1]);
278 <STARTUP,INITIAL>^
"."[pP][lL][oO][tT] {
279 spice_lval.ident = strdup (&spice_text[1]);
284 <STARTUP,INITIAL>^
"."[aA][cC] {
285 spice_lval.ident = strdup (&spice_text[1]);
290 <STARTUP,INITIAL>^
"."[dD][iI][sS][tT][oO] {
291 spice_lval.ident = strdup (&spice_text[1]);
296 <STARTUP,INITIAL>^
"."[nN][oO][dD][eE][sS][eE][tT] {
297 spice_lval.ident = strdup (&spice_text[1]);
299 return NODESET_Action;
302 <STARTUP,INITIAL>^
"."[iI][cC] {
303 spice_lval.ident = strdup (&spice_text[1]);
305 return NODESET_Action;
308 <STARTUP,INITIAL>^
"."[dD][cC] {
309 spice_lval.ident = strdup (&spice_text[1]);
314 <STARTUP,INITIAL>^
"."[oO][pP] {
315 spice_lval.ident = strdup (&spice_text[1]);
320 <STARTUP,INITIAL>^
"."[tT][eE][mM][pP] {
321 spice_lval.ident = strdup (&spice_text[1]);
326 <STARTUP,INITIAL>^
"."[pP][rR][iI][nN][tT] {
327 spice_lval.ident = strdup (&spice_text[1]);
332 <STARTUP,INITIAL>^
"."[oO][pP][tT][iI][oO][nN][sS] {
333 spice_lval.ident = strdup (&spice_text[1]);
335 return OPTIONS_Action;
338 <STARTUP,INITIAL>^
"."[oO][pP][tT] {
339 spice_lval.ident = strdup (&spice_text[1]);
341 return OPTIONS_Action;
344 <STARTUP,INITIAL>^
"."[oO][pP][tT][iI][oO][nN] {
345 spice_lval.ident = strdup (&spice_text[1]);
347 return OPTIONS_Action;
350 <STARTUP,INITIAL>^
"."[wW][iI][dD][tT][hH] {
351 spice_lval.ident = strdup (&spice_text[1]);
356 <STARTUP,INITIAL>^
"."[nN][oO][iI][sS][eE] {
357 spice_lval.ident = strdup (&spice_text[1]);
362 <STARTUP,INITIAL>^
"."[iI][nN][cC][lL][uU][dD][eE] {
363 spice_lval.ident = strdup (&spice_text[1]);
365 return INCLUDE_Action;
368 <STARTUP,INITIAL>^
"."[pP][zZ] {
369 spice_lval.ident = strdup (&spice_text[1]);
374 <STARTUP,INITIAL>^
"."[sS][aA][vV][eE] {
375 spice_lval.ident = strdup (&spice_text[1]);
380 <STARTUP,INITIAL>^
"."[sS][eE][nN][sS] {
381 spice_lval.ident = strdup (&spice_text[1]);
386 <STARTUP,INITIAL>^
"."[tT][fF] {
387 spice_lval.ident = strdup (&spice_text[1]);
392 <STARTUP,INITIAL>^
"."[fF][oO][uU][rR] {
393 spice_lval.ident = strdup (&spice_text[1]);
398 <STARTUP>[cC][uU][rR]|[vV][oO][lL] {
399 spice_lval.ident = strdup (spice_text);
403 <STARTUP>[pP][oO][lL]|[zZ][eE][rR]|[pP][zZ] {
404 spice_lval.ident = strdup (spice_text);
409 spice_lval.ident = strdup (spice_text);
413 <IVREF,VREF>[aA][lL][lL] {
414 spice_lval.ident = strdup (spice_text);
419 spice_lval.ident = strdup (spice_text);
423 <DEVPROP,VSWITCH,ISWITCH>[oO][fF][fF] {
424 spice_lval.ident = strdup (spice_text);
428 <VSWITCH,ISWITCH>[oO][nN] {
429 spice_lval.ident = strdup (spice_text);
433 <TLPROP,DEVPROP>[iI][cC] {
434 spice_lval.ident = strdup (spice_text);
438 <DEVPROP>[tT][eE][mM][pP] {
439 spice_lval.ident = strdup (spice_text);
444 spice_lval.ident = strdup (spice_text);
449 spice_lval.ident = strdup (spice_text);
454 spice_lval.ident = strdup (spice_text);
459 spice_lval.ident = strdup (spice_text);
464 spice_lval.ident = strdup (spice_text);
468 <IVREF,VREF,ISWITCH,FHVALS>[vV]{CSFX} {
469 spice_lval.ident = strdup (spice_text);
474 spice_lval.ident = strdup (spice_text);
479 spice_lval.ident = strdup (spice_text);
484 spice_lval.ident = strdup (spice_text);
489 spice_lval.ident = strdup (spice_text);
493 <STARTUP>^[dD]{CSFX} {
494 spice_lval.ident = strdup (spice_text);
499 <STARTUP>^[qQ]{CSFX} {
500 spice_lval.ident = strdup (spice_text);
502 return Bipolar_Device;
505 <STARTUP>^[jJ]{CSFX} {
506 spice_lval.ident = strdup (spice_text);
511 <STARTUP>^[mM]{CSFX} {
512 spice_lval.ident = strdup (spice_text);
514 return MOSFET_Device;
517 <STARTUP>^[zZ]{CSFX} {
518 spice_lval.ident = strdup (spice_text);
520 return MESFET_Device;
523 <STARTUP,INITIAL>
"."[Ee][Nn][Dd]{SPACE}*{EOL}* {
527 <STARTUP,IVREF,DEVPROP,LREF,FUNREF,VREF,VSINGLE,ISWITCH,VSWITCH,
528 GEVALS,TLPROP,RLCPROP,FHVALS>{DIGIT}+ {
530 spice_lval.ident = strdup (spice_text);
534 <STARTUP,IVREF,DEVPROP,LREF,FUNREF,VREF,VSINGLE,GEVALS,TLPROP,
535 RLCPROP,FHVALS>{NUMBER} {
537 spice_lval.ident = strdup (spice_text);
541 <GEVALS,FHVALS,RLCPROP>{POLY} {
543 spice_lval.ident = strdup (spice_text);
547 <GEVALS,FHVALS>{
TABLE}|{VALUE}|{FREQ}|{LAPLACE} {
549 spice_lval.ident = strdup (spice_text);
554 <IVREF,FUNREF>{FUNCTION} {
555 spice_lval.ident = strdup (spice_text);
560 spice_lval.ident = strdup (spice_text);
565 <STARTUP,DEVPROP,MODREF2,ISWITCH,VSWITCH,
566 TLPROP,RLCPROP>{IDENT} {
567 spice_lval.ident = strdup (spice_text);
568 spice_fix_identifier (spice_lval.ident);
573 spice_lval.ident = strdup (spice_text);
574 spice_fix_identifier (spice_lval.ident);
580 spice_lval.ident = strdup (spice_text);
581 spice_fix_identifier (spice_lval.ident);
586 <IVREF,VREF>[vV]{CSFX}#[bB][rR][aA][nN][cC][hH] {
588 spice_lval.ident = strdup (spice_text);
592 <IVREF,VREF>@[a-zA-Z]{CSFX}\[[a-zA-Z]{CSFX}\] {
594 spice_lval.ident = strdup (spice_text);
598 <STARTUP,IVREF,DEVPROP,FUNREF,VREF,VSINGLE,ISWITCH,VSWITCH,GEVALS,
599 TLPROP,RLCPROP,FHVALS>{NODE} {
601 spice_lval.ident = strdup (spice_text);
605 <STARTUP,IVREF,DEVPROP,LREF,IGNORE,FUNREF,FILEREF,VREF,VSINGLE,
606 ISWITCH,VSWITCH,GEVALS,SUBCKT,TLPROP,RLCPROP,FHVALS>{EOL} {
612 <*>{SPACE}|{EOL}+\+|[()=,] {
616 <COMMENT>{EOL} { BEGIN(STARTUP); }
620 <INLINE>{EOL} { BEGIN(STARTUP);
return Eol; }
626 "line %d: syntax error, unrecognized character: `%s'\n",
RLC_Device Node Node Value MODEL_Ident PairList Eol
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
#define Z0
Wave impedance in vacuum ( )