diff options
| author | Carson Fleming <[email protected]> | 2026-03-15 19:25:26 -0400 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2026-03-15 19:25:26 -0400 |
| commit | 66e278b0752eaa9808687c0dc214b49d7b58e8eb (patch) | |
| tree | cca09f74ab439c3d54913bc1b4355b8208a5824f /main.c | |
| parent | 1f85b418dd7960c28f16de21c44dcb4e2e05e694 (diff) | |
| download | ccc-66e278b0752eaa9808687c0dc214b49d7b58e8eb.tar.gz | |
functional lexer
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +#include "lexer.h" +#include <stdlib.h> +#include <stdio.h> + +int main(int argc, char** argv) { + if (argc < 2) { + fprintf(stderr, "ccc: no input files"); + return 1; + } + + struct token token; + for (int i = 1; i < argc; i++) { + lexer_load(argv[i]); + while (lexer_pop(&token)) { + 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(); + } +} |
