Skip to content

Commit cdf2767

Browse files
author
ThomasZecha
committed
Fix build issues flex/bison part
-fixed deprecated yacc/bison name-prefix directive warning, shift/reduce-conflicts (sr) and reduce/reduce-conflicts (rr) of the spice-parser build by parse_spice.ypp and scan_spice.lpp: -sr-conflicts solved by introducing token/rule precedence -rr-conflicts solved by introducing token lookahead's in the spice scanner -verification of equalness of generated output from both the converter before and after the code change done with spice input bjt.cir done -fixed ra3xdh/qucs_s#967: -The lookahead-pattern for differentiate the 3-/4-/5-node spice-bjt erroneously contains newline. This causes read a spice bjt-line don't stop at new line and detect a 5-node bjt instead of 3-node bjt as happen for AD822X.cir of Opamp_AC_Tran.zip from the issue 967. This is fixed and tested against AD822X.cir. The critical lines from AD822X.cir are included in the bjt.cir qucsconv_rf testing example. Signed-off-by: ThomasZecha <zecha@ihp-microelectronics.com>
1 parent abeec88 commit cdf2767

File tree

3 files changed

+122
-21
lines changed

3 files changed

+122
-21
lines changed

src/converter/parse_spice.ypp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444

4545
#include "check_spice.h"
4646

47+
#define YY_HEADER_EXPORT_START_CONDITIONS
48+
#include "scan_spice.hpp"
49+
50+
extern char* spice_text;
51+
52+
extern void push_state(int state);
53+
extern void pop_state();
54+
4755
// Converts the given string into upper case.
4856
static char * spice_toupper (char * str) {
4957
for (unsigned int i = 0; i < strlen (str); i++) {
@@ -128,10 +136,11 @@ static struct value_t * spice_append_val_values (struct value_t * values,
128136

129137
%}
130138

131-
%name-prefix "spice_"
139+
%define api.prefix {spice_}
132140

133141
%token TitleLine InvalidCharacter End Eol
134-
%token Identifier Digits Floats Nodes Options Function
142+
%token Identifier Digits Floats Nodes Options Function Lookahead_Double_Value
143+
%token Lookahead_Three_Node Lookahead_Four_Node Lookahead_Five_Node
135144
%token SUBCKT_Action ENDS_Action AC_Action OP_Action I_Source SAVE_Action
136145
%token RLC_Device L_Device K_Device IV_Source GE_Source FH_Source V_Source
137146
%token Diode_Device Bipolar_Device JFET_Device MOSFET_Device MESFET_Device
@@ -143,6 +152,9 @@ static struct value_t * spice_append_val_values (struct value_t * values,
143152
%token U_Device S_Device W_Device ON_Special TF_Action SENS_Action FOUR_Action
144153
%token OpFunc Behave TC_Special TEMP_Action
145154

155+
%precedence Identifier Digits Nodes
156+
%precedence _NODE_
157+
146158
%union {
147159
char * ident;
148160
char * str;
@@ -162,7 +174,7 @@ static struct value_t * spice_append_val_values (struct value_t * values,
162174
%type <value> IC_Condition_4 SWITCH_State NodeValueList TC_Value_1 TC_Value_2
163175
%type <value> VSourceList
164176

165-
%type <ident> Identifier Nodes Function Value Floats Digits Node FH_Node
177+
%type <ident> Identifier Nodes Function Value Lookahead_Double_Value Floats Digits Node FH_Node
166178
%type <ident> RLC_Device K_Device L_Device IV_Source GE_Source FH_Source
167179
%type <ident> V_Source MODEL_Spec Diode_Device Bipolar_Device JFET_Device
168180
%type <ident> MOSFET_Device MESFET_Device TRAN_Action PLOT_Action MODEL_Action
@@ -174,7 +186,7 @@ static struct value_t * spice_append_val_values (struct value_t * values,
174186
%type <ident> IC_Special OFF_Special SIM_Type TEMP_Special MOS_Special
175187
%type <ident> BranchFunc NODESET_Action T_Device U_Device S_Device W_Device
176188
%type <ident> TF_Action SENS_Action FOUR_Action OpFunc TC_Special TEMP_Action
177-
%type <ident> Behave
189+
%type <ident> Behave Lookahead_Three_Node Lookahead_Four_Node Lookahead_Five_Node
178190

179191
%%
180192

@@ -374,7 +386,7 @@ DefinitionLine:
374386
spice_append_str_value ($$, $5, HINT_NAME);
375387
$$->values = netlist_append_values ($$->values, $6);
376388
}
377-
| Bipolar_Device Node Node Node MODEL_Ident DEVICE_List_2 {
389+
| Bipolar_Device Lookahead_Three_Node Node Node MODEL_Ident DEVICE_List_2 {
378390
/* 3 node BJT */
379391
$$ = spice_create_device ($1);
380392
spice_append_str_value ($$, $2, HINT_NODE);
@@ -383,7 +395,7 @@ DefinitionLine:
383395
spice_append_str_value ($$, $5, HINT_NAME);
384396
$$->values = netlist_append_values ($$->values, $6);
385397
}
386-
| Bipolar_Device Node Node Node Node MODEL_Ident DEVICE_List_2 {
398+
| Bipolar_Device Lookahead_Four_Node Node Node Node MODEL_Ident DEVICE_List_2 {
387399
/* 4 node BJT */
388400
$$ = spice_create_device ($1);
389401
spice_append_str_value ($$, $2, HINT_NODE);
@@ -393,7 +405,7 @@ DefinitionLine:
393405
spice_append_str_value ($$, $6, HINT_NAME);
394406
$$->values = netlist_append_values ($$->values, $7);
395407
}
396-
| Bipolar_Device Node Node Node Node Node MODEL_Ident DEVICE_List_2 {
408+
| Bipolar_Device Lookahead_Five_Node Node Node Node Node MODEL_Ident DEVICE_List_2 {
397409
/* 5 node BJT */
398410
$$ = spice_create_device ($1);
399411
spice_append_str_value ($$, $2, HINT_NODE);
@@ -661,21 +673,22 @@ IC_Condition_4:
661673
;
662674

663675
Output_Range:
664-
Value Value { /* range specification during plotting */
676+
Lookahead_Double_Value Value { /* range specification during plotting */
665677
$$ = NULL;
666678
$$ = spice_append_val_values ($$, $1, HINT_NUMBER);
667679
$$ = spice_append_val_values ($$, $2, HINT_NUMBER);
668680
}
669681
;
670682

671683
VOLTAGE_Output:
672-
Node { // TODO: 2 reduce/reduce, 2 shift/reduce
684+
Node {
673685
/* print/plot specification of node voltage */
686+
push_state(DOUBLEVALUE);
674687
$$ = NULL;
675688
$$ = spice_append_str_values ($$, strdup ("V"), HINT_NAME | HINT_MSTART);
676689
$$ = spice_append_str_values ($$, $1, HINT_NODE | HINT_MSTOP);
677690
}
678-
| VoltFunc Node { // TODO: 2 reduce/reduce
691+
| VoltFunc Node %prec _NODE_ {
679692
/* print/plot specification of node voltage */
680693
$$ = NULL;
681694
$$ = spice_append_str_values ($$, $1, HINT_NAME | HINT_MSTART);
@@ -843,7 +856,7 @@ DEVICE_List_3: /* nothing */ { $$ = NULL; }
843856
$$ = netlist_append_values ($$, $2);
844857
}
845858
| IC_Condition_3 DEVICE_List_3 {
846-
$$ = netlist_append_values ($1, $2);
859+
$$ = netlist_append_values ($1, $2);
847860
}
848861
;
849862

@@ -969,6 +982,6 @@ SubBodyLine:
969982
%%
970983

971984
int spice_error (const char * error) {
972-
fprintf (stderr, "line %d: %s\n", spice_lineno, error);
985+
fprintf (stderr, "line %d: %s at id %d, token '%s'\n", spice_lineno, error, spice_char, spice_text);
973986
return 0;
974987
}

src/converter/scan_spice.lpp

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include "check_spice.h"
5151
#include "parse_spice.hpp"
5252

53-
5453
/* fixing invalid identifiers */
5554
static void spice_fix_identifier (char * ident) {
5655
char * p;
@@ -62,9 +61,25 @@ static void spice_fix_identifier (char * ident) {
6261
}
6362
}
6463

64+
static void yy_push_state(int);
65+
static void yy_pop_state();
66+
static int yy_top_state();
67+
68+
void push_state(int state) {
69+
yy_push_state(state);
70+
}
71+
72+
void pop_state() {
73+
yy_pop_state();
74+
}
75+
76+
int top_state() {
77+
return yy_top_state();
78+
}
79+
6580
%}
6681

67-
WS [ \t\n\r]
82+
WS [ \t]
6883
TITLE [* \t0-9A-Za-z][A-Za-z0-9\- \t;#:=()/\.,*\\]*\r*\n
6984
SPACE [ \t]
7085
NAME [A-Z][A-Z0-9]*
@@ -134,8 +149,8 @@ POLY [pP][oO][lL][yY]
134149

135150
%x COMMENT IVREF DEVPROP LREF MODREF1 MODREF2 IGNORE FUNREF FILEREF VREF
136151
%x STARTUP VSINGLE ISWITCH VSWITCH CONTROL GEVALS INLINE SUBCKT TLPROP RLCPROP
137-
%x FHVALS
138-
%option yylineno noyywrap nounput noinput prefix="spice_"
152+
%x FHVALS DOUBLEVALUE LANODE
153+
%option yylineno stack noyywrap nounput noinput prefix="spice_" header-file="scan_spice.hpp"
139154
%%
140155

141156
<INITIAL>^{TITLE} { /* detect initial title lines */
@@ -499,6 +514,7 @@ POLY [pP][oO][lL][yY]
499514
<STARTUP>^[qQ]{CSFX} { /* BJT instances */
500515
spice_lval.ident = strdup (spice_text);
501516
BEGIN(DEVPROP);
517+
push_state(LANODE);
502518
return Bipolar_Device;
503519
}
504520

@@ -524,17 +540,51 @@ POLY [pP][oO][lL][yY]
524540
return End;
525541
}
526542

543+
<DOUBLEVALUE>{NUMBER}|{DIGIT}+/{WS}({DIGIT}+|NUMBER) {
544+
/* identify value followed by value */
545+
spice_lval.ident = strdup (spice_text);
546+
pop_state();
547+
return Lookahead_Double_Value;
548+
}
549+
550+
<LANODE>{NODE}|{IDENT}|{DIGIT}+/{WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({MODEL}|{IDENT}) {
551+
/* identify node followed by 2 node */
552+
spice_lval.ident = strdup (spice_text);
553+
pop_state();
554+
return Lookahead_Three_Node;
555+
}
556+
557+
<LANODE>{NODE}|{IDENT}|{DIGIT}+/{WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({MODEL}|{IDENT}) {
558+
/* identify node followed by 3 node */
559+
spice_lval.ident = strdup (spice_text);
560+
pop_state();
561+
return Lookahead_Four_Node;
562+
}
563+
564+
<LANODE>{NODE}|{IDENT}|{DIGIT}+/{WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({DIGIT}+|{NODE}|{IDENT}){WS}+({MODEL}|{IDENT}) {
565+
/* identify node followed by 4 node */
566+
spice_lval.ident = strdup (spice_text);
567+
pop_state();
568+
return Lookahead_Five_Node;
569+
}
570+
527571
<STARTUP,IVREF,DEVPROP,LREF,FUNREF,VREF,VSINGLE,ISWITCH,VSWITCH,
528-
GEVALS,TLPROP,RLCPROP,FHVALS>{DIGIT}+ {
572+
GEVALS,TLPROP,RLCPROP,FHVALS,DOUBLEVALUE>{DIGIT}+ {
529573
/* identify node (containing digits) */
530574
spice_lval.ident = strdup (spice_text);
575+
if (yy_start_stack_ptr > 0 && top_state() == DOUBLEVALUE) {
576+
pop_state();
577+
}
531578
return Digits;
532579
}
533580

534581
<STARTUP,IVREF,DEVPROP,LREF,FUNREF,VREF,VSINGLE,GEVALS,TLPROP,
535-
RLCPROP,FHVALS>{NUMBER} {
582+
RLCPROP,FHVALS,DOUBLEVALUE>{NUMBER} {
536583
/* identify float (any kind) */
537584
spice_lval.ident = strdup (spice_text);
585+
if (yy_start_stack_ptr > 0 && top_state() == DOUBLEVALUE) {
586+
pop_state();
587+
}
538588
return Floats;
539589
}
540590

@@ -563,9 +613,12 @@ POLY [pP][oO][lL][yY]
563613
}
564614

565615
<STARTUP,DEVPROP,MODREF2,ISWITCH,VSWITCH,
566-
TLPROP,RLCPROP>{IDENT} { /* arbitrary identifier */
616+
TLPROP,RLCPROP,DOUBLEVALUE>{IDENT} { /* arbitrary identifier */
567617
spice_lval.ident = strdup (spice_text);
568618
spice_fix_identifier (spice_lval.ident);
619+
if (yy_start_stack_ptr > 0 && top_state() == DOUBLEVALUE) {
620+
pop_state();
621+
}
569622
return Identifier;
570623
}
571624

@@ -596,15 +649,21 @@ POLY [pP][oO][lL][yY]
596649
}
597650

598651
<STARTUP,IVREF,DEVPROP,FUNREF,VREF,VSINGLE,ISWITCH,VSWITCH,GEVALS,
599-
TLPROP,RLCPROP,FHVALS>{NODE} {
652+
TLPROP,RLCPROP,FHVALS,DOUBLEVALUE>{NODE} {
600653
/* identify node */
601654
spice_lval.ident = strdup (spice_text);
655+
if (yy_start_stack_ptr > 0 && top_state() == DOUBLEVALUE) {
656+
pop_state();
657+
}
602658
return Nodes;
603659
}
604660

605661
<STARTUP,IVREF,DEVPROP,LREF,IGNORE,FUNREF,FILEREF,VREF,VSINGLE,
606-
ISWITCH,VSWITCH,GEVALS,SUBCKT,TLPROP,RLCPROP,FHVALS>{EOL} {
662+
ISWITCH,VSWITCH,GEVALS,SUBCKT,TLPROP,RLCPROP,FHVALS,DOUBLEVALUE>{EOL} {
607663
/* detect end of line */
664+
if (yy_start_stack_ptr > 0 && top_state() == DOUBLEVALUE) {
665+
pop_state();
666+
}
608667
BEGIN(STARTUP);
609668
return Eol;
610669
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.title dual rc ladder
2+
* file name rcrcac.cir
3+
*R1 int in 10k
4+
*V1 in 0 dc 0 ac 1 PULSE (0 5 1u 1u 1u 1 1)
5+
*R2 out int 1k
6+
*C1 int 0 1u
7+
*C2 out 0 100n
8+
9+
Q1 A B C BJTNAME
10+
Q2 20 21 22 NPN 1.0
11+
Q3 A B C BJTNAME 7.0 8.0
12+
Q4 1 2 3 BJTNAME
13+
Q5 20 20 97 PNP
14+
Q6 21 21 22 A B NPN 1.0
15+
Q7 A B C D BJTNAME
16+
17+
.MODEL PNP PNP(BF=200 CJC=20pf CJE=20pf IS=1E-16)
18+
.MODEL NPN NPN(BF=200 CJC=20pf CJE=20pf IS=1E-16)
19+
.MODEL BJTNAME NPN(BF=200 CJC=20pf CJE=20pf IS=1E-16)
20+
21+
.plot dc 1 2 3 4 5 6 7 8
22+
23+
*.control
24+
*ac dec 10 1 100k
25+
*plot vdb(out)
26+
*plot ph(out)
27+
*.endc
28+
29+

0 commit comments

Comments
 (0)