summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-03-16 00:44:43 +0100
committerkdx <kdx@42l.fr>2023-03-16 00:44:43 +0100
commita0a2fb39c75525af379a18e418cadcfd347957f6 (patch)
treec2cb757f124312208704817fab94ede5a0144428
parentc08b0e3791c2d96d0d54de4c3e099fa0428ad395 (diff)
downloadgolem-a0a2fb39c75525af379a18e418cadcfd347957f6.tar.gz
identify functions
-rwxr-xr-xbuild.sh2
-rw-r--r--identify.c20
-rw-r--r--identify.h3
-rw-r--r--main.c2
4 files changed, 21 insertions, 6 deletions
diff --git a/build.sh b/build.sh
index ed7e3e1..eb8f5ab 100755
--- a/build.sh
+++ b/build.sh
@@ -1,2 +1,2 @@
#!/bin/sh
-tcc -Os -std=c99 -Wall -Wextra -o golem *.c
+gcc -O0 -g -std=c99 -Wall -Wextra -o golem *.c
diff --git a/identify.c b/identify.c
index 6847b8b..c9f2dac 100644
--- a/identify.c
+++ b/identify.c
@@ -1,10 +1,24 @@
#include "identify.h"
+#include "token.h"
#include <stddef.h>
void
-identify_function(Token *list)
+identify(Token *list, int (*fun)(Token*), unsigned int type)
{
for (Token *e = list; e != NULL; e = e->next)
- if (token_isgroup(e, GROUP_ATOM))
- e->group.type = GROUP_FUNCTION;
+ if (token_isgroup(e, GROUP_ATOM) && fun(e->group.tokens))
+ e->group.type = type;
+}
+
+int
+identify_function(Token *list)
+{
+ while (list != NULL) {
+ if (list->next == NULL && !token_isgroup(list, GROUP_SCOPE))
+ return 0;
+ if (list->next != NULL && list->type != TOK_WORD)
+ return 0;
+ list = list->next;
+ }
+ return 1;
}
diff --git a/identify.h b/identify.h
index d1014d0..1f58cb6 100644
--- a/identify.h
+++ b/identify.h
@@ -1,4 +1,5 @@
#pragma once
#include "token.h"
-void identify_function(Token *list);
+void identify(Token *list, int (*fun)(Token*), unsigned int type);
+int identify_function(Token *list);
diff --git a/main.c b/main.c
index 56d91fa..098b895 100644
--- a/main.c
+++ b/main.c
@@ -37,7 +37,7 @@ main(int argc, char **argv)
destroy_duplicates(&tokens, TOK_END);
group_scope(&tokens);
group_atom(&tokens);
- identify_function(tokens);
+ identify(tokens, identify_function, GROUP_FUNCTION);
token_print(tokens, 1, 0);
token_destroy(tokens);
}