diff options
| author | Mistivia <i@mistivia.com> | 2025-03-05 18:31:55 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-03-05 18:31:55 +0800 |
| commit | 1ce0d45242097a07b7a4ee539a074ec812851a58 (patch) | |
| tree | 5825213b60c3da442780e2a3fa1bbc0750ab25f1 /src/as_op.c | |
| parent | 2c228ecb7d373fd3a7150768302ce0ade6714246 (diff) | |
finish parser
Diffstat (limited to 'src/as_op.c')
| -rw-r--r-- | src/as_op.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/as_op.c b/src/as_op.c new file mode 100644 index 0000000..847214d --- /dev/null +++ b/src/as_op.c @@ -0,0 +1,28 @@ +#include "as_op.h" + +#include <string.h> + +struct opTableEntry{ + Op op; + const char* name; +}; +typedef struct opTableEntry OpTableEntry; + +OpTableEntry opTable[] = { + {ADD, "add"}, + {SUB, "sub"}, + {MUL, "mul"}, + {DIV, "div"}, + {MOD, "mod"}, + {EQ, "eq"}, + {OPEND, NULL} +}; + +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; +} |
