This commit is contained in:
gazhonsepaskwa
2025-02-11 15:49:59 +01:00
parent 7b783fcb4d
commit 5de086624e
2 changed files with 16 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ static void free_pline(t_ast_n *node)
i = -1;
while (node->pline[++i])
free_ast(node->pline[i]);
free(node->pline);
}
void free_ast(t_ast_n *node)

View File

@@ -97,24 +97,33 @@ int unclosed(t_node *head)
return (0);
}
int is_aop_operator(t_node *node)
{
if (!node || node->token != OPERATOR)
return (0);
if (node->pressision == AND
|| node->pressision == OR
|| node->pressision == PIPE)
return (1);
return (0);
}
int syntax_error(t_node *head)
{
t_node *cpy;
cpy = head;
if (cpy->token == OPERATOR && cpy->next && cpy->next->token == OPERATOR)
return (syntax_err_mess(cpy->next->val, 0));
if (cpy->token == OPERATOR && cpy->pressision != SUBSH_S)
if (is_aop_operator(cpy) && cpy->next == NULL)
return (syntax_err_mess(cpy->val, 0));
while (cpy)
{
if (unexpected_token(cpy))
return (syntax_err_mess(cpy->val, 0));
if (cpy->token == OPERATOR && cpy->next == NULL && cpy->pressision != SUBSH_E)
if (cpy->next == NULL && is_aop_operator(cpy))
return (syntax_err_mess(cpy->val, 3));
if (cpy->token == OPERATOR && cpy->pressision != SUBSH_E && cpy->next && cpy->next->token == OPERATOR)
if (is_aop_operator(cpy) && is_aop_operator(cpy->next))
return (syntax_err_mess(cpy->next->val, 0));
if (cpy->token == OPERATOR && ft_strlen(cpy->val) > 2)
if (is_aop_operator(cpy) && ft_strlen(cpy->val) > 2)
return (syntax_err_mess(cpy->val, 0));
cpy = cpy->next;
}