int main() { printf("sizeof ch:[%d], sizeof int:[%d]\n",sizeof(char),sizeof(int)); char hell = 'C'; char *ptrhell = &hell; int i = 5; printf("MemAdd of i: [%x]\n",&i); funccall(5, ptrhell); printf("MemAdd of i: [%x]\n",&i); return(0); }
ident_t factor(){ ident_t ret = 0; symbol_t id; if(sym->type==ID){ id = copySym(sym); nextSym(); if(sym->type!=LPAREN){ if(context) ret = findTable(context->local, (char*)(id->value)); if(!ret) ret = findTable(global, (char*)(id->value)); if(!ret){ msg(ERR, "undefined identifier", line); ERROR_STATUS = 1; } return ret; } nextSym(); if((ret = funccall(id))==0){ msg(ERR, "no value return from function", line); ERROR_STATUS = 1; } mfree(id); }else if(sym->type==LPAREN){ nextSym(); ret = expression(tn); if(sym->type!=RPAREN){ msg(ERR, "missing \')\'", line); ERROR_STATUS = 1; } nextSym(); }else if(isLiteral(sym) || isAddOperator(sym)){ readLiteral(); ret = getLiteral(global, sym); nextSym(); } return ret; }
void readfile(const char *name) { FILE *inp; size_t len; const char *cp; char *line, *eptr, rt = '\0'; int cline, isrc, iline; pos_t pos; if (inpfns == NULL) if ((inpfns = calloc(ninpfns = 128, sizeof (short))) == NULL) nomem(); if (fnames == NULL) if ((fnames = calloc(nfnames = 256, sizeof (char *))) == NULL) nomem(); if (tlstlen == 0) if ((tlst = calloc(tlstlen = 256, sizeof (type_t *))) == NULL) nomem(); if (thtab == NULL) if ((thtab = calloc(THSHSIZ2, sizeof (thtab_t))) == NULL) nomem(); _inithash(&renametab); srcfile = getfnidx(name); if ((inp = fopen(name, "r")) == NULL) err(1, "cannot open %s", name); while ((line = fgetln(inp, &len)) != NULL) { if (len == 0 || line[len - 1] != '\n') inperr(); line[len - 1] = '\0'; cp = line; /* line number in csrcfile */ cline = (int)strtol(cp, &eptr, 10); if (cp == eptr) { cline = -1; } else { cp = eptr; } /* record type */ if (*cp != '\0') { rt = *cp++; } else { inperr(); } if (rt == 'S') { setsrc(cp); continue; } else if (rt == 's') { setfnid(cline, cp); continue; } /* * Index of (included) source file. If this index is * different from csrcfile, it refers to an included * file. */ isrc = (int)strtol(cp, &eptr, 10); if (cp == eptr) inperr(); cp = eptr; isrc = inpfns[isrc]; /* line number in isrc */ if (*cp++ != '.') inperr(); iline = (int)strtol(cp, &eptr, 10); if (cp == eptr) inperr(); cp = eptr; pos.p_src = (u_short)csrcfile; pos.p_line = (u_short)cline; pos.p_isrc = (u_short)isrc; pos.p_iline = (u_short)iline; /* process rest of this record */ switch (rt) { case 'c': funccall(&pos, cp); break; case 'd': decldef(&pos, cp); break; case 'u': usedsym(&pos, cp); break; default: inperr(); } } _destroyhash(renametab); if (ferror(inp)) err(1, "read error on %s", name); (void)fclose(inp); }
int statement(){ symbol_t id; if(sym->type==IF){ nextSym(); brancher(); }else if(sym->type==WHILE){ nextSym(); looper(); }else if(sym->type==LBRACE){ nextSym(); statementlist(); if(sym->type!=RBRACE){ msg(ERR, "missing \'}\'", line); ERROR_STATUS = 1; } nextSym(); }else if(sym->type==ID){ id = copySym(sym); nextSym(); if(sym->type==LPAREN){ nextSym(); funccall(id); }else if(sym->type==ASN){ nextSym(); assign(id); }else{ msg(ERR, "expect a \'=\' or \'(\'", line); ERROR_STATUS = 1; } mfree(id); if(sym->type!=SEMIC){ msg(ERR, "missing \';\'", line); ERROR_STATUS = 1; } nextSym(); }else if(sym->type==PRINTF){ nextSym(); printfcall(); if(sym->type!=SEMIC){ msg(ERR, "missing \';\'", line); ERROR_STATUS = 1; } nextSym(); }else if(sym->type==SCANF){ nextSym(); scanfcall(); if(sym->type!=SEMIC){ msg(ERR, "missing \';\'", line); ERROR_STATUS = 1; } nextSym(); }else if(sym->type==SWITCH){ nextSym(); switcher(); }else if(sym->type==RETURN){ nextSym(); returns(); if(sym->type!=SEMIC){ msg(ERR, "missing \';\'", line); ERROR_STATUS = 1; } nextSym(); }else return 0;// a 0 statement return 1; }