#include #ifndef lint #if 0 static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; #else __IDSTRING(yyrcsid, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $"); #endif #endif #include #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) #define YYPREFIX "yy" #line 81 "exp.y" #include #include #include #include #include #include #include "export.h" #ifndef NULL #define NULL 0 #endif #define NEST_MAX 15 /*--------------------------- Function prototypes --------------------------*/ Record *GetRecord PRM( (char *); ) Field *GetField PRM( (Structdef *, char *); ) Structdef *GetStruct PRM( (Structdef *, char *); ) /*---------------------------- Global variables ----------------------------*/ static Record *cur_rec = NULL; /* Current record */ static Field *cur_fld = NULL; /* Current field */ static Structdef *cur_str = NULL; /* Current structure */ static Structdef *strnest[NEST_MAX]; /* Pointers to structures */ static int cur_nest = -1; /* Current nesting */ #line 110 "exp.y" typedef union { char s[IDENT_LEN+1]; } YYSTYPE; #line 52 "y.tab.c" #define T_EXPORT 257 #define T_RECORD 258 #define T_STRUCT 259 #define T_UNION 260 #define T_IN 261 #define T_IDENT 262 #define T_STRING 263 #define YYERRCODE 256 short yylhs[] = { -1, 0, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 7, }; short yylen[] = { 2, 5, 1, 2, 4, 4, 1, 2, 2, 5, 2, 1, 1, }; short yydefred[] = { 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 3, 0, 0, 11, 12, 0, 0, 6, 0, 0, 5, 8, 4, 7, 0, 10, 0, 0, 9, }; short yydgoto[] = { 2, 6, 7, 8, 17, 18, 19, 20, }; short yysindex[] = { -255, -253, 0, -116, -248, -250, -122, 0, -110, -247, 0, 0, -254, -246, 0, 0, -44, -125, 0, -107, -244, 0, 0, 0, 0, -254, 0, -121, -40, 0, }; short yyrindex[] = { 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, }; short yygindex[] = { 0, 0, 14, 0, -4, -16, 0, 0, }; #define YYTABLESIZE 141 short yytable[] = { 23, 24, 1, 10, 28, 14, 15, 4, 16, 3, 5, 24, 9, 12, 13, 22, 25, 21, 26, 29, 11, 27, 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, 14, 15, 5, 16, 14, 15, 0, 16, }; short yycheck[] = { 125, 17, 257, 125, 125, 259, 260, 123, 262, 262, 258, 27, 262, 123, 261, 59, 123, 263, 262, 59, 6, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 259, 260, 258, 262, 259, 260, -1, 262, }; #define YYFINAL 2 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 263 #if YYDEBUG char *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,"T_EXPORT","T_RECORD", "T_STRUCT","T_UNION","T_IN","T_IDENT","T_STRING", }; char *yyrule[] = { "$accept : export_spec", "export_spec : T_EXPORT T_IDENT '{' record_list '}'", "record_list : record", "record_list : record_list record", "record : record_head '{' field_list '}'", "record_head : T_RECORD T_IDENT T_IN T_STRING", "field_list : field", "field_list : field_list field", "field : T_IDENT ';'", "field : struct_head '{' field_list '}' ';'", "struct_head : struct_or_union T_IDENT", "struct_or_union : T_STRUCT", "struct_or_union : T_UNION", }; #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 200 int yydebug; int yynerrs; int yyerrflag; int yychar; short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; short *yyss; short *yysslim; YYSTYPE *yyvs; int yystacksize; #line 178 "exp.y" #include extern errors; yyerror(char *fmt ELLIPSIS) { va_list ap; printf("%s %d: ", spec_fname, lex_lineno); va_start(ap, fmt); vprintf(fmt, ap); puts(""); va_end(ap); errors++; return 0; } Record *GetRecord(name) char *name; { int i; for( i=0; ifirst_member]; int n = str->members; while( n ) { if( fld->nesting == cur_nest ) { if( !strcmp(fld->name, name) ) { fld->type |= FT_INCLUDE; return fld; } n--; } fld++; } yyerror("'%s' is not a member of '%s'", name, str->name); exit(1); return NULL; } Structdef *GetStruct(str, name) Structdef *str; char *name; { Field *fld; Structdef *struc; if( !(fld = GetField(str, name)) || FT_GETBASIC(fld->type) != FT_STRUCT ) return NULL; struc = &dbd.structdef[fld->structid]; /* If the structure is a union the control field must also have been * specified */ if( struc->is_union ) { if( !(dbd.field[struc->control_field].type & FT_INCLUDE) ) { yyerror("The control field of the union '%s' is not included", name); exit(1); } } return struc; } /* end-of-file */ #line 278 "y.tab.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ int yyparse __P((void)); static int yygrowstack __P((void)); 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; if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL) return -1; yyss = newss; yyssp = newss + i; if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *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 int yyparse() { int yym, yyn, yystate; #if YYDEBUG char *yys; if ((yys = getenv("YYDEBUG")) != NULL) { 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]) != 0) 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; goto yynewerror; yynewerror: yyerror("syntax error"); goto yyerrlab; yyerrlab: ++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 4: #line 130 "exp.y" { cur_nest--; } break; case 5: #line 136 "exp.y" { if( cur_rec = GetRecord(yyvsp[-2].s) ) { cur_rec->aux = 1; cur_str = &dbd.structdef[cur_rec->structid]; } else cur_str = NULL; strnest[++cur_nest] = cur_str; } break; case 8: #line 153 "exp.y" { if( cur_str ) cur_fld = GetField(cur_str, yyvsp[-1].s); } break; case 9: #line 159 "exp.y" { cur_str = strnest[--cur_nest]; } break; case 10: #line 165 "exp.y" { if( cur_str ) cur_str = GetStruct(cur_str, yyvsp[0].s); strnest[++cur_nest] = cur_str; } break; #line 484 "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); }