From fbc4fbfc856c71a37282bc86f6cdf23c9d450864 Mon Sep 17 00:00:00 2001 From: wilyJ80 Date: Thu, 12 Dec 2024 03:12:48 -0300 Subject: [PATCH] can i even do this --- parser/parser.c | 18 ++++++++++++------ test/parser_integration_tests.c | 7 +++++++ test/parser_integration_tests.h | 2 ++ test/test.c | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/parser/parser.c b/parser/parser.c index 2d2054e..d6d67a1 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -85,11 +85,6 @@ enum SYNTAX_ERROR arrayFator(struct Parser *parser) { return NO_ERROR; } -enum SYNTAX_ERROR expr(struct Parser *parser) { - // TODO: - return NO_ERROR; -} - /** * prog accepts repetitions of declarations of variables (decl_list_var), or * procedures (decl_list_proc). @@ -465,12 +460,23 @@ enum SYNTAX_ERROR cmdDo(struct Parser *parser) { parser->token.category == REALCON || parser->token.category == CHARCON || (parser->token.category == SIGN && parser->token.signCode == OPEN_PAR) || (parser->token.category == SIGN && parser->token.signCode == NEGATION)) { - enum SYNTAX_ERROR error = fator(parser); + // goes from expr down to fator + enum SYNTAX_ERROR error = expr(parser); if (error != NO_ERROR) { return error; } } + parser->token = lexerGetNextChar(parser->fd, parser->lineCount); + if (!(parser->token.category == SIGN && parser->token.signCode == CLOSE_PAR)) { + return INVALID_FUNCTION_CALL_PAREN_CLOSE; + } + + return NO_ERROR; +} + +enum SYNTAX_ERROR expr(struct Parser *parser) { + // TODO: return NO_ERROR; } diff --git a/test/parser_integration_tests.c b/test/parser_integration_tests.c index de4d9d4..99e25c4 100644 --- a/test/parser_integration_tests.c +++ b/test/parser_integration_tests.c @@ -363,6 +363,12 @@ void atribAssignedToABadExprAStringcon() { assert(error == NO_FACTOR_VALID_START_SYMBOL); } +void doButNoClosingParen() { + enum SYNTAX_ERROR error = setupError("def nitrogenio(int i) do nitrogenio(8("); + assert(error == INVALID_FUNCTION_CALL_PAREN_CLOSE); +} + + // TODO: // // atrib with bad unclosed paren @@ -370,3 +376,4 @@ void atribAssignedToABadExprAStringcon() { /* enum SYNTAX_ERROR error = setupError("def oxigenio(int i) id[8[");*/ /* assert(error == NO_ATRIB_BRACKET_CLOSE);*/ /*}*/ + diff --git a/test/parser_integration_tests.h b/test/parser_integration_tests.h index e55aada..1b65a06 100644 --- a/test/parser_integration_tests.h +++ b/test/parser_integration_tests.h @@ -73,6 +73,8 @@ void putstrError(); void doButNotIdproc(); void doButNoParenOpen(); +void doButNoClosingParen(); +// test expression list too void atribNoValidAfterId(); void atribAssignedToABadExprAStringcon(); diff --git a/test/test.c b/test/test.c index 2ff515d..186bbef 100644 --- a/test/test.c +++ b/test/test.c @@ -89,7 +89,7 @@ int main(void) { doButNotIdproc(); doButNoParenOpen(); - // doIdprocExprExprSimpTermoFatorNoValidTokenAfterId(); + doButNoClosingParen(); atribNoValidAfterId(); atribAssignedToABadExprAStringcon();