i think i did something
This commit is contained in:
13
src/main.c
13
src/main.c
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h> // for now
|
#include <stdio.h> // for now
|
||||||
// #include "lexer.h"
|
// #include "lexer.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "helper.h"
|
||||||
|
|
||||||
void tab(noom_uint_t amount) {
|
void tab(noom_uint_t amount) {
|
||||||
amount *= 2;
|
amount *= 2;
|
||||||
@@ -54,11 +55,21 @@ int main(int argc, char** argv) {
|
|||||||
printf("\nPARSE OUTPUT:\n");
|
printf("\nPARSE OUTPUT:\n");
|
||||||
|
|
||||||
noomP_Node *program;
|
noomP_Node *program;
|
||||||
|
noomP_Node *last_node;
|
||||||
|
|
||||||
int success = noomP_parse(code, "shitass", &program);
|
int success = noomP_parse(code, "shitass", &program, &last_node);
|
||||||
if (success != 0) return success;
|
if (success != 0) return success;
|
||||||
|
|
||||||
print_node(program, 0);
|
print_node(program, 0);
|
||||||
|
|
||||||
|
// freeing time
|
||||||
|
|
||||||
|
while (last_node) {
|
||||||
|
noomP_Node* next = last_node->previous_node;
|
||||||
|
noom_free(last_node->subnodes);
|
||||||
|
noom_free(last_node);
|
||||||
|
last_node = next;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ noomP_Node* noomP_parseStatement(noomP_Parser* parser) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int noomP_parse(const char* code, const char* filename, noomP_Node** outpointer) {
|
int noomP_parse(const char* code, const char* filename, noomP_Node** outpointer, noomP_Node** last_node) {
|
||||||
noomP_Parser parser;
|
noomP_Parser parser;
|
||||||
noomP_initParser(&parser, code, filename);
|
noomP_initParser(&parser, code, filename);
|
||||||
|
|
||||||
@@ -168,6 +168,7 @@ int noomP_parse(const char* code, const char* filename, noomP_Node** outpointer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*outpointer = node;
|
*outpointer = node;
|
||||||
|
*last_node = parser.last_node;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ noomP_Node* noomP_allocNode(noomP_Parser* parser);
|
|||||||
noomP_Node* noomP_parseStatement(noomP_Parser* parser);
|
noomP_Node* noomP_parseStatement(noomP_Parser* parser);
|
||||||
noomP_Node* noomP_parseExpression(noomP_Parser* parser);
|
noomP_Node* noomP_parseExpression(noomP_Parser* parser);
|
||||||
|
|
||||||
int noomP_parse(const char* code, const char* filename, noomP_Node** outpointer);
|
int noomP_parse(const char* code, const char* filename, noomP_Node** outpointer, noomP_Node** last_node);
|
||||||
|
|
||||||
int noomP_initParser(noomP_Parser* parser, const char* code, const char* filename);
|
int noomP_initParser(noomP_Parser* parser, const char* code, const char* filename);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user