1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include "as_op.h" #include <string.h> struct opTableEntry{ enum op op; const char* name; }; struct opTableEntry opTable[] = { {ADD, "add"}, {SUB, "sub"}, {MUL, "mul"}, {DIV, "div"}, {MOD, "mod"}, {EQ, "eq"}, {OPEND, NULL} }; enum op str2op(const char* str) { for (int i = 0; opTable[i].name != NULL; i++) { if (strcmp(opTable[i].name, str) == 0) { return opTable[i].op; } } return OPEND; }