diff options
author | kdx <kdx@42l.fr> | 2023-03-16 00:44:43 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-03-16 00:44:43 +0100 |
commit | a0a2fb39c75525af379a18e418cadcfd347957f6 (patch) | |
tree | c2cb757f124312208704817fab94ede5a0144428 | |
parent | c08b0e3791c2d96d0d54de4c3e099fa0428ad395 (diff) | |
download | golem-a0a2fb39c75525af379a18e418cadcfd347957f6.tar.gz |
identify functions
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | identify.c | 20 | ||||
-rw-r--r-- | identify.h | 3 | ||||
-rw-r--r-- | main.c | 2 |
4 files changed, 21 insertions, 6 deletions
@@ -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 @@ -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; } @@ -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); @@ -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); } |