#include #include #include #include #include "types.h" #include "token.h" static char *tokennames[] = { [Tvoid] = "void", [Tint] = "int", [Treturn] = "return", [Tident] = "identifier", [Tconstant] = "constant", [Tlparen] = "(", [Trparen] = ")", [Tlbrace] = "{", [Trbrace] = "}", [Tsemicolon] = ";", }; static_assert(sizeof(tokennames) / sizeof(char *) == Ntok, "token name map out of sync with tokens"); char * tokname(enum tokentype type) { return tokennames[type]; } enum tokentype findkeyword(char *name) { enum tokentype t; for (t = Tvoid; t < Tident; t++) { if (!strcmp(name, tokennames[t])) return t; } return Txxx; }