diff options
author | kdx <kikoodx@paranoici.org> | 2023-03-16 05:26:12 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-03-16 05:26:12 +0100 |
commit | 913d3f8ca3ca78cbb107893e0e86b9e76b1f8f73 (patch) | |
tree | 5e5aca29462f5aec7faa6796b2ebf8194f1c5a29 | |
parent | 57f62e264e2e885d3fa0e48e2be926df8189b354 (diff) | |
download | golem-913d3f8ca3ca78cbb107893e0e86b9e76b1f8f73.tar.gz |
check for unidentified atom
-rw-r--r-- | check.c | 17 | ||||
-rw-r--r-- | check.h | 4 | ||||
-rw-r--r-- | main.c | 6 |
3 files changed, 26 insertions, 1 deletions
@@ -0,0 +1,17 @@ +#include "check.h" +#include <stddef.h> + +int +check_atom(Token *list) +{ + while (list != NULL) { + if (list->type == TOK_GROUP) { + if (list->group.type == GROUP_ATOM) + return 1; + if (check_atom(list->group.tokens)) + return 1; + } + list = list->next; + } + return 0; +} @@ -0,0 +1,4 @@ +#pragma once +#include "token.h" + +int check_atom(Token *list); @@ -4,6 +4,7 @@ #include "token.h" #include "group.h" #include "identify.h" +#include "check.h" #include <stdio.h> #include <stdlib.h> @@ -47,7 +48,10 @@ main(int argc, char **argv) identify(tokens, identify_else, GROUP_ELSE, 1); identify(tokens, identify_while, GROUP_WHILE, 1); identify(tokens, identify_expression, GROUP_EXPRESSION, 1); - token_print(tokens, 1, 0); + if (check_atom(tokens)) + fprintf(stderr, "unidentified atoms are left\n"); + else + token_print(tokens, 1, 0); token_destroy(tokens); } |