aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lexer.c2
-rw-r--r--src/main.c26
-rw-r--r--src/parser.c5
3 files changed, 19 insertions, 14 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 5d334bd..2b94fea 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -265,4 +265,6 @@ char* lexer_get_c_as_string(lexer_t* lexer) {
void lexer_destroy(lexer_t* lexer) {
free(lexer->content);
free(lexer);
+
+
}
diff --git a/src/main.c b/src/main.c
index fa468a5..33be891 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,6 +4,7 @@
#include "include/log.h"
#include "include/lexer.h"
#include "include/tree.h"
+#include "include/parser.h"
int main(int argc, char* argv[]) {
@@ -13,7 +14,7 @@ int main(int argc, char* argv[]) {
fsource = fopen ("examples/hello.halk", "rb");
if (!fsource) {
- fputs("Source file not found.", stderr);
+ log_err("Source file not found");
exit(1);
};
@@ -25,32 +26,33 @@ int main(int argc, char* argv[]) {
if (!source) {
fclose(fsource);
- fputs("Memory allocation failed.", stderr);
+ log_err("Memory allocation failed");
exit(1);
}
if (1 != fread(source, fsource_size, 1, fsource)) {
fclose(fsource);
free(source);
- fputs("Could not read source file.", stderr);
+ log_err("Could not read source file");
exit(1);
}
- fclose(fsource);
+ log_inf("Source file loaded");
- lexer_t* lexer = lexer_init( source );
+ lexer_t* lexer = lexer_init(source);
+ log_inf("Lexer created");
- printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content);
+ parser_t* parser = parser_init(lexer);
+ log_inf("Parser created");
- token_t* token = NULL;
+ tree_t* tree = parser_parse(parser);
+ log_inf("Tree root created");
- while ((token = lexer_get_next_token(lexer)) != NULL) {
- printf("===\ntoken type: %d\ntoken value: %s\n===\n", token->type, token->value);
- }
+ printf("TYPE: [%d]\n", tree->type);
- lexer_destroy(lexer);
+ fclose(fsource);
- log_inf("Lexer destroyed.");
+ log_inf("Source file closed");
return 0;
}
diff --git a/src/parser.c b/src/parser.c
index 4da693b..01b252c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -49,8 +49,9 @@ tree_t* parser_parse_chunk(parser_t* parser) {
break;
}
default: {
- fputs("smthn smthn \"invalid syntax,\" idk.", stderr);
- exit(1);
+ log_dbg("Skiping non-keyword token");
+ lexer_next(parser->lexer);
+ break;
}
}
}