aboutsummaryrefslogtreecommitdiff
path: root/src/token.cc
blob: ff59123f81c200dc52f01e178b5c2fa0a9ba6b1f (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
29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <token.h>

void
Token::init(token_type_e type, char *lexeme, unsigned int line)
{
  m_type = type;
  m_lexeme = lexeme;
  m_line = line;
  m_string = NULL;
}

char *
Token::to_string(void)
{
  if (m_string == NULL)
    asprintf(&m_string, "%d: %s - %s", m_line, TOKEN_STRING[m_type], m_lexeme);

  return m_string;
}

void
Token::clean(void)
{
  if (m_string != NULL)
    free(m_string);
}