aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 2d741e4..a463a7e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,10 +6,38 @@
int main(int argc, char* argv[]) {
+ FILE *fsource;
+ long fsource_size;
+ char *source;
+
+ fsource = fopen ("examples/hello.halk", "rb");
+ if (!fsource) { fputs("Source file not found.", stderr); exit(1); };
+
+ fseek(fsource, 0L, SEEK_END);
+ fsource_size = ftell(fsource);
+ rewind(fsource);
+
+ source = calloc(1, fsource_size + 1);
+ if (!source) {
+ fclose(fsource);
+ fputs("Memory allocation faled.", stderr);
+ exit(1);
+ }
+
+ if (1 != fread(source, fsource_size, 1, fsource)) {
+ fclose(fsource);
+ free(source);
+ fputs("Could not read source file.", stderr);
+ exit(1);
+ }
+
lexer_t* lexer = lexer_init(
- "[a simple test script]\nlet it = \"Hello, World!\";\nsay it;"
+ source
);
+ fclose(fsource);
+ free(source);
+
printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content);
token_t* token = NULL;