aboutsummaryrefslogtreecommitdiff
path: root/src/token.c
blob: ece32f420a864332b1b403b8542454f44da1472a (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
#include <stdlib.h>

#include "include/token.h"

token_t* token_init(int type, char* val) {
   token_t* token;

   token = emalloc(sizeof(struct TOKEN_STRUC));
   token->type = type;
   token->val = val;
   token->nxt = NULL;

   return token;
}

void token_destroy(token_t* token) {
   if (token->nxt) {
      token_destroy(token->nxt);
      token->nxt = NULL;
   }

   free(token->val);
   free(token);
}

token_t* token_last(token_t* token) {
   token_t* t;

   while (t->nxt) {
      t = t->nxt;
   }

   return t;
}