ref: split parser into separate files
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/parser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Statement parsing
|
||||
fzl_node_t *pa_statement(fzl_parser_t *parser)
|
||||
{
|
||||
if (!peek(parser))
|
||||
return NULL;
|
||||
|
||||
fzl_node_t *res = NULL;
|
||||
|
||||
if (is(parser, FZL_TOKTYPE_CLASS))
|
||||
return pa_class(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_FUNCTION))
|
||||
return pa_function(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_RETURN))
|
||||
res = pa_return(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_IF))
|
||||
return pa_if(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_LBRACE))
|
||||
return pa_block(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_FOR) || is(parser, FZL_TOKTYPE_WHILE))
|
||||
return pa_loop(parser);
|
||||
else if (is(parser, FZL_TOKTYPE_BREAK))
|
||||
res = pa_break(parser);
|
||||
|
||||
if (!res)
|
||||
res = pa_expression(parser);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
fzl_freeast(res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!is(parser, FZL_TOKTYPE_SEMICOLON))
|
||||
{
|
||||
fzl_freeast(res);
|
||||
snprintf(plast_err, sizeof(plast_err), "'%s': missing ';' at %ld:%ld",
|
||||
last_known_tok->filename, last_known_tok->ln, last_known_tok->cn);
|
||||
return NULL;
|
||||
}
|
||||
while (is(parser, FZL_TOKTYPE_SEMICOLON))
|
||||
consume(parser);
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user