From 1aa823effc534526c1bc2ec4ca80139826660f2f Mon Sep 17 00:00:00 2001 From: kdx Date: Fri, 17 Mar 2023 03:49:29 +0100 Subject: scope function arguments --- main.c | 1 + scope.c | 20 ++++++++++++++++++++ scope.h | 1 + token.c | 10 ++++++++++ token.h | 1 + 5 files changed, 33 insertions(+) diff --git a/main.c b/main.c index 7ba3033..2a7b162 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,7 @@ main(int argc, char **argv) } group->group.type = GROUP_SCOPE; scope_extract(tokens); + scope_function(tokens); token_print(tokens, 1, 0); } while(0); token_destroy(tokens); diff --git a/scope.c b/scope.c index 722e430..fdd36c5 100644 --- a/scope.c +++ b/scope.c @@ -25,3 +25,23 @@ scope_extract(Token *list) } else e = e->next; } + +static void +_scope_function(Token *list) +{ + unsigned int len = token_len(list->group.tokens); + while (len > 2) { + token_append(&list->group.scope, + token_extract(&list->group.tokens, + list->group.tokens->next)); + len -= 1; + } +} + +void +scope_function(Token *list) +{ + for (Token *e = list->group.tokens; e != NULL; e = e->next) + if (token_isgroup(e, GROUP_FUNCTION)) + _scope_function(e); +} diff --git a/scope.h b/scope.h index 96ab8cb..1d5e1f1 100644 --- a/scope.h +++ b/scope.h @@ -2,3 +2,4 @@ #include "token.h" void scope_extract(Token *list); +void scope_function(Token *list); diff --git a/token.c b/token.c index 25223c0..6ec9f40 100644 --- a/token.c +++ b/token.c @@ -47,6 +47,16 @@ token_append(Token **list, Token *elem) return *list; } +Token * +token_prepend(Token **list, Token *elem) +{ + elem->next = *list; + if (*list) + (*list)->prev = elem; + *list = elem; + return *list; +} + void token_delete(Token **list, Token *elem) { diff --git a/token.h b/token.h index 018ee10..fd378a5 100644 --- a/token.h +++ b/token.h @@ -38,6 +38,7 @@ struct Token { Token *token_create(Slice slice, unsigned int type); void token_destroy(Token *token); Token *token_append(Token **list, Token *elem); +Token *token_prepend(Token **list, Token *elem); void token_delete(Token **list, Token *elem); Token *token_extract(Token **list, Token *elem); Token *token_search(Token *list, unsigned int type); -- cgit v1.2.3