as_op.c 496 B

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