CELLP open_f(CELLP args) // ファイルを開く { char type, fname[NAMELEN] = {0}; int i; FILE *lfp = NULL; NUMP np; STR mode; if (args->id != _CELL) { return error(NEA); } if (args->car->id != _ATOM) { return error(IAA); } getfname((STR)fname, (ATOMP)(args->car)); if ((args = args->cdr)->id != _CELL) { mode = (STR)"r"; } else if (args->car->id != _ATOM) { return error(IAA); } else { mode = ((ATOMP)(args->car))->name; } for (i = 3; i < NFILES; ++i) { if (fp[i].ptr == NULL) { switch (*mode) { case 'w': type = WRITEFILE; break; case 'a': type = APPENDFILE; break; default: type = READFILE; } if (*(mode+1) == 'b') { type |= BINF; } lfp = fopen(fname, modestr[type]); if (lfp == NULL) { return error(FNA); } fp[i].mode = type; fp[i].ptr = lfp; np = newnum(); ec; np->value.fix = (long)i; return (CELLP)np; } } return error(TMF); }
CELLP minus_f(CELLP args) { char c; NUMP np; if (args->id != _CELL) { return error(NEA); } if ((c = args->car->id) != _FIX && c != _FLT) { return error(IAN); } np = newnum(); ec; if (c == _FIX) { np->value.fix = ((NUMP)(args->car))->value.fix; } else { np->id = _FLT; np->value.flt = ((NUMP)(args->car))->value.flt; } if ((c = args->cdr->car->id) != _FIX && c != _FLT) { return error(IAN); } if (c == _FLT || np->id == _FLT) { np->id = _FLT; np->value.flt -= ((NUMP)(args->cdr->car))->value.flt; } else { np->value.fix -= ((NUMP)(args->cdr->car))->value.fix; } return (CELLP)np; }
void create() { for(i=0;i<4;i++) { temp=(node*)malloc(sizeof(node)); temp->right=temp->left=temp->down=temp->up=NULL; temp->data=0; if(i==0) head=temp; else { uend->down=temp; temp->up=uend; } e=temp; for(j=0;j<3;j++) { t=(node*)malloc(sizeof(node)); t->right=t->left=t->down=t->up=NULL; t->data=0; e->right=t; t->left=e; if(i!=0) { uend=uend->right; uend->down=t; t->up=uend; } e=t; } uend=temp; } temp=head; for(i=0;i<3;i++) temp=temp->right; rightm=temp; temp=head; for(i=0;i<3;i++) temp=temp->down; downm=temp; temp=head; newnum(); newnum(); }
// 現在の出力先ファイルのファイルディスクリプタを返す CELLP curout_f(CELLP arg) { NUMP np; int i; np = newnum(); ec; for (i = 0; i < NFILES; ++i) { if (cur_fpo == fp[i].ptr) { np->value.fix = (long)i; return (CELLP)np; } } return error(UNDEF); }
static CELLP setfirst(CELLP args, NUMP* npp) { NUM val; args = get1arg(args, &val); // 1番目(car)はvalに、2番目以降(cdr)はvalに収められる ec; *npp = newnum(); ec; if (val.id == _FIX) { (*npp)->value.fix = val.value.fix; } else { (*npp)->id = _FLT; (*npp)->value.flt = val.value.flt; } return args; }
CELLP sub1_f(CELLP arg) { char c; NUMP np; if (arg->id != _CELL) { return error(NEA); } if ((c = arg->car->id) != _FIX && c != _FLT) { return error(IAN); } np = newnum(); ec; if (c == _FIX) { np->value.fix = ((NUMP)(arg->car))->value.fix - 1; } else { np->id = _FLT; np->value.flt = ((NUMP)(arg->car))->value.flt - 1; } return (CELLP)np; }
void forUnroller(AstNode* nodep, AstNode* initp, AstNode* precondsp, AstNode* condp, AstNode* incp, AstNode* bodysp, const V3Number& numInit, AstNodeBiop* cmpInstrp, const V3Number& numStop, AstNodeBiop* incInstrp, const V3Number& numInc) { UINFO(4, " Unroll for var="<<numInit<<"; var<"<<numStop<<"; var+="<<numInc<<endl); UINFO(6, " cmpI "<<cmpInstrp<<endl); UINFO(6, " IncI "<<incInstrp<<endl); AstNode* stmtsp = NULL; if (initp) { initp->unlinkFrBack(); // Always a single statement; nextp() may be nodep // Don't add to list, we do it once, and setting loop index isn't needed as we're constant propagating it } if (precondsp) { precondsp->unlinkFrBackWithNext(); // cppcheck-suppress nullPointer // addNextNull deals with it stmtsp = stmtsp->addNextNull(precondsp); } if (bodysp) { bodysp->unlinkFrBackWithNext(); // cppcheck-suppress nullPointer // addNextNull deals with it stmtsp = stmtsp->addNextNull(bodysp); // Maybe null if no body } if (incp && !nodep->castGenFor()) { // Generates don't need to increment loop index incp->unlinkFrBackWithNext(); // cppcheck-suppress nullPointer // addNextNull deals with it stmtsp = stmtsp->addNextNull(incp); // Maybe null if no body } // Mark variable to disable some later warnings m_forVarp->usedLoopIdx(true); // If it's a While, then incp is already part of bodysp. V3Number loopValue(nodep->fileline(), m_forVarp->width()); // May differ in size from numInitp loopValue.opAssign(numInit); AstNode* newbodysp = NULL; ++m_statLoops; if (stmtsp) { int times = 0; while (1) { UINFO(8," Looping "<<loopValue<<endl); // if loopValue<valStop V3Number contin (nodep->fileline(), 1); cmpInstrp->numberOperate(contin, loopValue, numStop); if (contin.isEqZero()) { break; // Done with the loop } else { // Replace iterator values with constant. AstNode* oneloopp = stmtsp->cloneTree(true); m_varValuep = new AstConst(nodep->fileline(), loopValue); // Iteration requires a back, so put under temporary node if (oneloopp) { AstBegin* tempp = new AstBegin(oneloopp->fileline(),"[EditWrapper]",oneloopp); m_varModeReplace = true; tempp->stmtsp()->iterateAndNext(*this); m_varModeReplace = false; oneloopp = tempp->stmtsp()->unlinkFrBackWithNext(); tempp->deleteTree(); tempp=NULL; } if (m_generate) { string index = AstNode::encodeNumber(m_varValuep->toSInt()); string nname = m_beginName + "__BRA__" + index + "__KET__"; oneloopp = new AstBegin(oneloopp->fileline(),nname,oneloopp,true); } if (newbodysp) newbodysp->addNext(oneloopp); else newbodysp = oneloopp; ++m_statIters; if (++times > unrollCount()*3) { nodep->v3error("Loop unrolling took too long; probably this is an infinite loop, or set --unroll-count above "<<unrollCount()); break; } //loopValue += valInc V3Number newnum(nodep->fileline(), m_forVarp->width()); // Can't increment in-place incInstrp->numberOperate(newnum, loopValue, numInc); loopValue.opAssign(newnum); pushDeletep(m_varValuep); m_varValuep=NULL; } } } // Replace the FOR() if (newbodysp) nodep->replaceWith(newbodysp); else nodep->unlinkFrBack(); if (bodysp) { pushDeletep(bodysp); bodysp=NULL; } if (precondsp) { pushDeletep(precondsp); precondsp=NULL; } if (initp) { pushDeletep(initp); initp=NULL; } if (incp && !incp->backp()) { pushDeletep(incp); incp=NULL; } if (debug()>=9) newbodysp->dumpTree(cout,"- _new: "); }
int yyparse (void) { int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* The stacks and their tools: 'yyss': related to states. 'yyvs': related to semantic values. Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs; YYSTYPE *yyvsp; YYSIZE_T yystacksize; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; yyssp = yyss = yyssa; yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = yylex (); } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yytable_value_is_error (yyn)) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: #line 42 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newflow('I', (yyvsp[-2].a), (yyvsp[0].a), NULL); } #line 1267 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 3: #line 43 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newflow('I', (yyvsp[-4].a), (yyvsp[-2].a), (yyvsp[0].a)); } #line 1273 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 4: #line 44 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newflow('W', (yyvsp[-2].a), (yyvsp[0].a), NULL); } #line 1279 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 6: #line 48 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = NULL; } #line 1285 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 7: #line 49 "fb3-2.y" /* yacc.c:1646 */ { if ((yyvsp[0].a) == NULL) (yyval.a) = (yyvsp[-2].a); else (yyval.a) = newast('L', (yyvsp[-2].a), (yyvsp[0].a)); } #line 1295 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 8: #line 56 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newcmp((yyvsp[-1].fn), (yyvsp[-2].a), (yyvsp[0].a)); } #line 1301 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 9: #line 57 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('+', (yyvsp[-2].a),(yyvsp[0].a)); } #line 1307 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 10: #line 58 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('-', (yyvsp[-2].a),(yyvsp[0].a));} #line 1313 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 11: #line 59 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('*', (yyvsp[-2].a),(yyvsp[0].a)); } #line 1319 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 12: #line 60 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('/', (yyvsp[-2].a),(yyvsp[0].a)); } #line 1325 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 13: #line 61 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('|', (yyvsp[0].a), NULL); } #line 1331 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 14: #line 62 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = (yyvsp[-1].a); } #line 1337 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 15: #line 63 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('M', (yyvsp[0].a), NULL); } #line 1343 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 16: #line 64 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newnum((yyvsp[0].d)); } #line 1349 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 17: #line 65 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newfunc((yyvsp[-3].fn), (yyvsp[-1].a)); } #line 1355 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 18: #line 66 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newref((yyvsp[0].s)); } #line 1361 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 19: #line 67 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newasgn((yyvsp[-2].s), (yyvsp[0].a)); } #line 1367 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 20: #line 68 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newcall((yyvsp[-3].s), (yyvsp[-1].a)); } #line 1373 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 22: #line 72 "fb3-2.y" /* yacc.c:1646 */ { (yyval.a) = newast('L', (yyvsp[-2].a), (yyvsp[0].a)); } #line 1379 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 23: #line 74 "fb3-2.y" /* yacc.c:1646 */ { (yyval.sl) = newsymlist((yyvsp[0].s), NULL); } #line 1385 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 24: #line 75 "fb3-2.y" /* yacc.c:1646 */ { (yyval.sl) = newsymlist((yyvsp[-2].s), (yyvsp[0].sl)); } #line 1391 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 26: #line 80 "fb3-2.y" /* yacc.c:1646 */ { if(debug) dumpast((yyvsp[-1].a), 0); printf("= %4.4g\n> ", eval((yyvsp[-1].a))); treefree((yyvsp[-1].a)); } #line 1401 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 27: #line 85 "fb3-2.y" /* yacc.c:1646 */ { dodef((yyvsp[-6].s), (yyvsp[-4].sl), (yyvsp[-1].a)); printf("Defined %s\n> ", (yyvsp[-6].s)->name); } #line 1409 "fb3-2.tab.c" /* yacc.c:1646 */ break; case 28: #line 89 "fb3-2.y" /* yacc.c:1646 */ { yyerrok; printf("> "); } #line 1415 "fb3-2.tab.c" /* yacc.c:1646 */ break; #line 1419 "fb3-2.tab.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. One alternative is translating here after every semantic action, but that translation would be missed if the semantic action invokes YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an incorrect destructor might then be invoked immediately. In the case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) { char const *yymsgp = YY_("syntax error"); int yysyntax_error_status; yysyntax_error_status = YYSYNTAX_ERROR; if (yysyntax_error_status == 0) yymsgp = yymsg; else if (yysyntax_error_status == 1) { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); if (!yymsg) { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; yysyntax_error_status = 2; } else { yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; } } yyerror (yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } # undef YYSYNTAX_ERROR #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif return yyresult; }
void main() { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int left, top, right, bottom; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, "E:\TC\BGI"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } cleardevice(); create(); /*temp=head; temp=temp->down; for(i=0;i<3;i++) temp=temp->right; temp->data=2; temp=head; temp=temp->down->down; temp=temp->right; temp->data=2; */ setcolor(5); setlinestyle(1,1,3); line(250,100,50,200); line(50,200,250,225); line(250,225,25,325); line(500,100,300,200); line(300,200,500,225); line(500,225,275,325); settextstyle(1,0,6); outtextxy(150,375,"PRESENTS"); getch(); cleardevice(); settextstyle(1,0,6); outtextxy(150,150,"MYSTERIES"); outtextxy(190,250,"OF"); outtextxy(170,350,"1024"); getch(); cleardevice(); setcolor(15); settextstyle(0,0,1); sprintf(s,"RULES=>"); outtextxy(5,5,s); sprintf(s,"You Have To Create The Number 1024"); outtextxy(5,20,s); sprintf(s,"Use arrow Keys to Move"); outtextxy(5,35,s); sprintf(s,"Press N At Any Point To Quit..."); outtextxy(5,45,s); sprintf(s,"Are You Ready...."); outtextxy(5,60,s); getch(); cleardevice(); display(); while(k==0) { y=0; display(); sprintf(s,"Enter Your Move"); outtextxy(5,5,s); ch=getch(); switch(ch) { case 72: move='W'; break; case 80: move='S'; break; case 77: move='D'; break; case 75: move='A'; break; case 'n': k=1; break; default: y=1; } if(k==1) { outtextxy(5,25,"Thanks for playing....."); break; } if(y==1) { outtextxy(5,25,"Wrong Move...."); } else { movem(); // display(); // getch(); check(); movem(); newnum(); k=final_check(); display(); } if(k==2) outtextxy(5,25,"congratulation!!!!! You Have WON THE GAME..."); if(k==1) outtextxy(55,25,"SORRY!!! GAME OVER"); } getch(); //getch(); //getch(); closegraph(); }
TOKEN *gettok() { TOKEN *t; if (t = tokenstack) { tokenstack = t->next; return t; } t = (TOKEN *) malloc(sizeof(TOKEN)); while (*ptr == ' ' || *ptr == '\t') ++ptr; if (!*ptr) { t->type = tEOF; return t; } if (ptr[0] == '^') { ++ptr; t->type = tINFIX; t->sym = yEXP; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '*' && ptr[1] == '*') { ++ptr; ++ptr; t->type = tINFIX; t->sym = yEXP; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '*') { ++ptr; t->type = tINFIX; t->sym = yMUL; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '/') { ++ptr; t->type = tINFIX; t->sym = yDIV; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '+') { ++ptr; t->type = tINFIX; t->sym = yADD; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '=') { ++ptr; t->type = tINFIX; t->sym = yEQ; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '-') { ++ptr; t->type = tINFIX; t->sym = ySUB; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == '(') { ++ptr; t->type = tLPAREN; return t; } if (ptr[0] == ')') { ++ptr; t->type = tRPAREN; return t; } if (ptr[0] == '!') { ++ptr; t->type = tPOSTFIX; t->sym = yFACT; t->prec = t->sym->prec; return t; } if (ptr[0] == ',') { ++ptr; t->type = tCOMMA; return t; } if (ptr[0] == '\'') { ++ptr; t->type = tPOSTFIX; t->sym = yDERV; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (ptr[0] == 'D') { ++ptr; t->type = tPREFIX; t->sym = yD; t->ass = t->sym->ass; t->prec = t->sym->prec; return t; } if (*ptr >= '0' && *ptr <= '9' || *ptr == '.') { t->type = tNUM; t->num = newnum(0.0); sscanf(ptr, "%lf", &t->num->n); while (*ptr >= '0' && *ptr <= '9' || *ptr == '.' || *ptr == 'e' || *ptr == 'E') ++ptr; return t; } if (*ptr >= 'a' && *ptr <= 'z' || *ptr >= 'A' && *ptr <= 'Z' || *ptr == '_' || *ptr == '%') { C *s = ptr, o; while (*ptr >= 'a' && *ptr <= 'z' || *ptr >= 'A' && *ptr <= 'Z' || *ptr == '_' || *ptr == '%' || *ptr >= '0' && *ptr <= '9') ++ptr; o = *ptr; *ptr = 0; t->type = tSYM; if (!(t->sym = lookup(s))) t->sym = add(s); *ptr = o; return t; } t->type = tUNKNOWN; return t; }