aboutsummaryrefslogtreecommitdiff
path: root/src/token.c
blob: 6bba2b987c6b6085ee247c306b444c1d033e7bc4 (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdlib.h>

#include "include/token.h"


// token constructor
token_t* token_init(int type, char* val) {
   token_t* token = calloc(1, sizeof(struct TOKEN_STRUC));
   token->type = type;
   token->value = val;

   return token;
}

int char_could_start_keyword(char* character) {
   for (int i = 0; i < TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN; ++ i) {
      if (TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[i] == *character) {
         return 1;
      }
   }

   return 0;
}

int char_could_split_keyword(char* character) {
   if (char_could_start_keyword(character)) {
      return 1;
   } else {
      for (int i = 0; i < TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS_LEN; ++ i) {
         if (TOKEN_DEFNAME_SPLIT_CHAR_ALLOWED_CHARS[i] == *character) {
            return 1;
         }
      }

      return 0;
   }
}

int char_could_start_int(char* character) {
   for (int i = 0; i < 10; ++ i) {
      if (TOKEN_CHAR_FIRST_CHAR_INT[i] == *character) {
         return 1;
      }
   }

   return 0;
}

int char_can_ignore(char* character) {
   for (int i = 0; i < TOKEN_CHAR_IGNORE_LEN; ++ i) {
      if (TOKEN_CHAR_IGNORE[i] == *character) {
         return 1;
      }
   }

   return 0;
}