Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parse_spice.y
Go to the documentation of this file.
1 /* -*-c++-*- */
2 
3 %{
4 /*
5  * parse_spice.y - parser for a Spice netlist
6  *
7  * Copyright (C) 2004, 2005, 2006, 2007, 2009 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 #if defined(_WIN32) & not defined(__MINGW32__)
38 #define strcasecmp stricmp
39 #endif
40 
41 #define YYERROR_VERBOSE 42
42 #define YYDEBUG 1
43 #define YYMAXDEPTH 1000000
44 
45 #include "check_spice.h"
46 
47 // Converts the given string into upper case.
48 static char * spice_toupper (char * str) {
49  for (unsigned int i = 0; i < strlen (str); i++) {
50  if (str[i] >= 'a' && str[i] <= 'z') str[i] = toupper (str[i]);
51  }
52  return str;
53 }
54 
55 // Creates a device instance.
56 static struct definition_t * spice_create_device (char * instance) {
57  struct definition_t * def = create_definition ();
58  def->action = PROP_COMPONENT;
59  def->instance = spice_toupper (instance);
60  def->type = (char *) calloc (2, 1);
61  def->type[0] = def->instance[0];
62  def->line = spice_lineno;
63  return def;
64 }
65 
66 // Creates an action instance.
67 static struct definition_t * spice_create_action (char * type,
68  char * instance) {
69  struct definition_t * def = create_definition ();
70  def->action = PROP_ACTION;
71  def->instance = spice_toupper (instance);
72  def->type = spice_toupper (type);
73  def->line = spice_lineno;
74  return def;
75 }
76 
77 // Create a string value.
78 static struct value_t * spice_create_str_value (char * value, int hint) {
79  struct value_t * val = create_value ();
80  val->ident = spice_toupper (value);
81  val->hint |= hint;
82  return val;
83 }
84 
85 // Create a real value.
86 static struct value_t * spice_create_val_value (char * value, int hint) {
87  struct value_t * val = create_value ();
88  val->ident = value;
89  val->value = strtod (value, NULL);
90  val->hint |= hint;
91  return val;
92 }
93 
94 // Create a key/value pair.
95 static struct value_t * spice_create_par_value (char * key, char * value) {
96  struct value_t * val = spice_create_str_value (key, HINT_PAIR);
97  val->unit = value;
98  return val;
99 }
100 
101 // Append a string value to the definition.
102 static void spice_append_str_value (struct definition_t * def,
103  char * value, int hint) {
104  struct value_t * val = spice_create_str_value (value, hint);
105  def->values = netlist_append_values (def->values, val);
106 }
107 
108 // Append a string value to the given values.
109 static struct value_t * spice_append_str_values (struct value_t * values,
110  char * value, int hint) {
111  struct value_t * val = spice_create_str_value (value, hint);
112  return netlist_append_values (values, val);
113 }
114 
115 // Append a real value to the definition.
116 static void spice_append_val_value (struct definition_t * def,
117  char * value, int hint) {
118  struct value_t * val = spice_create_val_value (value, hint);
119  def->values = netlist_append_values (def->values, val);
120 }
121 
122 // Append a real value to the given values.
123 static struct value_t * spice_append_val_values (struct value_t * values,
124  char * value, int hint) {
125  struct value_t * val = spice_create_val_value (value, hint);
126  return netlist_append_values (values, val);
127 }
128 
129 %}
130 
131 %name-prefix="spice_"
132 
133 %token TitleLine InvalidCharacter End Eol
134 %token Identifier Digits Floats Nodes Options Function
135 %token SUBCKT_Action ENDS_Action AC_Action OP_Action I_Source SAVE_Action
136 %token RLC_Device L_Device K_Device IV_Source GE_Source FH_Source V_Source
137 %token Diode_Device Bipolar_Device JFET_Device MOSFET_Device MESFET_Device
138 %token MODEL_Action MODEL_Spec TRAN_Action PLOT_Action VoltFunc CurrFunc
139 %token DC_Action PRINT_Action OPTIONS_Action WIDTH_Action NOISE_Action
140 %token PZ_Action CurVol PoleZero ALL_Special X_Device O_Device ModelProps
141 %token OFF_Special IC_Special SIM_Type TEMP_Special MOS_Special B_Source
142 %token DISTO_Action INCLUDE_Action File BranchFunc NODESET_Action T_Device
143 %token U_Device S_Device W_Device ON_Special TF_Action SENS_Action FOUR_Action
144 %token OpFunc Behave TC_Special TEMP_Action
145 
146 %union {
147  char * ident;
148  char * str;
149  double d;
150  struct definition_t * definition;
151  struct definition_t * subcircuit;
152  struct value_t * value;
153 }
154 
155 %type <str> TitleLine
156 %type <definition> DefinitionLine BeginSub SubBody Subcircuit SubBodyLine
157 
158 %type <value> NodeList PairList Expr DC_List ValueList ExprList PLOT_List
159 %type <value> VOLTAGE_Output CURRENT_Output Output_Range PRINT_List
161 %type <value> IC_Condition_1 IC_Condition_2 IC_Condition_3 NODESET_List
162 %type <value> IC_Condition_4 SWITCH_State NodeValueList TC_Value_1 TC_Value_2
163 %type <value> VSourceList
164 
165 %type <ident> Identifier Nodes Function Value Floats Digits Node FH_Node
166 %type <ident> RLC_Device K_Device L_Device IV_Source GE_Source FH_Source
167 %type <ident> V_Source MODEL_Spec Diode_Device Bipolar_Device JFET_Device
168 %type <ident> MOSFET_Device MESFET_Device TRAN_Action PLOT_Action MODEL_Action
169 %type <ident> VoltFunc CurrFunc AC_Action DC_Action B_Source DISTO_Action
170 %type <ident> PRINT_Action Options OPTIONS_Action WIDTH_Action INCLUDE_Action
171 %type <ident> NOISE_Action PZ_Action CurVol PoleZero ALL_Special File
172 %type <ident> X_Device SUBCKT_Action SubCkt_Ident O_Device MODEL_Ident
173 %type <ident> ModelProps OP_Action I_Source IV_Reference SAVE_Action ON_Special
174 %type <ident> IC_Special OFF_Special SIM_Type TEMP_Special MOS_Special
175 %type <ident> BranchFunc NODESET_Action T_Device U_Device S_Device W_Device
176 %type <ident> TF_Action SENS_Action FOUR_Action OpFunc TC_Special TEMP_Action
177 %type <ident> Behave
178 
179 %%
180 
181 Input:
182  InputList End {
183  }
184  | TitleLine InputList End {
185  spice_title = $1;
186  }
187  | InputList {
188  fprintf (stderr, "spice notice, no .END directive found, continuing\n");
189  }
190  | TitleLine InputList {
191  spice_title = $1;
192  fprintf (stderr, "spice notice, no .END directive found, continuing\n");
193  }
194 ;
195 
196 InputList: /* nothing */
197  | InputLine InputList
198 ;
199 
200 InputLine:
201  Subcircuit {
202  /* chain definition root */
203  $1->next = definition_root;
205  }
207  /* chain definition root */
208  if ($1) {
209  $1->next = definition_root;
210  definition_root = $1;
211  }
212  }
213  | Eol { /* nothing to do here */ }
214 ;
215 
217  RLC_Device Node Node Value PairList Eol {
218  /* R, L and C definitions */
223  $$->values = netlist_append_values ($$->values, $5);
224  }
225  | RLC_Device Node Node Value MODEL_Ident PairList Eol {
226  /* R, L and C definitions specified by a Model */
227  $$ = spice_create_device ($1);
232  $$->values = netlist_append_values ($$->values, $6);
233  }
234  | RLC_Device Node Node MODEL_Ident Value Eol {
235  /* R, L and C definitions specified by a Model, a variant */
236  $$ = spice_create_device ($1);
241  }
242  | RLC_Device Node Node MODEL_Ident PairList Eol {
243  /* R definitions specified by a Model, yet another variant */
244  $$ = spice_create_device ($1);
248  $$->values = netlist_append_values ($$->values, $5);
249  }
250  | RLC_Device Node Node Value TC_Value_1 Eol {
251  /* R definitions including TC1 */
252  $$ = spice_create_device ($1);
256  $$->values = netlist_append_values ($$->values, $5);
257  }
258  | RLC_Device Node Node Value TC_Value_2 Eol {
259  /* R definitions including TC1/TC2 */
260  $$ = spice_create_device ($1);
264  $$->values = netlist_append_values ($$->values, $5);
265  }
266  | RLC_Device Node Node Value Behave NodeValueList Eol {
267  /* non-linear C and L poly definitions */
268  $$ = spice_create_device ($1);
273  $$->values = netlist_append_values ($$->values, $6);
274  }
275  | K_Device L_Device L_Device Value Eol {
276  /* Mutual inductors */
277  $$ = spice_create_device ($1);
281  }
282  | IV_Source Node Node ExprList Eol {
283  /* independent current/voltage sources */
284  $$ = spice_create_device ($1);
287  $$->values = netlist_append_values ($$->values, $4);
288  }
289  | IV_Source Node Node Value ExprList Eol {
290  /* independent current/voltage sources given the value */
291  $$ = spice_create_device ($1);
295  $$->values = netlist_append_values ($$->values, $5);
296  }
297  | GE_Source Node Node Behave Digits NodeValueList Eol {
298  /* voltage controlled source POLY */
299  if (!strcasecmp ($4, "POLY")) {
300  $$ = spice_create_device ($1);
305  $$->values = netlist_append_values ($$->values, $6);
306  }
307  else {
308  fprintf (stderr, "spice notice, behavioural %s source ignored\n", $1);
309  $$ = NULL;
310  }
311  }
312  | GE_Source Node Node Behave Eol {
313  /* voltage controlled sources OTHER behavioural */
314  fprintf (stderr, "spice notice, behavioural %s source ignored\n", $1);
315  $$ = NULL;
316  }
317  | GE_Source Node Node Node Node Value Eol {
318  /* voltage controlled sources */
319  $$ = spice_create_device ($1);
325  }
326  | FH_Source FH_Node FH_Node Behave Digits VSourceList NodeValueList Eol {
327  /* current controlled source POLY */
328  if (!strcasecmp ($4, "POLY")) {
329  $$ = spice_create_device ($1);
334  $$->values = netlist_append_values ($$->values, $6);
335  $$->values = netlist_append_values ($$->values, $7);
336  }
337  else {
338  fprintf (stderr, "spice notice, behavioural %s source ignored\n", $1);
339  $$ = NULL;
340  }
341  }
342  | FH_Source FH_Node FH_Node Behave Eol {
343  /* current controlled sources OTHER behavioural */
344  fprintf (stderr, "spice notice, behavioural %s source ignored\n", $1);
345  $$ = NULL;
346  }
347  | FH_Source FH_Node FH_Node V_Source Value Eol {
348  /* current controlled sources */
349  $$ = spice_create_device ($1);
354  }
355  | MODEL_Action MODEL_Ident MODEL_Spec MODEL_List Eol {
356  /* device specification */
357  $$ = spice_create_action ($1, $2);
360  $$->values = netlist_append_values ($$->values, $4);
361  }
362  | Diode_Device Node Node MODEL_Ident DEVICE_List_1 {
363  /* diode */
364  $$ = spice_create_device ($1);
368  $$->values = netlist_append_values ($$->values, $5);
369  }
370  | JFET_Device Node Node Node MODEL_Ident DEVICE_List_2 {
371  /* JFET */
372  $$ = spice_create_device ($1);
377  $$->values = netlist_append_values ($$->values, $6);
378  }
379  | Bipolar_Device Node Node Node MODEL_Ident DEVICE_List_2 {
380  /* 3 node BJT */
381  $$ = spice_create_device ($1);
386  $$->values = netlist_append_values ($$->values, $6);
387  }
388  | Bipolar_Device Node Node Node Node MODEL_Ident DEVICE_List_2 {
389  /* 4 node BJT */
390  $$ = spice_create_device ($1);
396  $$->values = netlist_append_values ($$->values, $7);
397  }
398  | MOSFET_Device Node Node Node Node MODEL_Ident DEVICE_List_3 {
399  /* MOS */
400  $$ = spice_create_device ($1);
406  $$->values = netlist_append_values ($$->values, $7);
407  }
408  | MESFET_Device Node Node Node MODEL_Ident DEVICE_List_2 {
409  /* MES */
410  $$ = spice_create_device ($1);
415  $$->values = netlist_append_values ($$->values, $6);
416  }
417  | TRAN_Action ValueList Eol {
418  /* transient analysis */
419  $$ = spice_create_action ($1, strdup ($1));
420  $$->values = $2;
421  }
422  | PLOT_Action SIM_Type PLOT_List Eol {
423  /* plotting */
424  $$ = spice_create_action ($1, strdup ($1));
426  $$->values = netlist_append_values ($$->values, $3);
427  }
428  | AC_Action Expr Eol {
429  /* AC analysis */
430  $$ = spice_create_action ($1, strdup ($1));
431  $$->values = $2;
432  }
433  | DC_Action Eol {
434  /* single DC analysis */
435  $$ = spice_create_action ($1, strdup ($1));
436  }
437  | DC_Action DC_List Eol {
438  /* DC analysis first order */
439  $$ = spice_create_action ($1, strdup ($1));
440  $$->values = $2;
441  }
442  | DC_Action DC_List DC_List Eol {
443  /* DC analysis second order */
444  $$ = spice_create_action ($1, strdup ($1));
445  $$->values = netlist_append_values ($2, $3);
446  }
447  | PRINT_Action SIM_Type PRINT_List Eol {
448  /* printing specifying the analysis type */
449  $$ = spice_create_action ($1, strdup ($1));
451  $$->values = netlist_append_values ($$->values, $3);
452  }
453  | PRINT_Action PRINT_List Eol {
454  /* printing */
455  $$ = spice_create_action ($1, strdup ($1));
456  $$->values = $2;
457  }
458  | PRINT_Action SIM_Type ALL_Special Eol {
459  /* printing */
460  $$ = spice_create_action ($1, strdup ($1));
463  }
464  | OPTIONS_Action OPTIONS_List Eol {
465  /* general analysis options */
466  $$ = spice_create_action ($1, strdup ($1));
467  $$->values = $2;
468  }
469  | TEMP_Action ValueList Eol {
470  /* temperatur analysis (Spice 2g6) */
471  $$ = spice_create_action ($1, strdup ($1));
472  $$->values = $2;
473  }
474  | WIDTH_Action PairList Eol {
475  /* TODO: default width of ??? */
476  $$ = spice_create_action ($1, strdup ($1));
477  $$->values = $2;
478  }
479  | NOISE_Action VOLTAGE_Output IV_Reference Expr Eol {
480  /* noise analysis */
481  $$ = spice_create_action ($1, strdup ($1));
482  $$->values = netlist_append_values ($$->values, $2);
484  $$->values = netlist_append_values ($$->values, $4);
485  }
486  | PZ_Action Node Node Node Node CurVol PoleZero Eol {
487  /* pole-zero analysis */
488  $$ = spice_create_action ($1, strdup ($1));
495  }
496  | X_Device NodeList Eol {
497  /* subcircuit call */
498  $$ = spice_create_device ($1);
500  $$->values = $2;
501  }
502  | S_Device Node Node Node Node MODEL_Ident SWITCH_State Eol {
503  /* voltage controlled switch */
504  $$ = spice_create_device ($1);
510  $$->values = netlist_append_values ($$->values, $7);
511  }
512  | W_Device Node Node V_Source MODEL_Ident SWITCH_State Eol {
513  /* current controlled switch */
514  $$ = spice_create_device ($1);
519  $$->values = netlist_append_values ($$->values, $6);
520  }
521  | O_Device Node Node Node Node MODEL_Ident Eol {
522  /* lossy transline */
523  $$ = spice_create_device ($1);
529  }
530  | U_Device Node Node Node MODEL_Ident PairList Eol {
531  /* distributed lossy transline */
532  $$ = spice_create_device ($1);
537  $$->values = netlist_append_values ($$->values, $6);
538  }
539  | T_Device Node Node Node Node PairList Eol {
540  /* lossless transline */
541  $$ = spice_create_device ($1);
546  $$->values = netlist_append_values ($$->values, $6);
547  }
548  | T_Device Node Node Node Node PairList IC_Condition_4 Eol {
549  /* lossless transline and initial condition */
550  $$ = spice_create_device ($1);
555  $$->values = netlist_append_values ($$->values, $6);
556  $$->values = netlist_append_values ($$->values, $7);
557  }
558  | OP_Action Eol {
559  /* operating point analysis */
560  $$ = spice_create_action ($1, strdup ($1));
561  }
562  | SAVE_Action Eol {
563  /* saving action */
564  $$ = spice_create_action ($1, strdup ($1));
565  }
566  | SENS_Action Eol {
567  /* sensitivity analysis */
568  $$ = spice_create_action ($1, strdup ($1));
569  }
570  | TF_Action Eol {
571  /* transfer function analysis */
572  $$ = spice_create_action ($1, strdup ($1));
573  }
574  | FOUR_Action Eol {
575  /* fourier analysis */
576  $$ = spice_create_action ($1, strdup ($1));
577  }
578  | B_Source Eol {
579  /* non-linear dependent sources */
580  $$ = spice_create_device ($1);
581  }
582  | DISTO_Action Expr Eol {
583  /* distortion analysis */
584  $$ = spice_create_action ($1, strdup ($1));
585  $$->values = $2;
586  }
587  | INCLUDE_Action File Eol {
588  /* file include */
589  $$ = spice_create_action ($1, strdup ($1));
590  struct value_t * file = create_value ();
591  file->ident = $2;
592  file->hint = HINT_NAME;
593  $$->values = file;
594  }
595  | NODESET_Action NODESET_List Eol {
596  /* nodeset functionality */
597  $$ = spice_create_action ($1, strdup ($1));
598  $$->values = $2;
599  }
600 ;
601 
602 TC_Value_1:
603  TC_Special Value {
604  $$ = NULL;
605  $$ = spice_create_par_value ($1, $2);
606  }
607 ;
608 
609 TC_Value_2:
610  TC_Special Value Value {
611  $$ = NULL;
612  $$ = spice_create_par_value ($1, $2);
614  }
615 ;
616 
617 IC_Condition_1:
618  IC_Special Value {
619  $$ = NULL;
620  $$ = spice_append_str_values ($$, $1, HINT_NAME);
622  }
623 ;
624 
625 IC_Condition_2:
626  IC_Special Value Value {
627  $$ = NULL;
628  $$ = spice_append_str_values ($$, $1, HINT_NAME);
629  $$ = spice_append_val_values ($$, $2, HINT_NUMBER);
631  }
632 
633 IC_Condition_3:
634  IC_Special Value Value Value {
635  $$ = NULL;
636  $$ = spice_append_str_values ($$, $1, HINT_NAME);
637  $$ = spice_append_val_values ($$, $2, HINT_NUMBER);
638  $$ = spice_append_val_values ($$, $3, HINT_NUMBER);
640  }
641 ;
642 
643 IC_Condition_4:
644  IC_Special Value Value Value Value {
645  $$ = NULL;
646  $$ = spice_append_str_values ($$, $1, HINT_NAME);
647  $$ = spice_append_val_values ($$, $2, HINT_NUMBER);
648  $$ = spice_append_val_values ($$, $3, HINT_NUMBER);
649  $$ = spice_append_val_values ($$, $4, HINT_NUMBER);
651  }
652 ;
653 
654 Output_Range:
655  Value Value { /* range specification during plotting */
656  $$ = NULL;
657  $$ = spice_append_val_values ($$, $1, HINT_NUMBER);
659  }
660 ;
661 
662 VOLTAGE_Output:
663  Node { // TODO: 2 reduce/reduce, 2 shift/reduce
664  /* print/plot specification of node voltage */
665  $$ = NULL;
666  $$ = spice_append_str_values ($$, strdup ("V"), HINT_NAME | HINT_MSTART);
668  }
669  | VoltFunc Node { // TODO: 2 reduce/reduce
670  /* print/plot specification of node voltage */
671  $$ = NULL;
674  }
675  | VoltFunc Node Node {
676  /* print/plot specification of differential node voltages */
677  $$ = NULL;
679  $$ = spice_append_str_values ($$, $2, HINT_NODE);
681  }
682 ;
683 
684 /* reference to a current or voltage source */
685 IV_Reference: I_Source | V_Source;
686 
687 CURRENT_Output:
688  CurrFunc V_Source {
689  /* print/plot specification of branch current */
690  $$ = NULL;
693  }
695  /* print/plot specification of branch current */
696  $$ = NULL;
697  $$ = spice_append_str_values ($$, strdup ("I"), HINT_NAME | HINT_MSTART);
699  }
700  | OpFunc {
701  /* print/plot specification of operating point */
702  $$ = NULL;
703  $$ = spice_append_str_values ($$, strdup ("OP"), HINT_NAME | HINT_MSTART);
705  }
706 ;
707 
708 PLOT_List: /* nothing */ { $$ = NULL; }
709  | VOLTAGE_Output PLOT_List {
710  $$ = netlist_append_values ($1, $2);
711  }
712  | VOLTAGE_Output Output_Range PLOT_List {
713  $$ = netlist_append_values ($1, $2);
714  $$ = netlist_append_values ($$, $3);
715  }
716  | CURRENT_Output PLOT_List {
717  $$ = netlist_append_values ($1, $2);
718  }
719  | CURRENT_Output Output_Range PLOT_List {
720  $$ = netlist_append_values ($1, $2);
721  $$ = netlist_append_values ($$, $3);
722  }
723 ;
724 
725 SWITCH_State: /* nothing */ { $$ = NULL; }
728  }
731  }
732 ;
733 
734 PRINT_List: /* nothing */ { $$ = NULL; }
735  | VOLTAGE_Output PLOT_List {
736  $$ = netlist_append_values ($1, $2);
737  }
738  | CURRENT_Output PLOT_List {
739  $$ = netlist_append_values ($1, $2);
740  }
741 ;
742 
743 OPTIONS_List: /* nothing */ { $$ = NULL; }
744  | Options OPTIONS_List {
746  $$ = netlist_append_values ($$, $2);
747  }
748  | Identifier Value OPTIONS_List {
749  $$ = spice_create_par_value ($1, $2);
750  $$ = netlist_append_values ($$, $3);
751  }
752 ;
753 
754 MODEL_List: /* nothing */ { $$ = NULL; }
755  | ModelProps MODEL_List {
757  $$ = netlist_append_values ($$, $2);
758  }
759  | Identifier Value MODEL_List {
760  $$ = spice_create_par_value ($1, $2);
761  $$ = netlist_append_values ($$, $3);
762  }
763 ;
764 
765 NODESET_List: /* nothing */ { $$ = NULL; }
766  | VoltFunc Node Value NODESET_List {
767  $$ = NULL;
770  $$ = spice_append_str_values ($$, $3, HINT_NUMBER);
771  $$ = netlist_append_values ($$, $4);
772  }
773 ;
774 
775 DEVICE_List_1: /* nothing */ { $$ = NULL; }
776  | TEMP_Special Value DEVICE_List_1 {
777  $$ = spice_create_par_value ($1, $2);
778  $$ = netlist_append_values ($$, $3);
779  }
780  | Value DEVICE_List_1 {
781  $$ = spice_create_par_value (strdup ("Area"), $1);
782  $$ = netlist_append_values ($$, $2);
783  }
786  $$ = netlist_append_values ($$, $2);
787  }
788  | IC_Condition_1 DEVICE_List_1 {
789  $$ = netlist_append_values ($1, $2);
790  }
791 ;
792 
793 DEVICE_List_2: /* nothing */ { $$ = NULL; }
794  | TEMP_Special Value DEVICE_List_2 {
795  $$ = spice_create_par_value ($1, $2);
796  $$ = netlist_append_values ($$, $3);
797  }
798  | Value DEVICE_List_2 {
799  $$ = spice_create_par_value (strdup ("Area"), $1);
800  $$ = netlist_append_values ($$, $2);
801  }
804  $$ = netlist_append_values ($$, $2);
805  }
806  | IC_Condition_2 DEVICE_List_2 {
807  $$ = netlist_append_values ($1, $2);
808  }
809  | MOS_Special Value DEVICE_List_2 {
810  $$ = spice_create_par_value ($1, $2);
811  $$ = netlist_append_values ($$, $3);
812  }
813 ;
814 
815 DEVICE_List_3: /* nothing */ { $$ = NULL; }
816  | TEMP_Special Value DEVICE_List_3 {
817  $$ = spice_create_par_value ($1, $2);
818  $$ = netlist_append_values ($$, $3);
819  }
820  | MOS_Special Value DEVICE_List_3 {
821  $$ = spice_create_par_value ($1, $2);
822  $$ = netlist_append_values ($$, $3);
823  }
824  | Value DEVICE_List_3 {
826  $$ = netlist_append_values ($$, $2);
827  }
830  $$ = netlist_append_values ($$, $2);
831  }
832  | IC_Condition_3 DEVICE_List_3 {
833  $$ = netlist_append_values ($1, $2);
834  }
835 ;
836 
837 MODEL_Ident: Identifier | MODEL_Spec;
838 
839 DC_List:
840  IV_Reference Value Value Value {
841  /* identification of a DC sweep */
842  $$ = NULL;
844  $$ = spice_append_val_values ($$, $2, HINT_NUMBER);
845  $$ = spice_append_val_values ($$, $3, HINT_NUMBER);
847  }
848 ;
849 
850 Value: Digits | Floats;
851 
852 Node: Digits | Nodes | Identifier;
853 
854 FH_Node: Node | V_Source;
855 
856 PairList: /* nothing */ { $$ = NULL; }
858  $$ = spice_create_par_value ($1, $2);
859  $$->next = $3;
860  }
861 ;
862 
863 ValueList: /* nothing */ { $$ = NULL; }
864  | Value ValueList {
866  $$->next = $2;
867  }
868 ;
869 
870 NodeValueList: /* nothing */ { $$ = NULL; }
873  $$->next = $2;
874  }
875  | Floats NodeValueList {
877  $$->next = $2;
878  }
879 ;
880 
881 NodeList: /* nothing */ { $$ = NULL; }
884  $$->next = $2;
885  }
886 ;
887 
888 VSourceList: /* nothing */ { $$ = NULL; }
889  | V_Source VSourceList {
891  $$->next = $2;
892  }
893 ;
894 
895 Expr:
896  Function ValueList {
899  $$->next = $2;
900  }
901 ;
902 
903 ExprList: /* nothing */ { $$ = NULL; }
904  | Expr ExprList {
905  $$ = netlist_append_values ($1, $2);
906  }
907 ;
908 
909 Subcircuit:
910  BeginSub SubBody EndSub {
911  $1->sub = $2;
912  $$ = $1;
913  $2 = NULL;
914  }
915 ;
916 
917 BeginSub:
918  SUBCKT_Action SubCkt_Ident NodeList Eol {
919  $$ = spice_create_action ($1, $2);
920  $$->values = $3;
921  }
922 ;
923 
924 SubBody: /* nothing */ { $$ = NULL; }
925  | SubBodyLine SubBody { /* chain definitions here */
926  if ($1) {
927  $1->next = $2;
928  $$ = $1;
929  }
930  else {
931  $$ = $2;
932  }
933  }
934 ;
935 
936 SubCkt_Ident: Identifier;
937 
938 EndSub:
939  ENDS_Action { /* nothing to do */ }
940  | ENDS_Action SubCkt_Ident { free ($2); /* nothing to do */ }
941 ;
942 
943 SubBodyLine:
944  DefinitionLine { /* chain definitions here */
945  if ($1) {
946  $1->next = $$;
947  $$ = $1;
948  }
949  }
950  | Subcircuit { /* do nothing here, see subcircuit rule */ }
951  | Eol {
952  $$ = NULL;
953  }
954 ;
955 
956 %%
957 
958 int spice_error (const char * error) {
959  fprintf (stderr, "line %d: %s\n", spice_lineno, error);
960  return 0;
961 }
Node NodeValueList
Definition: parse_spice.y:871
Expr ExprList
Definition: parse_spice.y:904
OFF_Special
Definition: parse_spice.y:729
#define HINT_MSTOP
name
Definition: parse_mdl.y:352
BranchFunc
Definition: parse_spice.y:694
static struct definition_t * spice_create_device(char *instance)
Definition: parse_spice.y:56
ModelProps MODEL_List
Definition: parse_spice.y:755
struct value_t * values
Definition: netdefs.h:80
static struct value_t * spice_create_val_value(char *value, int hint)
Definition: parse_spice.y:86
Identifier
Definition: parse_csv.y:87
char * type
Definition: netdefs.h:62
char * spice_title
Definition: check_spice.cpp:51
int line
Definition: netdefs.h:75
static struct value_t * spice_append_str_values(struct value_t *values, char *value, int hint)
Definition: parse_spice.y:109
Node NodeList
Definition: parse_spice.y:882
#define create_definition()
Definition: netdefs.h:191
static struct value_t * spice_create_str_value(char *value, int hint)
Definition: parse_spice.y:78
int action
Definition: netdefs.h:71
static __END_DECLS char * spice_toupper(char *str)
Definition: parse_spice.y:48
double value
Definition: netdefs.h:45
instance
TEMP_Special Value DEVICE_List_3
Definition: parse_spice.y:816
int spice_error(const char *error)
Definition: parse_spice.y:958
char * ident
Definition: netdefs.h:42
char * instance
Definition: netdefs.h:63
#define PROP_ACTION
Definition: netdefs.h:115
i
Definition: parse_mdl.y:516
Value ValueList
Definition: parse_spice.y:864
char * unit
Definition: netdefs.h:43
ON_Special
Definition: parse_spice.y:726
static struct value_t * spice_create_par_value(char *key, char *value)
Definition: parse_spice.y:95
definition_root
Definition: parse_spice.y:204
RLC_Device Node Node Value MODEL_Ident PairList Eol
Definition: parse_spice.y:225
V_Source VSourceList
Definition: parse_spice.y:889
#define HINT_MSTART
TEMP_Special Value DEVICE_List_1
Definition: parse_spice.y:776
Identifier Value PairList
Definition: parse_spice.y:857
#define PROP_COMPONENT
Definition: netdefs.h:116
#define HINT_NUMBER
static void spice_append_val_value(struct definition_t *def, char *value, int hint)
Definition: parse_spice.y:116
OpFunc
Definition: parse_spice.y:700
#define HINT_NODE
free($1)
VoltFunc Node
Definition: parse_spice.y:669
< INITIAL >< INITIAL >< INITIAL >< INITIAL > return InvalidCharacter
Definition: scan_netlist.l:698
#define HINT_PAIR
Subcircuit
Definition: parse_spice.y:950
static struct value_t * spice_append_val_values(struct value_t *values, char *value, int hint)
Definition: parse_spice.y:123
char * subcircuit
Definition: netdefs.h:79
InputLine InputList
value
Definition: parse_vcd.y:315
#define create_value()
Definition: netdefs.h:193
DefinitionLine
Definition: parse_spice.y:206
static struct definition_t * spice_create_action(char *type, char *instance)
Definition: parse_spice.y:67
type
Definition: parse_vcd.y:164
name prefix
Definition: parse_spice.y:131
spice_add_last_hint($2, HINT_MSTOP)
#define HINT_NAME
void spice_set_last_hint(struct value_t *val, int hint)
TEMP_Special Value DEVICE_List_2
Definition: parse_spice.y:794
VOLTAGE_Output PLOT_List
Definition: parse_spice.y:709
int spice_lineno
Definition: parse_spice.y:40
int hint
Definition: netdefs.h:48
struct value_t * netlist_append_values(struct value_t *v1, struct value_t *v2)
values
Definition: parse_spice.y:223
key
Options OPTIONS_List
Definition: parse_spice.y:744
VoltFunc Node Value NODESET_List
Definition: parse_spice.y:766
SubBodyLine SubBody
Definition: parse_spice.y:925
static void spice_append_str_value(struct definition_t *def, char *value, int hint)
Definition: parse_spice.y:102