Files
fz-lang/src/compiler/parser/pa_unary.c
T

25 lines
567 B
C

#include <compiler/fzl_parser.h>
#include <compiler/internals/parser.h>
// Parse unary operations
fzl_node_t *pa_unary(fzl_parser_t *parser)
{
if (!parser)
return NULL;
if (!is(parser, FZL_TOKTYPE_MINUS) && !is(parser, FZL_TOKTYPE_PLUS) &&
!is(parser, FZL_TOKTYPE_NOT))
return pa_postfix(parser);
fzl_token_t *op = consume(parser);
fzl_node_t *operand = pa_unary(parser);
if (!operand)
return NULL;
fzl_node_t *result = fzl_mknode(unary_op_to_type(op->type), op);
result->unary_op.operand = operand;
return result;
}