Updated parser

This commit is contained in:
2022-11-26 01:59:37 +00:00
parent 30c3a890ee
commit 4cf5c6a5bf
7 changed files with 107 additions and 167 deletions

View File

@@ -3,8 +3,8 @@ CC=gcc
IDIR +=. ../source ../repl
CFLAGS +=$(addprefix -I,$(IDIR)) -g -Wall -W -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable
LIBS +=
ODIR = obj
#TARGETS = $(wildcard ../source/*.c) $(wildcard ../repl/lib_*.c)
#literal primitives
@@ -17,7 +17,7 @@ TARGETS+=../source/toy_common.c ../source/keyword_types.c ../source/lexer.c
TARGETS+=../source/ast_node.c
#parser
#TARGETS+=
TARGETS+=../source/parser.c
TESTS = $(wildcard test_*.c)
OBJ = $(addprefix $(ODIR)/,$(TARGETS:../source/%.c=%.o)) $(addprefix $(ODIR)/,$(TESTS:.c=.o))

View File

@@ -72,18 +72,18 @@ int main() {
return -1;
}
if (node->type != AST_NODEUNARY || node->unary.opcode != OP_PRINT) {
fprintf(stderr, ERROR "ERROR: ASTNode is not a print instruction" RESET);
if (node->type != AST_NODE_UNARY || node->unary.opcode != OP_PRINT) {
fprintf(stderr, ERROR "ERROR: ASTNode is not a unary print instruction" RESET);
return -1;
}
if (node->unary.child->type != AST_NODELITERAL || !IS_NULL(node->unary.child->atomic.literal)) {
fprintf(stderr, ERROR "ERROR: ASTNode to be printed is not a null value" RESET);
if (node->unary.child->type != AST_NODE_LITERAL || !IS_NULL(node->unary.child->atomic.literal)) {
fprintf(stderr, ERROR "ERROR: ASTNode to be printed is not a null literal" RESET);
return -1;
}
//cleanup
freeNode(node);
freeASTNode(node);
freeParser(&parser);
}
@@ -101,12 +101,12 @@ int main() {
ASTNode* node = scanParser(&parser);
while (node != NULL) {
if (node->type == AST_NODEERROR) {
if (node->type == AST_NODE_ERROR) {
fprintf(stderr, ERROR "ERROR: Error node detected" RESET);
return -1;
}
freeNode(node);
freeASTNode(node);
node = scanParser(&parser);
}
@@ -114,6 +114,7 @@ int main() {
freeParser(&parser);
free((void*)source);
}
printf(NOTICE "All good\n" RESET);
return 0;
}