aboutsummaryrefslogtreecommitdiff
path: root/src/as_op.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/as_op.c')
-rw-r--r--src/as_op.c28
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;
+}