这篇教程C++ yyerror函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中yyerror函数的典型用法代码示例。如果您正苦于以下问题:C++ yyerror函数的具体用法?C++ yyerror怎么用?C++ yyerror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了yyerror函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: outcode//.........这里部分代码省略......... case BRACE: outcode(c0, eflag); break; case COUNT: emitf(Xmark); outcode(c0, eflag); emitf(Xcount); break; case FN: emitf(Xmark); outcode(c0, eflag); if(c1){ emitf(Xfn); p = emiti(0); emits(fnstr(c1)); outcode(c1, eflag); emitf(Xunlocal); /* get rid of $* */ emitf(Xreturn); stuffdot(p); } else emitf(Xdelfn); break; case IF: outcode(c0, 0); emitf(Xif); p = emiti(0); outcode(c1, eflag); emitf(Xwastrue); stuffdot(p); break; case NOT: if(!runq->iflast) yyerror("`if not' does not follow `if(...)'"); emitf(Xifnot); p = emiti(0); outcode(c0, eflag); stuffdot(p); break; case OROR: outcode(c0, 0); emitf(Xfalse); p = emiti(0); outcode(c1, eflag); stuffdot(p); break; case PAREN: outcode(c0, eflag); break; case SIMPLE: emitf(Xmark); outcode(c0, eflag); emitf(Xsimple); if(eflag) emitf(Xeflag); break; case SUBSHELL: emitf(Xsubshell); if(havefork){ p = emiti(0); outcode(c0, eflag); emitf(Xexit); stuffdot(p); } else emits(fnstr(c0)); if(eflag)
开发者ID:00001,项目名称:plan9port,代码行数:67,
示例2: eval_routine data eval_routine(routineNode rout, symrec ** symTable, list * routineList){ data res; //recupera la routine e controlla se esiste routine * r = getRoutine(rout.name, routineList); if(r==NULL){ yyerror("accessing unexisting procedure or function.."); exit(NO_SUCH_PROCEDURE); } //dalla routine prendi gli i parametri form * forms; forms = r->parameters; //dal nodo passato prendi gli argomenti actual * aes; aes = rout.args; //HERE HAPPENS typechecking //we do minimal typechecking on length - the rest is left as exercise int flen = formLength(forms); int alen = actLength(aes); if(flen!=alen){ yyerror("args len is different from formal length"); } //qui fai il bind tra parametri e argomenti, mettendoli nella symbol TABLE // da ripassare a tutta la funzione di eval, usando il nodo expr come funzione di partenza symrec * rSymrec; rSymrec = NULL; for(int i = 0; i< flen; i++){ form * f = getFormAtIndex(i,forms); if(f == NULL){ //TODO place here the number of forms already used yyerror("execeed form list"); exit(FORM_LIST_EXCEEDED); } actual * a = getActualAtIndex(i,aes); if (a == NULL){ //TODO place here the number of args already used yyerror("execeed args list"); exit(ARGS_LIST_EXCEEDED); } //eseguo dichiarazione e assegnazione nella symbol table che userà la routine type * t = basicDec(f->bt); //TODO: considered only basic type treeNode * dec = varDec(f->name,false,t); eval_identifier_declaration(dec->value.dec,&rSymrec,routineList); //cerca la var appena inserita e fai l'assignement identifier id; id.name = malloc(strlen(f->name)+1); strcpy(id.name,f->name); if (f->byref){ if (a->expr->type != identifier_type){ yyerror("incompatible arg for pass by ref"); exit(ARGS_LIST_EXCEEDED); } symrec * tmp = getSymbolFromIdentifier(id,&rSymrec); symrec * tmp2 = getSymbolFromIdentifier(a->expr->value.id, symTable); tmp->value = tmp2->value; } else { //eval expr in current env, then assign it symrec * tmp = getSymbolFromIdentifier(id,&rSymrec); data e = eval(a->expr, symTable,routineList); spec_assignment(tmp,e, &rSymrec, routineList); } // printf("%s", ); } //eventually with return res = eval... eval(r->statementList, &rSymrec,routineList); if(r->type == procedure){ res.type = no_op; }else{ //qui cerca nella routine, nel suo return value il valore, puliscilo e resituicilo res = *r->returnValue; r->returnValue = NULL; } return res;}
开发者ID:simonacca,项目名称:LFC-PROJ,代码行数:79,
示例3: mpatofix//// fixed point input// required syntax is [+-][0[x]]d*//voidmpatofix(Mpint *a, char *as){ int c, f; char *s; s = as; f = 0; mpmovecfix(a, 0); c = *s++; switch(c) { case '-': f = 1; case '+': c = *s++; if(c != '0') break; case '0': goto oct; } while(c) { if(c >= '0' && c <= '9') { mpmulcfix(a, 10); mpaddcfix(a, c-'0'); c = *s++; continue; } goto bad; } goto out;oct: c = *s++; if(c == 'x' || c == 'X') goto hex; while(c) { if(c >= '0' && c <= '7') { mpmulcfix(a, 8); mpaddcfix(a, c-'0'); c = *s++; continue; } goto bad; } goto out;hex: c = *s++; while(c) { if(c >= '0' && c <= '9') { mpmulcfix(a, 16); mpaddcfix(a, c-'0'); c = *s++; continue; } if(c >= 'a' && c <= 'f') { mpmulcfix(a, 16); mpaddcfix(a, c+10-'a'); c = *s++; continue; } if(c >= 'A' && c <= 'F') { mpmulcfix(a, 16); mpaddcfix(a, c+10-'A'); c = *s++; continue; } goto bad; }out: if(f) mpnegfix(a); return;bad: yyerror("set ovf in mpatov: %s", as); mpmovecfix(a, 0);}
开发者ID:Ahmah2009,项目名称:golang,代码行数:87,
示例4: typecheckrangevoidtypecheckrange(Node *n){ char *why; Type *t, *t1, *t2; Node *v1, *v2; NodeList *ll; // delicate little dance. see typecheckas2 for(ll=n->list; ll; ll=ll->next) if(ll->n->defn != n) typecheck(&ll->n, Erv | Easgn); typecheck(&n->right, Erv); if((t = n->right->type) == T) goto out; if(isptr[t->etype] && isfixedarray(t->type)) t = t->type; n->type = t; switch(t->etype) { default: yyerror("cannot range over %lN", n->right); goto out; case TARRAY: t1 = types[TINT]; t2 = t->type; break; case TMAP: t1 = t->down; t2 = t->type; break; case TCHAN: if(!(t->chan & Crecv)) { yyerror("invalid operation: range %N (receive from send-only type %T)", n->right, n->right->type); goto out; } t1 = t->type; t2 = nil; if(count(n->list) == 2) goto toomany; break; case TSTRING: t1 = types[TINT]; t2 = runetype; break; } if(count(n->list) > 2) { toomany: yyerror("too many variables in range"); } v1 = n->list->n; v2 = N; if(n->list->next) v2 = n->list->next->n; if(v1->defn == n) v1->type = t1; else if(v1->type != T && assignop(t1, v1->type, &why) == 0) yyerror("cannot assign type %T to %lN in range%s", t1, v1, why); if(v2) { if(v2->defn == n) v2->type = t2; else if(v2->type != T && assignop(t2, v2->type, &why) == 0) yyerror("cannot assign type %T to %lN in range%s", t2, v2, why); }out: typechecklist(n->nbody, Etop); // second half of dance n->typecheck = 1; for(ll=n->list; ll; ll=ll->next) if(ll->n->typecheck == 0) typecheck(&ll->n, Erv | Easgn);}
开发者ID:Alfalfamale,项目名称:robvdhout-go,代码行数:82,
示例5: operation //We assume here typechecking has already happened data operation(int oper, data e1, data e2){ data res; basic b; //pointer to a funcion that takes two int input and return an int int (*funIntPtr)(int,int); float (*funFloatPtr)(float,float); bool (*funBoolFloatPrt)(float,float); bool (*funBoolIntPrt)(int,int); bool (*funBoolPtr)(bool,bool); funIntPtr = NULL; funFloatPtr= NULL; funBoolFloatPrt = NULL; funBoolIntPrt = NULL; //I look for the function to be called switch (oper) { case MINUS: //*functionPtr = &subInt; switch (e1.b.type) { case basic_int_value:funIntPtr = subInt;break; case basic_float_value:funFloatPtr = subFloat;break; case basic_boolean_value: yyerror("boolean arithmetic operation are NOT_ALLOWED"); exit(NOT_ALLOWED); break; case undef: default: yyerror("operation unmanaged type..."); exit(BUGGY_THE_CLOWN); break; } break; case PLUS : switch (e1.b.type) { case basic_int_value:funIntPtr = addInt;break; case basic_float_value:funFloatPtr = addFloat;break; case basic_boolean_value: yyerror("boolean arithmetic operation are NOT_ALLOWED"); exit(NOT_ALLOWED); break; case undef: default: yyerror("operation unmanaged type..."); exit(BUGGY_THE_CLOWN); break; } break; case MULTIPLY: switch (e1.b.type) { case basic_int_value:funIntPtr = mulInt;break; case basic_float_value:funFloatPtr = mulFloat;break; case basic_boolean_value: yyerror("boolean arithmetic operation are NOT_ALLOWED"); exit(NOT_ALLOWED); break; case undef: default: yyerror("operation unmanaged type..."); exit(BUGGY_THE_CLOWN); break; } break; case DIVIDE : switch (e1.b.type) { case basic_int_value:funIntPtr = divInt;break; case basic_float_value:funFloatPtr = divFloat;break; case basic_boolean_value: yyerror("boolean arithmetic operation are NOT_ALLOWED"); exit(NOT_ALLOWED); break; case undef: default: yyerror("operation unmanaged type..."); exit(BUGGY_THE_CLOWN); break; } break; case LT : { switch (e1.b.type) { case basic_int_value:funBoolIntPrt = ltInt;break; case basic_float_value:funBoolFloatPrt = ltFloat;break; case basic_boolean_value: yyerror("boolean arithmetic operation are NOT_ALLOWED"); exit(NOT_ALLOWED); break; case undef: default: yyerror("operation unmanaged type..."); exit(BUGGY_THE_CLOWN); break; } } break; case GT : {switch (e1.b.type) { case basic_int_value:funBoolIntPrt = gtInt;break; case basic_float_value:funBoolFloatPrt = gtFloat;break; case basic_boolean_value://.........这里部分代码省略.........
开发者ID:simonacca,项目名称:LFC-PROJ,代码行数:101,
示例6: add_object_sectionsint add_object_sections(NAME_LIST *section_name_list){ OBJECT_FILE **current; Elf_Scn *elf_section; Elf32_Shdr *shdr; NAME_LIST *section_name; Elf_Scn **array; int scns_available; int scns_added; array_index_t link_index; int page_links; const char *input_name; scns_added = scns_available = 0; array = NULL; array_index_init( &link_index, &link_array ); current = (OBJECT_FILE **)array_index_next_page( &link_index, &page_links ); while (current) { elf_section = NULL; while ((elf_section = elf_nextscn((*current)->elf, elf_section)) != 0) { shdr = elf32_getshdr(elf_section); elfcheck( shdr != NULL ); if ( shdr->sh_type == SHT_PROGBITS || shdr->sh_type == SHT_NOBITS ) { input_name = (*current)->strings+shdr->sh_name; for ( section_name = section_name_list ; section_name ; section_name = section_name->next ) { if (strcmp( input_name, section_name->name) == 0) { if ((shdr->sh_flags & SHF_REFERENCED) == 0) { if ( scns_added >= scns_available ) { array_update( &scn_array, scns_added ); scns_added = 0; array = array_alloc( &scn_array, &scns_available ); } *array++ = elf_section; ++scns_added;// elf_flagshdr( elf_section, ELF_C_SET, SHF_REFERENCED ); shdr->sh_flags |= SHF_REFERENCED; } else { yyerror( "Input section is referenced twice" ); } break; } } } } ++current; if ( --page_links == 0 ) { current = (OBJECT_FILE **)array_index_next_page( &link_index, &page_links ); } } array_update( &scn_array, scns_added ); return 1;}
开发者ID:wodz,项目名称:open21xx,代码行数:67,
示例7: yyparse/*** yyparse - return 0 if worked, 1 if syntax error not recovered from*/intyyparse(){ register YYSTYPE *yypvt; /* top of value stack for $vars */ unsigned yymaxdepth = YYMAXDEPTH; /* ** Initialize externals - yyparse may be called more than once */ yyv = (YYSTYPE*)malloc(yymaxdepth*sizeof(YYSTYPE)); yys = (int*)malloc(yymaxdepth*sizeof(int)); if (!yyv || !yys) { yyerror( "out of memory" ); return(1); } yypv = &yyv[-1]; yyps = &yys[-1]; yystate = 0; yytmp = 0; yynerrs = 0; yyerrflag = 0; yychar = -1; goto yystack; { register YYSTYPE *yy_pv; /* top of value stack */ register int *yy_ps; /* top of state stack */ register int yy_state; /* current state */ register int yy_n; /* internal state number info */ /* ** get globals into registers. ** branch to here only if YYBACKUP was called. */ yynewstate: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; goto yy_newstate; /* ** get globals into registers. ** either we just started, or we just finished a reduction */ yystack: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; /* ** top of for (;;) loop while no reductions done */ yy_stack: /* ** put a state and value onto the stacks */#if YYDEBUG /* ** if debugging, look up token value in list of value vs. ** name pairs. 0 and negative (-1) are special values. ** Note: linear search is used since time is not a real ** consideration while debugging. */ if ( yydebug ) { register int yy_i; (void)printf( "State %d, token ", yy_state ); if ( yychar == 0 ) (void)printf( "end-of-file/n" ); else if ( yychar < 0 ) (void)printf( "-none-/n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } (void)printf( "%s/n", yytoks[yy_i].t_name ); } }#endif /* YYDEBUG */ if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */ { /* ** reallocate and recover. Note that pointers ** have to be reset, or bad things will happen */ int yyps_index = (yy_ps - yys); int yypv_index = (yy_pv - yyv); int yypvt_index = (yypvt - yyv); yymaxdepth += YYMAXDEPTH; yyv = (YYSTYPE*)realloc((char*)yyv, yymaxdepth * sizeof(YYSTYPE));//.........这里部分代码省略.........
开发者ID:Akagi201,项目名称:learning-lua,代码行数:101,
示例8: IsCf3Scalarstatic int IsCf3Scalar(char *str){ char *sp; char left = 'x', right = 'x'; int dollar = false; int bracks = 0, vars = 0; CfDebug("IsCf3Scalar(%s) - syntax verify/n", str); if (str == NULL) { return false; } for (sp = str; *sp != '/0'; sp++) /* check for varitems */ { switch (*sp) { case '$': if (*(sp + 1) == '{' || *(sp + 1) == '(') { dollar = true; } break; case '(': case '{': if (dollar) { left = *sp; bracks++; } break; case ')': case '}': if (dollar) { bracks--; right = *sp; } break; } /* Some chars cannot be in variable ids, e.g. $(/bin/cat file) is legal in bash */ if (bracks > 0) { switch (*sp) { case '/': return false; } } if (left == '(' && right == ')' && dollar && (bracks == 0)) { vars++; dollar = false; } if (left == '{' && right == '}' && dollar && (bracks == 0)) { vars++; dollar = false; } } if (dollar && (bracks != 0)) { char output[CF_BUFSIZE]; snprintf(output, CF_BUFSIZE, "Broken scalar variable syntax or bracket mismatch in /"%s/"", str); yyerror(output); return false; } CfDebug("Found %d variables in (%s)/n", vars, str); return vars;}
开发者ID:joegen,项目名称:sipx-externals,代码行数:79,
示例9: CfDebugconst char *ExtractInnerCf3VarString(const char *str, char *substr){ const char *sp; int bracks = 1; CfDebug("ExtractInnerVarString( %s ) - syntax verify/n", str); if (str == NULL || strlen(str) == 0) { return NULL; } memset(substr, 0, CF_BUFSIZE); if (*(str + 1) != '(' && *(str + 1) != '{') { return NULL; }/* Start this from after the opening $( */ for (sp = str + 2; *sp != '/0'; sp++) /* check for varitems */ { switch (*sp) { case '(': case '{': bracks++; break; case ')': case '}': bracks--; break; default: if (isalnum((int) *sp) || strchr("_[]$.:-", *sp)) { } else { CfDebug("Illegal character found: '%c'/n", *sp); CfDebug("Illegal character somewhere in variable /"%s/" or nested expansion", str); } } if (bracks == 0) { strncpy(substr, str + 2, sp - str - 2); CfDebug("Returning substring value %s/n", substr); return substr; } } if (bracks != 0) { char output[CF_BUFSIZE]; if (strlen(substr) > 0) { snprintf(output, CF_BUFSIZE, "Broken variable syntax or bracket mismatch - inner (%s/%s)", str, substr); yyerror(output); } return NULL; } return sp - 1;}
开发者ID:joegen,项目名称:sipx-externals,代码行数:67,
示例10: pragvarargvoidpragvararg(void){ Sym *s; int n, c; char *t; Rune r; Type *ty; if(!debug['F']) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; if(s && strcmp(s->name, "flag") == 0) goto ckflag; yyerror("syntax in #pragma varargck"); goto out;ckpos:/*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out;ckflag:/*#pragma varargck flag 'c'*/ c = getnsc(); if(c != '/'') goto bad; c = getr(); if(c == '//') c = getr(); else if(c == '/'') goto bad; if(c == '/n') goto bad; if(getc() != '/'') goto bad; argflag(c, Fignor); goto out;cktype:/*#pragma varargck type O int*/ c = getnsc(); if(c != '"') goto bad; t = fmtbuf; for(;;) { r = getr(); if(r == ' ' || r == '/n') goto bad; if(r == '"') break; t += runetochar(t, &r); } *t = 0; t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; ty = s->type; while((c = getnsc()) == '*') ty = typ(TIND, ty); unget(c); newprot(s, ty, t); goto out;bad: yyerror("syntax in #pragma varargck");out: while(getnsc() != '/n') ;}
开发者ID:99years,项目名称:plan9,代码行数:82,
示例11: yyparseintyyparse(void){ struct { YYSTYPE yyv; int yys; } yys[YYMAXDEPTH], *yyp, *yypt; short *yyxi; int yyj, yym, yystate, yyn, yyg; long yychar; YYSTYPE save1, save2; int save3, save4; save1 = yylval; save2 = yyval; save3 = yynerrs; save4 = yyerrflag; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyp = &yys[-1]; goto yystack;ret0: yyn = 0; goto ret;ret1: yyn = 1; goto ret;ret: yylval = save1; yyval = save2; yynerrs = save3; yyerrflag = save4; return yyn;yystack: /* put a state and value onto the stack */ if(yydebug >= 4) fprint(2, "char %s in %s", yytokname(yychar), yystatname(yystate)); yyp++; if(yyp >= &yys[YYMAXDEPTH]) { yyerror("yacc stack overflow"); goto ret1; } yyp->yys = yystate; yyp->yyv = yyval;yynewstate: yyn = yypact[yystate]; if(yyn <= YYFLAG) goto yydefault; /* simple state */ if(yychar < 0) yychar = yylex1(); yyn += yychar; if(yyn < 0 || yyn >= YYLAST) goto yydefault; yyn = yyact[yyn]; if(yychk[yyn] == yychar) { /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if(yyerrflag > 0) yyerrflag--; goto yystack; }yydefault: /* default state action */ yyn = yydef[yystate]; if(yyn == -2) { if(yychar < 0) yychar = yylex1(); /* look through exception table */ for(yyxi=yyexca;; yyxi+=2) if(yyxi[0] == -1 && yyxi[1] == yystate) break; for(yyxi += 2;; yyxi += 2) { yyn = yyxi[0]; if(yyn < 0 || yyn == yychar) break; } yyn = yyxi[1]; if(yyn < 0) goto ret0; } if(yyn == 0) { /* error ... attempt to resume parsing */ switch(yyerrflag) { case 0: /* brand new error */ yyerror("syntax error"); yynerrs++; if(yydebug >= 1) {//.........这里部分代码省略.........
开发者ID:8l,项目名称:inferno,代码行数:101,
示例12: regopt//.........这里部分代码省略......... r->p1 = R; r1->s1 = R; } } // Avoid making variables for direct-called functions. if(p->as == ABL && p->to.type == D_EXTERN) continue; /* * left side always read */ bit = mkvar(r, &p->from); for(z=0; z<BITS; z++) r->use1.b[z] |= bit.b[z]; /* * middle always read when present */ if(p->reg != NREG) { if(p->from.type != D_FREG) r->use1.b[0] |= RtoB(p->reg); else r->use1.b[0] |= FtoB(p->reg); } /* * right side depends on opcode */ bit = mkvar(r, &p->to); if(bany(&bit)) switch(p->as) { default: yyerror("reg: unknown op: %A", p->as); break; /* * right side read */ case ATST: case ATEQ: case ACMP: case ACMN: case ACMPD: case ACMPF: rightread: for(z=0; z<BITS; z++) r->use2.b[z] |= bit.b[z]; break; /* * right side read or read+write, depending on middle * ADD x, z => z += x * ADD x, y, z => z = x + y */ case AADD: case AAND: case AEOR: case ASUB: case ARSB: case AADC: case ASBC: case ARSC: case AORR: case ABIC: case ASLL:
开发者ID:xorrbit,项目名称:golang,代码行数:67,
示例13: genfuncnamevoidgenfuncname(struct table *tp, char *cname, char *fname, int type){ char tmp[512], *xp; struct column *cp = NULL; if (tp == NULL) return; if (cname != NULL && (cp = findcolumn(tp, cname)) == NULL) { yyerror("cannot find column within table"); return; } switch (type) { case DBOW_INSERT: if (tp->ifname != NULL) { yyerror("multiple insert definitions for table"); return; } xp = "insert"; break; case DBOW_DELETE: if (cp == NULL) return; if (cp->dfname != NULL) { yyerror("multiple insert definitions for column"); return; } xp = "delete"; break; case DBOW_SEARCH: if (cp == NULL) return; if (cp->sfname != NULL) { yyerror("multiple insert definitions for column"); return; } xp = "find"; break; case DBOW_UPDATE: if (cp == NULL) return; if (cp->ufname != NULL) { yyerror("multiple insert definitions for column"); return; } xp = "update"; break; } if (fname == NULL) { if (type != DBOW_INSERT) sprintf(tmp, "db_%s%sby%s", xp, tp->name, cp->name); else sprintf(tmp, "db_%s%s", xp, tp->name); xp = tmp; } else xp = fname; switch (type) { case DBOW_INSERT: tp->ifname = strdup(xp); break; case DBOW_DELETE: cp->dfname = strdup(xp); break; case DBOW_SEARCH: cp->sfname = strdup(xp); break; case DBOW_UPDATE: cp->ufname = strdup(xp); break; }}
开发者ID:kalopa,项目名称:dbow,代码行数:71,
示例14: yyparseintyyparse(void){ struct { YYSTYPE yyv; int yys; } yys[YYMAXDEPTH], *yyp, *yypt; short *yyxi; int yyj, yym, yystate, yyn, yyg; long yychar; YYSTYPE save1, save2; int save3, save4; save1 = yylval; save2 = yyval; save3 = yynerrs; save4 = yyerrflag; yystate = 0; yychar = -1; yynerrs = 0; yyerrflag = 0; yyp = &yys[-1]; goto yystack;ret0: yyn = 0; goto ret;ret1: yyn = 1; goto ret;ret: yylval = save1; yyval = save2; yynerrs = save3; yyerrflag = save4; return yyn;yystack: /* put a state and value onto the stack */ if(yydebug >= 4) fprint(2, "char %s in %s", yytokname(yychar), yystatname(yystate)); yyp++; if(yyp >= &yys[YYMAXDEPTH]) { yyerror("yacc stack overflow"); goto ret1; } yyp->yys = yystate; yyp->yyv = yyval;yynewstate: yyn = yypact[yystate]; if(yyn <= YYFLAG) goto yydefault; /* simple state */ if(yychar < 0) yychar = yylex1(); yyn += yychar; if(yyn < 0 || yyn >= YYLAST) goto yydefault; yyn = yyact[yyn]; if(yychk[yyn] == yychar) { /* valid shift */ yychar = -1; yyval = yylval; yystate = yyn; if(yyerrflag > 0) yyerrflag--; goto yystack; }yydefault: /* default state action */ yyn = yydef[yystate]; if(yyn == -2) { if(yychar < 0) yychar = yylex1(); /* look through exception table */ for(yyxi=yyexca;; yyxi+=2) if(yyxi[0] == -1 && yyxi[1] == yystate) break; for(yyxi += 2;; yyxi += 2) { yyn = yyxi[0]; if(yyn < 0 || yyn == yychar) break; } yyn = yyxi[1]; if(yyn < 0) goto ret0; } if(yyn == 0) { /* error ... attempt to resume parsing */ switch(yyerrflag) { case 0: /* brand new error */ yyerror("syntax error"); yynerrs++; if(yydebug >= 1) {//.........这里部分代码省略.........
开发者ID:bsheridan94,项目名称:inferno,代码行数:101,
示例15: strcmpstatic OBJECT_FILE *object_open( const char *file_name ){ OBJECT_FILE *file; Elf_Scn *section; Elf_Data *symtab; Elf32_Shdr *shdr; int compare; // search for the file in the list of already open objects for (file = objects ; file ; file = file->next_object) { compare = strcmp( file_name, file->name ); if ( compare == 0 ) // if we found it { return file; } else if ( compare < 0 ) // if we didn't find it { break; } } // try to add a new file to the list of open objects file = (OBJECT_FILE *)malloc( sizeof(OBJECT_FILE) ); assert(file); if ( file ) { memset( file, 0, sizeof(*file) ); if ((file->fd = open(file_name, O_RDONLY | O_BINARY)) != -1) { file->elf = elf_begin(file->fd, ELF_C_READ, NULL); if (file->elf) { file->ehdr = elf32_getehdr(file->elf); if (file->ehdr) { if ( file->ehdr->e_machine == out_file_machine ) { Elf_Data *string_data; OBJECT_FILE **scan; int compare; exec_getsection( file->elf, file->ehdr->e_shstrndx, NULL, &string_data ); file->strings = (char *)string_data->d_buf; file->name = strdup( file_name ); section = NULL; while ((section = elf_nextscn(file->elf, section)) != 0) { shdr = elf32_getshdr(section); elfcheck( shdr != NULL ); if (shdr->sh_type == SHT_SYMTAB) { symtab = exec_getdata(section); file->symbols = symtab->d_buf; file->symbol_count = symtab->d_size / sizeof(Elf32_Sym); file->first_global = shdr->sh_info; file->string_index = shdr->sh_link; if ( file->symbol_count > max_symbols ) { max_symbols = file->symbol_count; } break; } } // ordered insert into the file list assert( file->name ); for ( scan = &objects ; *scan ; scan = &(*scan)->next_object ) { compare = strcmp(file_name, (*scan)->name ); // if this file already exists we should have found // it instead of creating it assert( compare != 0 ); if (compare < 0) { break; } } file->next_object = *scan; *scan = file; return file; } else { yyerror( "Input file machine type doesn't match architecture" ); } } else { yyerror( "File %s is not a valid ELF file: %s", file_name, elf_errmsg(-1) ); } elf_end(file->elf); }//.........这里部分代码省略.........
开发者ID:wodz,项目名称:open21xx,代码行数:101,
示例16: yyparsebool yyparse( void ){ short yypnum; short yyi, yyk, yylhs, yyaction; short yytoken; short yys[MAXDEPTH], *yysp; YYSTYPE yyv[MAXDEPTH], *yyvp; short yyerrflag; yyerrflag = 0; yyaction = 0; yysp = yys; yyvp = yyv; *yysp = YYSTART; yytoken = yylex(); for(;;){yynewact: yyk = *yysp; while( (yyi = yyk + yytoken) < 0 || yyi >= YYUSED || yychktab[yyi] != yytoken ) if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN ) goto yycheck1; else yyk = yyacttab[yyi]; yyaction = yyacttab[yyi]; if( yyaction == YYNOACTION ){yycheck1: yyk = *yysp; while( (yyi = yyk + YYDTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYDTOKEN ) if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN ) goto yycheck2; else yyk = yyacttab[yyi]; yyaction = yyacttab[yyi]; if( yyaction == YYNOACTION ){yycheck2: switch( yyerrflag ){ case 0: yyerror( "syntax error" ); yyerrlab: case 1: case 2: yyerrflag = 3; while( yysp >= yys ){ yyk = *yysp; while( (yyi = yyk + YYETOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYETOKEN ) if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN ) goto continu; else yyk = yyacttab[yyi]; yyaction = yyacttab[yyi]; if( yyaction < YYUSED ){ *++yysp = yyaction; ++yyvp; goto yynewact; }; continu:; --yysp; --yyvp; }; YYABORT; case 3: if( yytoken == 0 ) /* EOF token */ YYABORT; yytoken = yylex(); goto yynewact; }; }; }; if( yyaction < YYUSED ){ if( yyaction == YYSTOP ){ YYACCEPT; } else { *++yysp = yyaction; *++yyvp = yylval; if( yyerrflag ) --yyerrflag; yytoken = yylex(); }; } else { yypnum = yyaction - YYUSED; yyi = yyplentab[yypnum]; yysp -= yyi; yyvp -= yyi; yylhs = yyplhstab[yypnum]; if( yysp < yys ){ printf( "stack underflow/n" ); YYABORT; }; yyk = *yysp; while( (yyi = yyk + yylhs) < 0 || yyi >= YYUSED || yychktab[yyi] != yylhs ){ if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN ){ printf( "missing nonterminal/n" ); YYABORT; }; yyk = yyacttab[yyi]; }; *++yysp = yyacttab[yyi]; ++yyvp;#ifdef AS_DEBUG_DUMP dump_rule( yypnum );//.........这里部分代码省略.........
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:101,
示例17: fixup_symbolsstatic void fixup_symbols( void ){ bbtree_node_t *parent; OBJECT_FILE *file; Elf_Scn *section; Elf32_Shdr *shdr; Elf32_Sym *symbol; global_t *global_sym; int i; int compare; char *sym_name; file = objects; while (file) { section = NULL; while ((section = elf_nextscn(file->elf, section)) != 0) { shdr = elf32_getshdr(section); elfcheck( shdr != NULL ); if ( (shdr->sh_type == SHT_PROGBITS || shdr->sh_type == SHT_NOBITS) && (shdr->sh_flags & SHF_REFERENCED) == 0) { yyerror( "Section %s in file %s is not referenced/n", file->strings + shdr->sh_name, file->name ); } } symbol = file->symbols + 1; for ( i = 1 ; i < file->symbol_count ; ++i ) { sym_name = elf_strptr( file->elf, file->string_index, symbol->st_name); if (symbol->st_shndx != SHN_UNDEF) { exec_getsection( file->elf, symbol->st_shndx, &shdr, NULL ); symbol->st_value += shdr->sh_addr; if (i >= file->first_global) { parent = bbtree_preinsert( &globals, sym_name, &compare ); if (!parent || compare != 0) { global_sym = (global_t *)malloc(sizeof(*global_sym)); if (global_sym) { global_sym->file = file; global_sym->name = sym_name; global_sym->symbol = symbol; bbtree_insert( &globals, parent, &global_sym->node, compare ); } else { yyerror( "Failed to allocate memory/n" ); } } else { yyerror( "Global symbol /"%s/" multiply defined/n", sym_name ); } } } else if (i < file->first_global) { yyerror( "Symbol /"%s/" is undefined but local/n", sym_name ); } ++symbol; } file = file->next_object; }}
开发者ID:wodz,项目名称:open21xx,代码行数:76,
示例18: StartVSMint StartVSM(int StartAddr, int TraceSW) /* Start VSM */{ int addr, op; Pctr = StartAddr; /* Set Pctr */ SP = Freg = 0; /* Set register flag */ while (1) { if (SP >= STACK_SIZE || SP < 0) { /* check the range of stack pointer */ fprintf(stderr, "Illegal Stack pointer %d/n", SP); return -1; } op = Iseg[Pctr].Op; /* fetch instruction */ addr = Iseg[Pctr].Addr; /* calculate effective address */ if (Iseg[Pctr++].Reg & FP) /* FP register modification */ addr += Freg; /* add FP */ InsCount++; /* Increment the number of instructions */ if (SP > MaxSD) MaxSD = SP; /* check the max SP value */ if (TraceSW) { /* if trace flag is on, make trace */ PrintIns(Pctr-1); printf("%15d %5d %12d/n", addr, SP, Stack[SP]); } switch (op) { /* execute each instruction */ case NOP: continue; case ASSGN: addr = Stack[--SP]; Dseg[addr] = Stack[SP] = Stack[SP+1]; continue; case ADD: BINOP(+); continue; case SUB: BINOP(-); continue; case MUL: BINOP(*); continue; case DIV: if (Stack[SP] == 0) { yyerror("Zero divider detected"); return -2; } BINOP(/); continue; case MOD: if (Stack[SP] == 0) { yyerror("Zero divider detected"); return -2; } BINOP(%); continue; case CSIGN: Stack[SP] = -Stack[SP]; continue; case AND: BINOP(&&); continue; case OR: BINOP(||); continue; case NOT: Stack[SP] = !Stack[SP]; continue; case COMP: Stack[SP-1] = Stack[SP-1] > Stack[SP] ? 1 : Stack[SP-1] < Stack[SP] ? -1 : 0; SP--; continue; case COPY: ++SP; Stack[SP] = Stack[SP-1]; continue; case PUSH: Stack[++SP] = Dseg[addr]; continue; case PUSHI: Stack[++SP] = addr; continue; case REMOVE: --SP; continue; case POP: Dseg[addr] = Stack[SP--]; continue; case INC: Stack[SP] = ++Stack[SP]; continue; case DEC: Stack[SP] = --Stack[SP]; continue; case SETFR: Freg = addr; continue; case INCFR : if ((Freg += addr) >= DSEG_SIZE) { printf("Freg overflow at loc. %d/n", Pctr-1); return -3; } continue; case DECFR : Freg -= addr; if (Freg < MinFR) MinFR = Freg; continue; case JUMP: Pctr = addr; continue; case BLT: if (Stack[SP--] < 0) Pctr = addr; continue; case BLE: if (Stack[SP--] <= 0) Pctr = addr; continue; case BEQ: if (Stack[SP--] == 0) Pctr = addr; continue; case BNE: if (Stack[SP--] != 0) Pctr = addr; continue; case BGE: if (Stack[SP--] >= 0) Pctr = addr; continue; case BGT: if (Stack[SP--] > 0) Pctr = addr; continue; case CALL: Stack[++SP] = Pctr; Pctr = addr; CallC++; continue; case RET: Pctr = Stack[SP--]; continue; case HALT: return 0; case INPUT: scanf("%d", &Dseg[Stack[SP--]]); continue; case OUTPUT: printf("%15d/n", Stack[SP--]); continue; default: printf("Illegal Op. code at location %d/n", Pctr); return -4; } }}
开发者ID:mikoim,项目名称:funstuff,代码行数:69,
示例19: mainint main(int argc, char *argv[]) { int c, i; Nonterm p; for (i = 1; i < argc; i++) if (strcmp(argv[i], "-T") == 0) Tflag = 1; else if (strncmp(argv[i], "-p", 2) == 0 && argv[i][2]) prefix = &argv[i][2]; else if (strncmp(argv[i], "-p", 2) == 0 && i + 1 < argc) prefix = argv[++i]; else if (*argv[i] == '-' && argv[i][1]) { yyerror("usage: %s [-T | -p prefix]... [ [ input ] output ] /n", argv[0]); exit(1); } else if (infp == NULL) { if (strcmp(argv[i], "-") == 0) infp = stdin; else if ((infp = fopen(argv[i], "r")) == NULL) { yyerror("%s: can't read `%s'/n", argv[0], argv[i]); exit(1); } } else if (outfp == NULL) { if (strcmp(argv[i], "-") == 0) outfp = stdout; if ((outfp = fopen(argv[i], "w")) == NULL) { yyerror("%s: can't write `%s'/n", argv[0], argv[i]); exit(1); } } if (infp == NULL) infp = stdin; if (outfp == NULL) outfp = stdout; yyparse(); if (start) ckreach(start); for (p = nts; p; p = p->link) { if (p->rules == NULL) yyerror("undefined nonterminal `%s'/n", p->name); if (!p->reached) yyerror("can't reach nonterminal `%s'/n", p->name); } emitheader(); emitdefs(nts, ntnumber); emitstruct(nts, ntnumber); emitnts(rules, nrules); emitstring(rules); emitrule(nts); emitclosure(nts); if (start) emitlabel(terms, start, ntnumber); emitkids(rules, nrules); if (!feof(infp)) while ((c = getc(infp)) != EOF) putc(c, outfp); while (memlist) { /* for purify */ struct block *q = memlist->link; free(memlist); memlist = q; } return errcnt > 0;}
开发者ID:0culus,项目名称:ioq3,代码行数:63,
示例20: assembleintassemble(char *file){ char ofile[100], incfile[20], *p; int i, of; strcpy(ofile, file); p = utfrrune(ofile, pathchar()); if(p) { include[0] = ofile; *p++ = 0; } else p = ofile; if(outfile == 0) { outfile = p; if(outfile){ p = utfrrune(outfile, '.'); if(p) if(p[1] == 's' && p[2] == 0) p[0] = 0; p = utfrune(outfile, 0); p[0] = '.'; p[1] = thechar; p[2] = 0; } else outfile = "/dev/null"; } p = getenv("INCLUDE"); if(p) { setinclude(p); } else { if(systemtype(Plan9)) { sprint(incfile,"/%s/include", thestring); setinclude(strdup(incfile)); } } of = create(outfile, OWRITE, 0664); if(of < 0) { yyerror("%ca: cannot create %s", thechar, outfile); errorexit(); } Binit(&obuf, of, OWRITE); pass = 1; pinit(file); Bprint(&obuf, "%s/n", thestring); for(i=0; i<nDlist; i++) dodefine(Dlist[i]); yyparse(); if(nerrors) { cclean(); return nerrors; } Bprint(&obuf, "/n!/n"); pass = 2; outhist(); pinit(file); for(i=0; i<nDlist; i++) dodefine(Dlist[i]); yyparse(); cclean(); return nerrors;}
开发者ID:8l,项目名称:go-learn,代码行数:68,
示例21: yyserrorvoid yyserror(const char *str, char *other){ sprintf(errmsg, str, other); yyerror(errmsg);}
开发者ID:CtheSky,项目名称:CSAPP-lab,代码行数:5,
示例22: main//.........这里部分代码省略......... if (!exec_flag && oname) { char *e; if (oname[0] == '/') snprintf(buf, sizeof(buf), "%s", oname); else snprintf(buf, sizeof(buf), "%s%s%s", outdir ? outdir : "", outdir ? "/" : "", oname); e = strrchr(buf, '/'); if (e) { *e = 0; outdir = strdup(buf); } } if (!outdir) outdir = "."; if (outdir) { char cdir[256]; getcwd(cdir, sizeof(cdir)); if (!chdir(outdir)) { getcwd(buf, sizeof(buf)); outdir = strdup(buf); chdir(cdir); } else { yyerror("cannot change to output dir '%s': %s", outdir, strerror(errno)); exit(1); } } if (!preproc_flag) { v_printf(2, "set source charset to %s/n", sourceCharset); v_printf(2, "set target charset to %s/n", targetCharset); } init_lex(); init_parser(); if (argc < 1) ii = -1; else ii = 0; Beg = times(&ts); if (argc > 0) { for (i = 0; i < argc; i++) { char *e; e = argv[i]; if (e[0] == '-' && e[1] == 'L') { insert_Coll(&lib_dirs, strdup(e + 2)); continue; } e = strrchr(argv[i], '.');
开发者ID:amery,项目名称:clip-angelo,代码行数:67,
示例23: eval_exprdata eval_expr(node expr, symrec ** symTable,list * routineList){ data res; switch (expr.operator) { case SEMICOLON: { //c'è sempre uno statement da valutare //valuto il primo eval(expr.op[0],symTable,routineList); if(expr.noperands>1){ //valuto il secondo, non è possibile per la struttura del parser averne più di due return eval(expr.op[1], symTable, routineList); } } break; case PRINT: { //statement data e = eval(expr.op[0], symTable,routineList); printData(e); res.type = no_op; return res; } break; case EQUALS: //statement { symrec * s = getSymbolFromIdentifier(expr.op[0]->value.id,symTable); //check if the variable is function routine * r = getRoutine(expr.op[0]->value.id.name, routineList); if(s == NULL && r == NULL){ yyerror("during assignment found unknown variable or function"); exit(NO_SUCH_VARIABLE); } //else data res; if(s!=NULL){ res = assignment(s,expr.op[1],symTable,routineList); } if(r!=NULL){ //TODO check if this is a function or a procedure res = r_assignment(r,expr.op[1], symTable,routineList); } return res; } break; case WHILE: //statement { // in ro con ambiente delta valuto <while e to c, omega> --> c <c; while e do c, omega> solo se in ro con ambiente delta posso valutare e a boleano vedi pag 54 semantica opearzionale data bool_guard = eval(expr.op[0],symTable,routineList); //here typechecking for correct return type of bool_guard...must be boolean if(bool_guard.b.b == true){ eval(expr.op[1],symTable,routineList); //ho fatto il comando c, ora rimetto a valutazione la stessa operazione treeNode * newWhile = opr(WHILE,2,expr.op[0],expr.op[1]); eval(newWhile,symTable,routineList); //free(newWhile) } data res; res.type = no_op; return res; } break; case IF: //statement { data bool_guard = eval(expr.op[0],symTable,routineList); //here typechecking for correct return type of bool_guard...must be boolean if(bool_guard.b.b == true){ eval(expr.op[1],symTable,routineList); }else if(expr.noperands == 3){ //se c'è il branch else eval(expr.op[2],symTable,routineList); } data res; res.type = no_op; return res; } break; case FOR: //statement { symrec * s = getSymbolFromIdentifier(expr.op[0]->value.id,symTable); if(s == NULL){ yyerror("NO_SUCH_VARIABLE"); exit(NO_SUCH_VARIABLE); } assignment(s,expr.op[1],symTable,routineList); identifier index; index.name = malloc(strlen(s->name)+1); strcpy(index.name,s->name); data id = eval_identifier(index, symTable,routineList); //consider only LT data guard = eval(expr.op[2],symTable,routineList); data comparison = operation(LT, id,guard); //here happens typechecking if(comparison.b.b == true){ eval(expr.op[3],symTable,routineList); //incremento la variable, assume only integers treeNode * nextValue = constantNode(basic_int_value, id.b.i + 1); //assignment(s,nextValue,symTable); treeNode * newFor = opr(FOR,4,expr.op[0],nextValue,expr.op[2],expr.op[3]); eval(newFor,symTable,routineList); //free(newFor); //free(nextValue); }//.........这里部分代码省略.........
开发者ID:simonacca,项目名称:LFC-PROJ,代码行数:101,
示例24: yylex//.........这里部分代码省略......... && (input_stream_pos[1] == '/n' || (input_stream_pos[1] == '/r' && input_stream_pos[2] == '/n'))) { mclex_want_line = FALSE; while (input_stream_pos[0] != 0 && input_stream_pos[0] != '/n') ++input_stream_pos; if (input_stream_pos[0] == '/n') ++input_stream_pos; return MCENDLINE; } while (input_stream_pos[0] != 0 && input_stream_pos[0] != '/n') ++input_stream_pos; if (input_stream_pos[0] == '/n') ++input_stream_pos; yylval.ustr = get_diff (input_stream_pos, start_token); return MCLINE; } while ((ch = input_stream_pos[0]) <= 0x20) { if (ch == 0) return -1; ++input_stream_pos; if (ch == '/n') input_line += 1; if (mclex_want_nl && ch == '/n') { mclex_want_nl = FALSE; return NL; } } start_token = input_stream_pos; ++input_stream_pos; if (mclex_want_filename) { mclex_want_filename = FALSE; if (ch == '"') { start_token++; while ((ch = input_stream_pos[0]) != 0) { if (ch == '"') break; ++input_stream_pos; } yylval.ustr = get_diff (input_stream_pos, start_token); if (ch == '"') ++input_stream_pos; } else { while ((ch = input_stream_pos[0]) != 0) { if (ch <= 0x20 || ch == ')') break; ++input_stream_pos; } yylval.ustr = get_diff (input_stream_pos, start_token); } return MCFILENAME; } switch (ch) { case ';': ++start_token; while (input_stream_pos[0] != '/n' && input_stream_pos[0] != 0) ++input_stream_pos; if (input_stream_pos[0] == '/n') input_stream_pos++; yylval.ustr = get_diff (input_stream_pos, start_token); return MCCOMMENT; case '=': return '='; case '(': return '('; case ')': return ')'; case '+': return '+'; case ':': return ':'; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': yylval.ival = parse_digit (ch); return MCNUMBER; default: if (ch >= 0x40) { int ret; while (input_stream_pos[0] >= 0x40 || (input_stream_pos[0] >= '0' && input_stream_pos[0] <= '9')) ++input_stream_pos; ret = mc_token (start_token, (size_t) (input_stream_pos - start_token)); if (ret != -1) return ret; yylval.ustr = get_diff (input_stream_pos, start_token); return MCIDENT; } yyerror ("illegal character 0x%x.", ch); } return -1;}
开发者ID:Caleb1994,项目名称:stewieos-binutils,代码行数:101,
示例25: yyparse//.........这里部分代码省略......... 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
开发者ID:shusinthebox,项目名称:minilang_compiler,代码行数:67,
示例26: typecheckrangevoidtypecheckrange(Node *n){ int op, et; Type *t, *t1, *t2; Node *v1, *v2; NodeList *ll; // delicate little dance. see typecheckas2 for(ll=n->list; ll; ll=ll->next) if(ll->n->defn != n) typecheck(&ll->n, Erv | Easgn); typecheck(&n->right, Erv); if((t = n->right->type) == T) goto out; n->type = t; switch(t->etype) { default: yyerror("cannot range over %+N", n->right); goto out; case TARRAY: t1 = types[TINT]; t2 = t->type; break; case TMAP: t1 = t->down; t2 = t->type; break; case TCHAN: t1 = t->type; t2 = nil; if(count(n->list) == 2) goto toomany; break; case TSTRING: t1 = types[TINT]; t2 = types[TINT]; break; } if(count(n->list) > 2) { toomany: yyerror("too many variables in range"); } v1 = n->list->n; v2 = N; if(n->list->next) v2 = n->list->next->n; if(v1->defn == n) v1->type = t1; else if(v1->type != T && checkconv(t1, v1->type, 0, &op, &et) < 0) yyerror("cannot assign type %T to %+N", t1, v1); if(v2) { if(v2->defn == n) v2->type = t2; else if(v2->type != T && checkconv(t2, v2->type, 0, &op, &et) < 0) yyerror("cannot assign type %T to %+N", t1, v1); }out: typechecklist(n->nbody, Etop); // second half of dance n->typecheck = 1; for(ll=n->list; ll; ll=ll->next) if(ll->n->typecheck == 0) typecheck(&ll->n, Erv | Easgn);}
开发者ID:8l,项目名称:go-learn,代码行数:76,
示例27: mpatoflt//.........这里部分代码省略......... f = 0; /* sign */ ex = 0; /* exponent */ eb = 0; /* binary point */ zer = 1; /* zero */ mpmovecflt(a, 0.0); for(;;) { switch(c = *s++) { default: goto bad; case '-': f = 1; case ' ': case '/t': case '+': continue; case '.': dp = 1; continue; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': zer = 0; case '0': mpmulcflt(a, 10); mpaddcflt(a, c-'0'); if(dp) dp++; continue; case 'P': case 'p': eb = 1; case 'E': case 'e': ex = 0; ef = 0; for(;;) { c = *s++; if(c == '+' || c == ' ' || c == '/t') continue; if(c == '-') { ef = 1; continue; } if(c >= '0' && c <= '9') { ex = ex*10 + (c-'0'); continue; } break; } if(ef) ex = -ex; case 0: break; } break; } if(eb) { if(dp) goto bad; a->exp += ex; goto out; } if(dp) dp--; if(mpcmpfltc(a, 0.0) != 0) { if(ex >= dp) { mppow10flt(&b, ex-dp); mpmulfltflt(a, &b); } else { mppow10flt(&b, dp-ex); mpdivfltflt(a, &b); } }out: if(f) mpnegflt(a); return;bad: yyerror("set ovf in mpatof"); mpmovecflt(a, 0.0);}
开发者ID:8l,项目名称:go-learn,代码行数:101,
示例28: calluserstatic double calluser(struct ufncall *f){ struct symbol *fn = f->s; /* function name */ struct symlist *sl; /* dummy arguments */ struct ast *args = f->l; /* actual arguments */ double *oldval, *newval; /* saved arg values */ double v; int nargs; int i; if(!fn->func) { yyerror("call to undefined function", fn->name); return 0; } /* count the arguments */ sl = fn->syms; for(nargs = 0; sl; sl = sl->next) nargs++; /* prepare to save them */ oldval = (double *)malloc(nargs * sizeof(double)); newval = (double *)malloc(nargs * sizeof(double)); if(!oldval || !newval) { yyerror("Out of space in %s", fn->name); return 0.0; } /* evaluate the arguments */ for(i = 0; i < nargs; i++) { if(!args) { yyerror("too few args in call to %s", fn->name); free(oldval); free(newval); return 0; } if(args->nodetype == 'L') { /* if this is a list node */ newval[i] = eval(args->l); args = args->r; } else { /* if it's the end of the list */ newval[i] = eval(args); args = NULL; } } /* save old values of dummies, assign new ones */ sl = fn->syms; for(i = 0; i < nargs; i++) { struct symbol *s = sl->sym; oldval[i] = s->value; s->value = newval[i]; sl = sl->next; } free(newval); /* evaluate the function */ v = eval(fn->func); /* put the dummies back */ sl = fn->syms; for(i = 0; i < nargs; i++) { struct symbol *s = sl->sym; s->value = oldval[i]; sl = sl->next; } free(oldval); return v;}
开发者ID:koalakoker,项目名称:resParser,代码行数:71,
注:本文中的yyerror函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ yyget_extra函数代码示例 C++ yy_switch_to_buffer函数代码示例 |