aboutsummaryrefslogtreecommitdiff
path: root/src/as_op.c
blob: 847214d8323fd87a770ea28a9e820f2215f71223 (plain)
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
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;
}