Skip to content

Commit

Permalink
might be better to do do first
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyJ80 committed Dec 12, 2024
1 parent 08e54a5 commit caf56fd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ enum SYNTAX_ERROR cmd(struct Parser *parser) {

enum SYNTAX_ERROR cmdAtrib(struct Parser *parser) {
parser->token = lexerGetNextChar(parser->fd, parser->lineCount);
if (!(parser->token.category == SIGN && (parser->token.signCode == OPEN_BRACK || parser->token.signCode == ASSIGN))) {
if (!(parser->token.category == SIGN &&
(parser->token.signCode == OPEN_BRACK ||
parser->token.signCode == ASSIGN))) {
return NO_ATRIB_VALID_TOKEN_AFTER_ID;
}

Expand All @@ -433,6 +435,16 @@ enum SYNTAX_ERROR cmdAtrib(struct Parser *parser) {
}
}

// arrayAtrib
while (parser->token.category == SIGN &&
parser->token.signCode == OPEN_BRACK) {
parser->token = lexerGetNextChar(parser->fd, parser->lineCount);
enum SYNTAX_ERROR error = expr(parser);
if (error != NO_ERROR) {
return error;
}
}

return NO_ERROR;
}

Expand Down
3 changes: 2 additions & 1 deletion parser/syntax_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdbool.h>
#include <stdio.h>

#define ERROR_QTY 90
#define ERROR_QTY 91

// ANSI escape codes
#define RESET "\033[0m"
Expand Down Expand Up @@ -131,6 +131,7 @@ void printSyntaxError(enum SYNTAX_ERROR error, int *lineCount) {
{NO_ATRIB_EXPR, "No expression assigned to expression assign"},
{NO_ATRIB_VALID_TOKEN_AFTER_ID,
"No valid token after identifier for assignment"},
{NO_ATRIB_BRACKET_CLOSE, "Expected bracket closing at array assignment"},
// expr
{NO_EXPR_EXPR_SIMP, "No simple expression for expression"},
{NO_EXPR_EXPR_SIMP_AFTER_OP_REL, "No simple expression after operation"},
Expand Down
1 change: 1 addition & 0 deletions parser/syntax_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum SYNTAX_ERROR {
NO_ATRIB_ASSIGN,
NO_ATRIB_EXPR,
NO_ATRIB_VALID_TOKEN_AFTER_ID,
NO_ATRIB_BRACKET_CLOSE,
// expr
NO_EXPR_EXPR_SIMP,
NO_EXPR_EXPR_SIMP_AFTER_OP_REL,
Expand Down
8 changes: 8 additions & 0 deletions test/parser_integration_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,11 @@ void atribAssignedToABadExprAStringcon() {
enum SYNTAX_ERROR error = setupError("def potassio(int i) i = $");
assert(error == NO_FACTOR_VALID_START_SYMBOL);
}

// TODO:
//
// atrib with bad unclosed paren
/*void atribBadClosedParen() {*/
/* enum SYNTAX_ERROR error = setupError("def oxigenio(int i) id[8[");*/
/* assert(error == NO_ATRIB_BRACKET_CLOSE);*/
/*}*/
1 change: 1 addition & 0 deletions test/parser_integration_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void doButNoParenOpen();

void atribNoValidAfterId();
void atribAssignedToABadExprAStringcon();
void atribBadClosedParen();

// void doIdprocExprExprSimpTermoFatorNoValidTokenAfterId();

Expand Down
1 change: 1 addition & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ int main(void) {

atribNoValidAfterId();
atribAssignedToABadExprAStringcon();
// atribBadClosedParen();

printf("--- Parser integration tests passed\n");

Expand Down

0 comments on commit caf56fd

Please sign in to comment.