diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cc | 28 | ||||
| -rw-r--r-- | src/scanner.cc | 11 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/main.cc b/src/main.cc index 857537d..d357756 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,4 +1,6 @@ +#include <scanner.h> #include <stdio.h> +#include <stdlib.h> int main(int argc, char **argv) @@ -6,7 +8,31 @@ main(int argc, char **argv) (void) argc; (void) argv; - printf("main\n"); + if (argc != 2) { + printf("Usage: %s <script>\n", argv[0]); + return 1; + } + FILE *f = fopen(argv[1], "r"); + if (f == NULL) { + printf("Unable to open %s\n", argv[1]); + return 1; + } + + fseek(f, 0, SEEK_END); + unsigned long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + + char *buffer = (char *) calloc(fsize, sizeof(char)); + int bytesread = fread(buffer, sizeof(char), fsize, f); + if (bytesread < 0) { + printf("Unable to open %s\n", argv[1]); + return 1; + } + + Scanner s(buffer); + s.scan_tokens(); + + free(buffer); return 0; } diff --git a/src/scanner.cc b/src/scanner.cc new file mode 100644 index 0000000..f193562 --- /dev/null +++ b/src/scanner.cc @@ -0,0 +1,11 @@ +#include <cstdio> +#include <scanner.h> + +Scanner::Scanner(char *script) : script(script) {} + +void +Scanner::scan_tokens(void) +{ + (void) script; + printf("%s\n", script); +} |
