|
@@ -2,28 +2,64 @@
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define IMP
|
|
#define IMP
|
|
|
|
|
+#include "./lexer.h"
|
|
|
|
|
+#include "./da.h"
|
|
|
|
|
+#include "./str.h"
|
|
|
#include "./file.h"
|
|
#include "./file.h"
|
|
|
|
|
|
|
|
-
|
|
|
|
|
#include "./int.h"
|
|
#include "./int.h"
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
+ * TODO:
|
|
|
|
|
+ * - Parse main function
|
|
|
|
|
+ * - Run parsed code
|
|
|
|
|
+ * - Parse generic function
|
|
|
|
|
+ * - Handle variables
|
|
|
|
|
+ * - Get source from argv
|
|
|
|
|
+ * - Help flag
|
|
|
|
|
+ * */
|
|
|
|
|
+
|
|
|
int
|
|
int
|
|
|
main(int argc, const char *argv[])
|
|
main(int argc, const char *argv[])
|
|
|
{
|
|
{
|
|
|
|
|
+ struct str str;
|
|
|
|
|
+
|
|
|
const char *src_path = "./main.c";
|
|
const char *src_path = "./main.c";
|
|
|
enum file_err ferr;
|
|
enum file_err ferr;
|
|
|
char *src = NULL;
|
|
char *src = NULL;
|
|
|
|
|
+ size_t src_size = 0;
|
|
|
|
|
+
|
|
|
|
|
+ struct lexer l = {0};
|
|
|
|
|
+ struct token t = {0};
|
|
|
|
|
+
|
|
|
|
|
+ struct token ts[256] = {0};
|
|
|
|
|
+ size_t ts_size = 0;
|
|
|
|
|
+
|
|
|
|
|
+ size_t i = 0;
|
|
|
|
|
|
|
|
- src = (char *) file_read_all(src_path, NULL, &ferr);
|
|
|
|
|
|
|
+ src = (char *) file_read_all(src_path, &src_size, &ferr);
|
|
|
if ( ferr != FILE_ERR_OK ) {
|
|
if ( ferr != FILE_ERR_OK ) {
|
|
|
fprintf(stderr, "Failed to open src file `%s`: `%s`",
|
|
fprintf(stderr, "Failed to open src file `%s`: `%s`",
|
|
|
src_path, file_err_to_cstr(ferr));
|
|
src_path, file_err_to_cstr(ferr));
|
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- printf("%s", src);
|
|
|
|
|
|
|
+ str = str_from_cstr(src, src_size);
|
|
|
|
|
|
|
|
|
|
+ l = lexer_create(str);
|
|
|
|
|
+ for ( ; t.typ.code != TT_EOF; t = lexer_next_token(&l) ) {
|
|
|
|
|
+ ts[ts_size++] = t;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for ( i = 0; i < ts_size; ++i ) {
|
|
|
|
|
+ printf("%d - %s -> `%.*s`\n",
|
|
|
|
|
+ ts[i].typ.code, ts[i].typ.name,
|
|
|
|
|
+ (int) ts[i].lit.size, ts[i].lit.data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ free(src);
|
|
|
|
|
|
|
|
(void) argc; (void) argv;
|
|
(void) argc; (void) argv;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+
|