#ifndef lint static char const yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $"; #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) static int yygrowstack(); #define YYPREFIX "yy" #line 30 "ejsc_parser.y" #define MAXVARS 16 #define MAXARGLISTS 8 #define MAXSYMS 300 /* Keep up with linenumbers */ int yylineno=1; /* Index constructions to generate evalIds */ int evalIndex=0; /* Error "handling" */ int yyerror(char *s) { fprintf(stderr, "%s\n", s); fflush(stderr); return 0; } /* Get first non-null index in tVariable array */ int first_null_index(tVariable *vp) { int i; for (i=0 ; i #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 512 "ejsc_parser.y" #include "ejsc_lexer.c" #line 409 "ejsc_parser.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 */ int yyparse (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; #endif yynewerror: yyerror("syntax error"); #if defined(lint) || defined(__GNUC__) goto yyerrlab; #endif 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 2: #line 248 "ejsc_parser.y" { tIdentifier name; int i; static int cnum=1; /* Number of construction */ static int lastlineno=0; /* Line number when last time visiting */ /* Generate unique name */ if ( yylineno != lastlineno ) { cnum = 1; lastlineno = yylineno; } name = (tIdentifier)malloc(32*sizeof(char)); sprintf(name, "line_%d_construction_%d", yylineno, cnum++); i = append_symbol_to_current(name, yyvsp[-2].vp); (*(yyvsp[-2].vp)).scope = (*currentSym).symTable[i]; /* In case of function definition, fix name */ if ( ((*((*currentSym).symTable[i])).symTSize != 0) && ((*(*((*currentSym).symTable[i])).symValue).type == tOb) ) { /* free((*currentSym).symTable[i].symName);*/ (*((*currentSym).symTable[i])).symName = (*(*((*currentSym).symTable[i])).symValue).value.o.objName; } #ifdef EJSCCDEBUG if ( ejsccdebug ) { printf("ejsccdebug: Assigned to '%s'.\n", name); fflush(stdout); } #endif } break; case 3: #line 276 "ejsc_parser.y" { int i; i = append_symbol_to_current(yyvsp[-3].v.value.s, yyvsp[-1].vp); (*(yyvsp[-1].vp)).scope = (*currentSym).symTable[i]; #ifdef EJSCCDEBUG if ( ejsccdebug ) { printf("ejsccdebug: Assigned to '%s'.\n", yyvsp[-3].v.value.s); fflush(stdout); } #endif } break; case 7: #line 296 "ejsc_parser.y" { tVariable *val; int ***tmp_eval; int i,j,k; /* Allocate memory */ val = (tVariable *)malloc(sizeof(tVariable)); /* Create construction object */ (*val).type = tOb; (*val).evalId = evalIndex; evalIndex += EVALIDSTEP; /* Unique id*/ (*val).value.o.objName = yyvsp[-3].v.value.s; /* Name*/ /* Allocate memory for return values and reset them */ (*val).value.o.returnValues = (char **)malloc(MAXSYMS * sizeof(char *)); memset((*val).value.o.returnValues, (int)NULL, MAXSYMS * sizeof(char *)); /* Decide type. Existing codeblock means definition */ if ( yyvsp[0].b == true ) { (*val).value.o.type = Definition; } else { (*val).value.o.type = Object; } /* Evaluation id's to keep track on the need of re-evaluation of arguments */ (*val).value.o.arguments = yyvsp[-2].vpp; /* Argument list */ tmp_eval = (*val).value.o.argumentEvalId = (int ***)malloc(MAXARGLISTS * sizeof(int **)); for ( i=0 ; i MAXARGLISTS-1 ) { /* FIXME: realloc */ yyerror("Error. Too many attributelists.\n"); } else { yyval.vpp = yyvsp[-3].vpp; yyval.vpp[i] = yyvsp[-1].vp; } } break; case 9: #line 360 "ejsc_parser.y" { int size = MAXARGLISTS; int i; #ifdef EJSCCDEBUG if ( ejsccdebug ) { printf("ejsccdebug: Argument list found.\n"); fflush(stdout); } #endif yyval.vpp = (tVariable **)malloc(size * sizeof(tVariable *)); for (i=0 ; i MAXVARS-1 ) { /* FIXME: realloc */ yyerror("Error. Too many attributes.\n"); } else { yyval.vp = yyvsp[-2].vp; yyval.vp[i] = (*(yyvsp[0].vp)); } } break; case 11: #line 386 "ejsc_parser.y" { int size = MAXVARS; int i; yyval.vp = (tVariable *)malloc(size * sizeof(tVariable)); /* Set all variables to 'nullVar' */ for (i=0 ; i MAXVARS-1 ) { /* FIXME: realloc */ fprintf(stderr, "Fatal error: Too many formats on line %d.\n", yylineno); exit(1); } else { yyval.vp = yyvsp[-2].vp; yyval.vp[i] = (*(yyvsp[0].vp)); } } break; case 21: #line 444 "ejsc_parser.y" { int size = MAXVARS; int i; yyval.vp = (tVariable *)malloc(size * sizeof(tVariable)); /* Set all variables to 'nullVar' */ for (i=0 ; i$ = (tVariable*)malloc(sizeof(tVariable)); (*($$)) = $2; */ yyval.vp = &yyvsp[-1].v; } break; case 24: #line 466 "ejsc_parser.y" { int ***tmp_eval; int i,j,k; #ifdef EJSCCDEBUG if ( ejsccdebug ) { printf("ejsccdebug: Format call '%s' found.\n", yyvsp[-3].v.value.d); fflush(stdout); } #endif yyval.v.type = tOb; yyval.v.value.o.objName = yyvsp[-3].v.value.d; yyval.v.value.o.type = Format; /* Allocate memory for argument lists */ yyval.v.value.o.arguments = (tVariable**)malloc(2*sizeof(tVariable*)); yyval.v.value.o.arguments[0] = yyvsp[-1].vp; yyval.v.value.o.arguments[1] = NULL; tmp_eval = yyval.v.value.o.argumentEvalId = (int ***)malloc(2 * sizeof(int **)); for ( i=0 ; i<2 ; i++ ) { tmp_eval[i] = (int **)malloc(MAXVARS * sizeof(int*)); for ( j=0 ; j= 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); }