summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorCarson Fleming <[email protected]>2026-03-15 19:25:26 -0400
committerCarson Fleming <[email protected]>2026-03-15 19:25:26 -0400
commit66e278b0752eaa9808687c0dc214b49d7b58e8eb (patch)
treecca09f74ab439c3d54913bc1b4355b8208a5824f /main.c
parent1f85b418dd7960c28f16de21c44dcb4e2e05e694 (diff)
downloadccc-66e278b0752eaa9808687c0dc214b49d7b58e8eb.tar.gz
functional lexer
Diffstat (limited to 'main.c')
-rw-r--r--main.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/main.c b/main.c
index e69de29..d2a6ef5 100644
--- a/main.c
+++ b/main.c
@@ -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();
+ }
+}