diff --git a/src/execution/execution_helpers.c b/src/execution/execution_helpers.c index 3166578..9a72c10 100644 --- a/src/execution/execution_helpers.c +++ b/src/execution/execution_helpers.c @@ -201,6 +201,8 @@ int exec_ast_command(struct ast_command *command, struct hash_map *vars) int exec_ast_if(struct ast_if *if_node, struct hash_map *vars) { + if (if_node == NULL) + return 2; int cond = execution(if_node->condition, vars); if (cond == 0) return execution(if_node->then_clause, vars); diff --git a/src/parser/grammar.c b/src/parser/grammar.c index 73258ea..b89a99e 100644 --- a/src/parser/grammar.c +++ b/src/parser/grammar.c @@ -140,6 +140,7 @@ bool grammar_init(void) // Element add_first(RULE_ELEMENT, TOKEN_WORD); + add_first(RULE_ELEMENT, TOKEN_ASSIGNMENT_WORD); add_firsts(RULE_ELEMENT, first(RULE_REDIRECTION)); // Prefix diff --git a/src/parser/grammar_basic.c b/src/parser/grammar_basic.c index 6a6839b..86ed089 100644 --- a/src/parser/grammar_basic.c +++ b/src/parser/grammar_basic.c @@ -281,7 +281,7 @@ struct ast *parse_simple_command(struct lexer_context *ctx) struct ast *parse_element(struct lexer_context *ctx) { struct token *token = PEEK_TOKEN(); - if (token->type == TOKEN_WORD) + if (token->type == TOKEN_WORD || token->type == TOKEN_ASSIGNMENT_WORD) { token = POP_TOKEN(); return ast_create_word(token->data); diff --git a/src/utils/ast/ast_if.c b/src/utils/ast/ast_if.c index 1402ff6..6b0ff5d 100644 --- a/src/utils/ast/ast_if.c +++ b/src/utils/ast/ast_if.c @@ -19,7 +19,7 @@ struct ast *ast_create_if(struct ast *condition, struct ast *then_clause, struct ast_if *ast_get_if(struct ast *node) { - if (node == NULL || node->type == AST_IF) + if (node == NULL || node->type != AST_IF) return NULL; return node->data; }