static void expect(int kind) { if(tok->k != kind) errorposf(&tok->pos,"expected %s, got %s", tokktostr(kind), tokktostr(tok->k)); next(); }
static CTy * directdeclarator(CTy *basety, char **name) { CTy *ty, *stub; *name = 0; switch(tok->k) { case '(': expect('('); stub = gcmalloc(sizeof(CTy)); *stub = *basety; ty = declarator(stub, name, 0); expect(')'); *stub = *declaratortail(basety); return ty; case TOKIDENT: if(name) *name = tok->v; next(); return declaratortail(basety); default: if(!name) errorposf(&tok->pos, "expected ident or ( but got %s", tokktostr(tok->k)); return declaratortail(basety); } errorf("unreachable"); return 0; }
int main(int argc, char *argv[]) { Tok *t; if(argc != 2) usage(); cppinit(argv[1], vec()); while(1) { t = pp(); if(t->k == TOKEOF) break; printf("%s %s\n", tokktostr(t->k), t->v); } return 0; }