43 lines
1.0 KiB
C
43 lines
1.0 KiB
C
#include <compiler/fzl_parser.h>
|
|
#include <compiler/internals/parser.h>
|
|
#include <stdio.h>
|
|
|
|
// Assignments parsing
|
|
fzl_node_t *pa_assignment(fzl_parser_t *parser)
|
|
{
|
|
fzl_node_t *left = pa_new(parser);
|
|
if (!left)
|
|
return NULL;
|
|
|
|
if (is(parser, FZL_TOKTYPE_EQ))
|
|
{
|
|
fzl_token_t *asn = consume(parser);
|
|
if (!left || (left->type != FZL_NODETYPE_IDENTIFIER &&
|
|
left->type != FZL_NODETYPE_DECLARATION &&
|
|
left->type != FZL_NODETYPE_FIELD))
|
|
{
|
|
fzl_freeast(left);
|
|
snprintf(plast_err, sizeof(plast_err),
|
|
"'%s': cannot assign to '%s' at %ld:%ld",
|
|
last_known_tok->filename, (char *)left->token->value,
|
|
last_known_tok->ln, last_known_tok->cn);
|
|
return NULL;
|
|
}
|
|
|
|
fzl_node_t *right = pa_assignment(parser);
|
|
if (!right)
|
|
{
|
|
fzl_freeast(left);
|
|
return NULL;
|
|
}
|
|
|
|
fzl_node_t *node = fzl_mknode(FZL_NODETYPE_ASSIGN, asn);
|
|
node->binary_op.left = left;
|
|
node->binary_op.right = right;
|
|
|
|
left = node;
|
|
}
|
|
|
|
return left;
|
|
}
|