42 lines
887 B
C
42 lines
887 B
C
#include <compiler/fzl_parser.h>
|
|
#include <compiler/internals/parser.h>
|
|
#include <stdio.h>
|
|
|
|
// Parse power expression
|
|
fzl_node_t *pa_power(fzl_parser_t *parser)
|
|
{
|
|
if (!parser)
|
|
return NULL;
|
|
|
|
fzl_node_t *left = pa_unary(parser);
|
|
fzl_node_t *right = NULL;
|
|
|
|
if (!left)
|
|
return NULL;
|
|
|
|
if (is(parser, FZL_TOKTYPE_CARET))
|
|
{
|
|
fzl_token_t *caret = consume(parser);
|
|
|
|
right = pa_unary(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(FZL_NODETYPE_POW, caret);
|
|
node->binary_op.left = left;
|
|
node->binary_op.right = right;
|
|
|
|
left = node;
|
|
}
|
|
|
|
return left;
|
|
}
|