ref: split parser into separate files
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/internals/parser.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Internal parsing entry point
|
||||
fzl_node_t *pa_program(fzl_parser_t *parser)
|
||||
{
|
||||
if (!peek(parser))
|
||||
return NULL;
|
||||
|
||||
fzl_node_t *first = NULL;
|
||||
fzl_node_t *last = NULL;
|
||||
fzl_node_t *node = NULL;
|
||||
while (peek(parser) != NULL)
|
||||
{
|
||||
node = pa_statement(parser);
|
||||
if (!node)
|
||||
{
|
||||
fzl_freeast(first);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!last)
|
||||
{
|
||||
first = node;
|
||||
last = node;
|
||||
}
|
||||
else
|
||||
{
|
||||
last->next = node;
|
||||
last = node;
|
||||
}
|
||||
}
|
||||
|
||||
if (!first)
|
||||
{
|
||||
snprintf(plast_err, sizeof(plast_err), "nothing to parse >:(");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
Reference in New Issue
Block a user