📄 y.tab.c
字号:
#ifndef lintstatic char const yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $";#endif#include <stdlib.h>#define YYBYACC 1#define YYMAJOR 1#define YYMINOR 9#define YYLEX yylex()#define YYEMPTY -1#define yyclearin (yychar=(YYEMPTY))#define yyerrok (yyerrflag=0)#define YYRECOVERING() (yyerrflag!=0)static int yygrowstack();#define YYPREFIX "yy"#line 1 "netlist.y"
#include <stdio.h>
#include <stdarg.h>
#include "component.h"
extern char *yytext;
extern FILE *yyin;
#line 29 "netlist.y"typedef union { char svalue[100]; double fvalue;comp_def cvalue; int ivalue;} YYSTYPE;#line 31 "y.tab.c"#define YYERRCODE 256#define IDENTIFIER 257#define CAPACITOR 258#define INDUCTOR 259#define RESISTOR 260#define INTEGER 261#define COMPONENT_START 262#define COMPONENT_END 263#define NODE_START 264#define NODE_END 265const short yylhs[] = { -1, 4, 0, 2, 2, 5, 1, 1, 1, 1, 3, 3, 8, 6, 7, 7, 9, 9,};const short yylen[] = { 2, 0, 3, 2, 1, 5, 1, 1, 1, 1, 2, 1, 0, 5, 2, 1, 2, 2,};const short yydefred[] = { 0, 0, 0, 0, 4, 0, 0, 3, 0, 0, 0, 11, 9, 6, 7, 8, 0, 12, 10, 5, 0, 0, 0, 15, 16, 17, 13, 14,};const short yydgoto[] = { 2, 16, 3, 10, 6, 4, 11, 22, 20, 23,};const short yysindex[] = { -260, -254, 0, -260, 0, -253, -258, 0, -248, -250, -258, 0, 0, 0, 0, 0, -249, 0, 0, 0, -244, -256, -257, 0, 0, 0, 0, 0,};const short yyrindex[] = { 0, 0, 0, -247, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};const short yygindex[] = { 0, 0, 0, 0, 0, 13, 8, 0, 0, -3,};#define YYTABLESIZE 19const short yytable[] = { 21, 24, 1, 5, 8, 25, 9, 17, 26, 12, 13, 14, 15, 21, 19, 2, 7, 1, 18, 27,};const short yycheck[] = { 257, 257, 262, 257, 257, 261, 264, 257, 265, 257, 258, 259, 260, 257, 263, 0, 3, 264, 10, 22,};#define YYFINAL 2#ifndef YYDEBUG#define YYDEBUG 0#endif#define YYMAXTOKEN 265#if YYDEBUGconst char * const yyname[] = {"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"IDENTIFIER","CAPACITOR","INDUCTOR","RESISTOR","INTEGER","COMPONENT_START","COMPONENT_END","NODE_START","NODE_END",};const char * const yyrule[] = {"$accept : netlist","$$1 :","netlist : components $$1 netlists","components : components component","components : component","component : COMPONENT_START IDENTIFIER IDENTIFIER instance COMPONENT_END","instance : CAPACITOR","instance : INDUCTOR","instance : RESISTOR","instance : IDENTIFIER","netlists : netlists node_entry","netlists : node_entry","$$2 :","node_entry : NODE_START IDENTIFIER $$2 nets NODE_END","nets : nets net","nets : net","net : IDENTIFIER IDENTIFIER","net : IDENTIFIER INTEGER",};#endif#if YYDEBUG#include <stdio.h>#endif#ifdef YYSTACKSIZE#undef YYMAXDEPTH#define YYMAXDEPTH YYSTACKSIZE#else#ifdef YYMAXDEPTH#define YYSTACKSIZE YYMAXDEPTH#else#define YYSTACKSIZE 10000#define YYMAXDEPTH 10000#endif#endif#define YYINITSTACKSIZE 200int yydebug;int yynerrs;int yyerrflag;int yychar;short *yyssp;YYSTYPE *yyvsp;YYSTYPE yyval;YYSTYPE yylval;short *yyss;short *yysslim;YYSTYPE *yyvs;int yystacksize;#line 154 "netlist.y"
yyerror( const char *fmt,...)
{
va_list a;
va_start (a, fmt);
extern int yylineno;
printf("line %d:",yylineno);
vprintf (fmt, a);
va_end (a);
}#line 161 "y.tab.c"/* allocate initial stack or double stack size, up to YYMAXDEPTH */static int yygrowstack(){ int newsize, i; short *newss; YYSTYPE *newvs; if ((newsize = yystacksize) == 0) newsize = YYINITSTACKSIZE; else if (newsize >= YYMAXDEPTH) return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; i = yyssp - yyss; newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) : (short *)malloc(newsize * sizeof *newss); if (newss == NULL) return -1; yyss = newss; yyssp = newss + i; newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) : (YYSTYPE *)malloc(newsize * sizeof *newvs); if (newvs == NULL) return -1; yyvs = newvs; yyvsp = newvs + i; yystacksize = newsize; yysslim = yyss + newsize - 1; return 0;}#define YYABORT goto yyabort#define YYREJECT goto yyabort#define YYACCEPT goto yyaccept#define YYERROR goto yyerrlab#ifndef YYPARSE_PARAM#if defined(__cplusplus) || __STDC__#define YYPARSE_PARAM_ARG void#define YYPARSE_PARAM_DECL#else /* ! ANSI-C/C++ */#define YYPARSE_PARAM_ARG#define YYPARSE_PARAM_DECL#endif /* ANSI-C/C++ */#else /* YYPARSE_PARAM */#ifndef YYPARSE_PARAM_TYPE#define YYPARSE_PARAM_TYPE void *#endif#if defined(__cplusplus) || __STDC__#define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM#define YYPARSE_PARAM_DECL#else /* ! ANSI-C/C++ */#define YYPARSE_PARAM_ARG YYPARSE_PARAM#define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM;#endif /* ANSI-C/C++ */#endif /* ! YYPARSE_PARAM */intyyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL{ register int yym, yyn, yystate;#if YYDEBUG register const char *yys; if ((yys = getenv("YYDEBUG"))) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; }#endif yynerrs = 0; yyerrflag = 0; yychar = (-1); if (yyss == NULL && yygrowstack()) goto yyoverflow; yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0;yyloop: if ((yyn = yydefred[yystate])) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0;#if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, yychar, yys); }#endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) {#if YYDEBUG if (yydebug) printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]);#endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery;#if defined(lint) || defined(__GNUC__) goto yynewerror;#endifyynewerror: yyerror("syntax error");#if defined(lint) || defined(__GNUC__) goto yyerrlab;#endifyyerrlab: ++yynerrs;yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) {#if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);#endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; } else {#if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", YYPREFIX, *yyssp);#endif if (yyssp <= yyss) goto yyabort; --yyssp; --yyvsp; } } } else { if (yychar == 0) goto yyabort;#if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, error recovery discards token %d (%s)\n", YYPREFIX, yystate, yychar, yys); }#endif yychar = (-1); goto yyloop; }yyreduce:#if YYDEBUG if (yydebug) printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, yystate, yyn, yyrule[yyn]);#endif yym = yylen[yyn]; yyval = yyvsp[1-yym]; switch (yyn) {case 1:#line 40 "netlist.y"{pin_init();}break;case 2:#line 42 "netlist.y"{link_init();}break;case 5:#line 56 "netlist.y"{
comp_t *comp;
printf("Compoent done:%s %s <%d>\n",yyvsp[-3].svalue,yyvsp[-2].svalue,yyvsp[-1].cvalue.type);
switch (yyvsp[-1].cvalue.type)
{
case COMP_CAP:
case COMP_IND:
case COMP_RES:
comp = new_basic_component (yyvsp[-1].cvalue.type, yyvsp[-3].svalue,yyvsp[-1].cvalue.value.f);
break;
default:
comp = new_component (yyvsp[-1].cvalue.value.class, yyvsp[-3].svalue, NULL);
break;
}
if (!comp) {
yyerror ("component not instantiated:%s", yyvsp[-3].svalue );
YYERROR;
}
}break;case 6:#line 80 "netlist.y"{
yyval.cvalue.type = COMP_CAP;
yyval.cvalue.value.f = yyvsp[0].fvalue;
}break;case 7:#line 85 "netlist.y"{
yyval.cvalue.type = COMP_IND;
yyval.cvalue.value.f = yyvsp[0].fvalue;
}break;case 8:#line 90 "netlist.y"{
yyval.cvalue.type = COMP_RES;
yyval.cvalue.value.f = yyvsp[0].fvalue;
}break;case 9:#line 95 "netlist.y"{
yyval.cvalue.type = COMP_COMP;
printf ("\nnew component class:%s",yyvsp[0].svalue);
if (!(yyval.cvalue.value.class = get_class (yyvsp[0].svalue))) {
yyerror ("component not defined:%s", yyvsp[0].svalue );
YYERROR;
}
}break;case 12:#line 111 "netlist.y"{
node_start (yyvsp[0].svalue);
}break;case 13:#line 116 "netlist.y"{
node_end();
}break;case 16:#line 129 "netlist.y"{
int i = pin_map_str_str (yyvsp[-1].svalue, yyvsp[0].svalue);
if (i==-2 ){
yyerror ("Unknown component:%s\n", yyvsp[-1].svalue );
YYERROR;
}else if (i<0 ){
yyerror ("Unknown pin <%s> for component:%s\n", yyvsp[0].svalue, yyvsp[-1].svalue );
YYERROR;
}else
node_add_pin (i);
}break;case 17:#line 141 "netlist.y"{
int i = pin_map_str_pin (yyvsp[-1].svalue, yyvsp[0].ivalue);
if (i==-2 ){
yyerror ("Unknown component:%s\n", yyvsp[-1].svalue );
YYERROR;
}else if (i<0 ){
yyerror ("Unknown pin <%d> for component:%s\n", yyvsp[0].ivalue, yyvsp[-1].svalue );
YYERROR;
}else
node_add_pin (i);
}break;#line 459 "y.tab.c" } yyssp -= yym; yystate = *yyssp; yyvsp -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) {#if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state 0 to\ state %d\n", YYPREFIX, YYFINAL);#endif yystate = YYFINAL; *++yyssp = YYFINAL; *++yyvsp = yyval; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0;#if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, YYFINAL, yychar, yys); }#endif } if (yychar == 0) goto yyaccept; goto yyloop; } if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym];#if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \to state %d\n", YYPREFIX, *yyssp, yystate);#endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate; *++yyvsp = yyval; goto yyloop;yyoverflow: yyerror("yacc stack overflow");yyabort: return (1);yyaccept: return (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -