summaryrefslogtreecommitdiff
path: root/main.c
blob: 6fc75e96a8c26be9d7549dc0649663827c3d3040 (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
#include "lexer.h"
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv) {
    if (argc < 2) {
        fprintf(stderr, "ccc: no input files\n");
        return 1;
    }

    struct token token;
    for (int i = 1; i < argc; i++) {
        lexer_load(argv[i]);
        while (lexer_pop(&token)) {
            printf("[%s]: ", argv[i]);
            switch (token.type) {
                case IDENTIFIER:
                    printf("got identifier: %s\n", token.data.identifier);
                    free(token.data.identifier);
                    break;
                case STR_LIT:
                    printf("got string: %s\n", token.data.str_lit);
                    free(token.data.str_lit);
                    break;
                case INT_LIT:
                    printf("got int: %lld\n", token.data.int_lit);
                    break;
                case FLOAT_LIT:
                    printf("got float: %lf\n", token.data.float_lit);
                    break;
                case CHAR_LIT:
                    printf("got char: %c\n", token.data.char_lit);
                    break;
                default:
                    printf("got simple token: %d\n", token.type);
            }
        }
        lexer_close();
    }
}