42 lines
1006 B
C
42 lines
1006 B
C
#include <compiler/fzl_parser.h>
|
|
#include <compiler/internals/parser.h>
|
|
#include <stdio.h>
|
|
|
|
// Parse FACTOR: multiplication and division
|
|
fzl_node_t *pa_factor(fzl_parser_t *parser)
|
|
{
|
|
if (!parser)
|
|
return NULL;
|
|
|
|
fzl_node_t *left = pa_power(parser);
|
|
fzl_node_t *right = NULL;
|
|
|
|
if (!left)
|
|
return NULL;
|
|
|
|
while (is(parser, FZL_TOKTYPE_STAR) || is(parser, FZL_TOKTYPE_SLASH) ||
|
|
is(parser, FZL_TOKTYPE_PERCENT))
|
|
{
|
|
fzl_token_t *op = consume(parser);
|
|
|
|
right = pa_factor(parser);
|
|
if (!right)
|
|
{
|
|
fzl_freeast(left);
|
|
if (!plast_err[0])
|
|
snprintf(plast_err, sizeof(plast_err),
|
|
"'%s': expected expression at %ld:%ld",
|
|
last_known_tok->filename, last_known_tok->ln,
|
|
last_known_tok->cn);
|
|
return NULL;
|
|
}
|
|
|
|
fzl_node_t *node = fzl_mknode(math_op_to_type(op->type), op);
|
|
node->binary_op.left = left;
|
|
node->binary_op.right = right;
|
|
left = node;
|
|
}
|
|
|
|
return left;
|
|
}
|