scl/src/token.c

31 lines
645 B
C
Raw Normal View History

#include "include/token.h"
Token* token_init(TokenType type, char* val) {
Token* t = malloc(sizeof(Token));
t->type = type;
t->val = val;
return t;
}
void token_destroy(Token* t) {
free(t->val);
free(t);
}
2024-10-07 11:48:53 -04:00
void token_print(Token* token) {
printf("Token @%p:\n", token);
printf("\ttype: %s\n", token_type_str(token));
printf("\tval: %s\n", token->val);
printf("\tlen: %ld\n", token->len);
}
static char* token_type_str(Token* token) {
switch (token->type) {
case TOKEN_TYPE_CALL: return "CALL";
case TOKEN_TYPE_NUMBER: return "NUMBER";
default: return "???";
}
}