diff options
author | kdx <kdx.42@42l.fr> | 2023-03-17 06:11:06 +0100 |
---|---|---|
committer | kdx <kdx.42@42l.fr> | 2023-03-17 06:11:06 +0100 |
commit | 19a77b5c755f6cca04cbea8ca91a6e809b53beae (patch) | |
tree | 3561b2729dc8658ed5e70d9c1225a1025bc0d02e | |
parent | c39d9d78a785826a1ba32375c9819a7f0317515b (diff) | |
download | golem-19a77b5c755f6cca04cbea8ca91a6e809b53beae.tar.gz |
error checking
-rw-r--r-- | identify.c | 9 | ||||
-rw-r--r-- | identify.h | 2 | ||||
-rw-r--r-- | main.c | 29 |
3 files changed, 21 insertions, 19 deletions
@@ -33,12 +33,11 @@ identify_control(Token **list, unsigned int type) } void -identify(Token *list, int (*fun)(Token**), unsigned int type, int recurse) +identify(Token *list, int (*fun)(Token**), unsigned int type) { - if (recurse) - for (Token *e = list; e != NULL; e = e->next) - if (e->type == TOK_GROUP) - identify(e->group.tokens, fun, type, 1); + for (Token *e = list; e != NULL; e = e->next) + if (e->type == TOK_GROUP) + identify(e->group.tokens, fun, type); for (Token *e = list; e != NULL; e = e->next) if (token_isgroup(e, GROUP_ATOM) && fun(&e->group.tokens)) @@ -1,7 +1,7 @@ #pragma once #include "token.h" -void identify(Token *list, int (*fun)(Token**), unsigned int type, int recurse); +void identify(Token *list, int (*fun)(Token**), unsigned int type); int identify_function(Token **list); int identify_let(Token **list); int identify_return(Token **list); @@ -37,21 +37,24 @@ main(int argc, char **argv) Token *tokens = lexer(slice); if (tokens != NULL) { destroy_duplicates(&tokens, TOK_END); - group_scope(&tokens); - group_atom(&tokens); - group_funcall(&tokens); - group_deref(&tokens); - identify(tokens, identify_function, GROUP_FUNCTION, 0); - identify(tokens, identify_let, GROUP_LET, 1); - identify(tokens, identify_return, GROUP_RETURN, 1); - identify(tokens, identify_assign, GROUP_ASSIGN, 1); - identify(tokens, identify_if, GROUP_IF, 1); - identify(tokens, identify_else, GROUP_ELSE, 1); - identify(tokens, identify_while, GROUP_WHILE, 1); - identify(tokens, identify_expression, GROUP_EXPRESSION, 1); do { + if (group_scope(&tokens) || + group_atom(&tokens) || + group_funcall(&tokens) || + group_deref(&tokens)) { + fprintf(stderr, "a group operation failed\n"); + break; + } + identify(tokens, identify_function, GROUP_FUNCTION); + identify(tokens, identify_let, GROUP_LET); + identify(tokens, identify_return, GROUP_RETURN); + identify(tokens, identify_assign, GROUP_ASSIGN); + identify(tokens, identify_if, GROUP_IF); + identify(tokens, identify_else, GROUP_ELSE); + identify(tokens, identify_while, GROUP_WHILE); + identify(tokens, identify_expression, GROUP_EXPRESSION); if (check_atom(tokens)) { - fprintf(stderr, "unidentified atoms are left\n"); + fprintf(stderr, "unidentified atoms remain\n"); break; } Token *group = group_create(&tokens, tokens, |