summaryrefslogtreecommitdiff
path: root/lexer.h
blob: 62ee9c241d6744f94abd734d2f125fd988aebc3f (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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef LEXER_H
#define LEXER_H

enum token_type {
    IDENTIFIER,
    INT_LIT,
    CHAR_LIT,
    STR_LIT,
    HASHTAG,
    LPAREN,
    RPAREN,
    LCURLY,
    RCURLY,
    LSQUARE,
    RSQUARE,
    COLON,
    SEMI,
    COMMA,
    DOT,
    QMARK,
    NOT,
    NEQ,
    XOR,
    XEQ,
    AMP,
    LOG_AND,
    AND_EQ,
    STAR,
    MUL_EQ,
    NEG,
    NEG_EQ,
    ARROW,
    ASSIGN,
    TEST_EQ,
    PLUS,
    PLUS_EQ,
    BSLASH,
    PIPE,
    LOG_PIPE,
    PIPE_EQ,
    DIV,
    DIV_EQ, // comments too
    LT,
    GT,
    LEQ,
    GEQ,
    SHR,
    SHR_EQ,
    SHL,
    SHL_EQ
    /* more to come */
    // ->, everything that can precede = (multi-symbols)
};

typedef unsigned long long intlit_t;

struct token {
    enum token_type type;
    union {
        char* identifier;
        intlit_t int_lit;
        char char_lit;
        char* str_lit;
        void* unused;
    } data;
};

void lexer_load(const char* path);
bool lexer_peek(struct token* p_token);
bool lexer_pop(struct token* p_token);

#endif