forked from cosmonaut/wraith-lang
42 lines
752 B
C
42 lines
752 B
C
|
#include <stdio.h>
|
||
|
|
||
|
#include "y.tab.h"
|
||
|
#include "ast.h"
|
||
|
#include "stack.h"
|
||
|
|
||
|
extern FILE *yyin;
|
||
|
extern int yydebug;
|
||
|
|
||
|
int Parse(char *inputFilename, Node **pRootNode, uint8_t parseVerbose)
|
||
|
{
|
||
|
int result;
|
||
|
Stack *stack = CreateStack();
|
||
|
yydebug = parseVerbose;
|
||
|
|
||
|
FILE *fp = fopen(inputFilename, "r");
|
||
|
yyin = fp;
|
||
|
result = yyparse(fp, stack, pRootNode);
|
||
|
fclose(fp);
|
||
|
|
||
|
/* TODO: free stack */
|
||
|
/* TODO: free AST on error */
|
||
|
|
||
|
if (result == 0)
|
||
|
{
|
||
|
if (parseVerbose)
|
||
|
{
|
||
|
PrintTree(*pRootNode, 0);
|
||
|
}
|
||
|
}
|
||
|
else if (result == 1)
|
||
|
{
|
||
|
fprintf(stderr, "Syntax error.\n");
|
||
|
}
|
||
|
else if (result == 2)
|
||
|
{
|
||
|
fprintf(stderr, "Out of memory.\n");
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|