ref: split parser into separate files
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/parser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Parse TERM: addition and subtraction
|
||||
fzl_node_t *pa_term(fzl_parser_t *parser)
|
||||
{
|
||||
if (!parser)
|
||||
return NULL;
|
||||
|
||||
fzl_node_t *left = pa_factor(parser);
|
||||
fzl_node_t *right = NULL;
|
||||
|
||||
if (!left)
|
||||
return NULL;
|
||||
|
||||
while (is(parser, FZL_TOKTYPE_PLUS) || is(parser, FZL_TOKTYPE_MINUS))
|
||||
{
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user