diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | flake.nix | 9 | ||||
-rw-r--r-- | include/scanner.h | 14 | ||||
-rw-r--r-- | src/main.cc | 28 | ||||
-rw-r--r-- | src/scanner.cc | 11 |
6 files changed, 59 insertions, 5 deletions
@@ -1,4 +1,5 @@ .cache/ +.ccls-cache/ .direnv/ build/ compile_commands.json
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index fc60ab8..c6ac1c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(minni CXX) set(SRC src/main.cc + src/scanner.cc ) add_executable(minni ${SRC}) @@ -2,16 +2,17 @@ inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; outputs = { self, nixpkgs, ... }: let - pkgs = import nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; }; + pkgs = import nixpkgs { system = "x86_64-linux"; }; in { devShells.x86_64-linux.default = pkgs.mkShell { buildInputs = with pkgs; [ + # clang-tools provides a working clangd and MUST COME BEFORE clang! + # https://discourse.nixos.org/t/get-clangd-to-find-standard-headers-in-nix-shell/11268 + clang-tools + clang cmake ninja - - clang-tools - ccls ]; }; }; diff --git a/include/scanner.h b/include/scanner.h new file mode 100644 index 0000000..e3ffe73 --- /dev/null +++ b/include/scanner.h @@ -0,0 +1,14 @@ +#ifndef __SCANNER_H +#define __SCANNER_H + +class Scanner +{ +private: + char *script; + +public: + Scanner(char *script); + void scan_tokens(void); +}; + +#endif 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); +} |