summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-16 05:26:12 +0100
committerkdx <kikoodx@paranoici.org>2023-03-16 05:26:12 +0100
commit913d3f8ca3ca78cbb107893e0e86b9e76b1f8f73 (patch)
tree5e5aca29462f5aec7faa6796b2ebf8194f1c5a29
parent57f62e264e2e885d3fa0e48e2be926df8189b354 (diff)
downloadgolem-913d3f8ca3ca78cbb107893e0e86b9e76b1f8f73.tar.gz
check for unidentified atom
-rw-r--r--check.c17
-rw-r--r--check.h4
-rw-r--r--main.c6
3 files changed, 26 insertions, 1 deletions
diff --git a/check.c b/check.c
new file mode 100644
index 0000000..238c285
--- /dev/null
+++ b/check.c
@@ -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;
+}
diff --git a/check.h b/check.h
new file mode 100644
index 0000000..07c4d16
--- /dev/null
+++ b/check.h
@@ -0,0 +1,4 @@
+#pragma once
+#include "token.h"
+
+int check_atom(Token *list);
diff --git a/main.c b/main.c
index 65c296d..778fae9 100644
--- a/main.c
+++ b/main.c
@@ -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);
}