Remove TOPTREE

This commit is contained in:
bʰedoh₂ swé 2024-06-03 23:55:02 +05:00
parent 9764aff184
commit 7ed5367f20
4 changed files with 4 additions and 10 deletions

View File

@ -9,7 +9,7 @@
struct SyntaxElement* parse(FILE* file) { struct SyntaxElement* parse(FILE* file) {
struct SyntaxElement* syntaxtree = se_create(); struct SyntaxElement* syntaxtree = se_create();
struct SyntaxElement* syntaxtreestart = syntaxtree; struct SyntaxElement* syntaxtreestart = syntaxtree;
syntaxtree->type = TOPTREE; syntaxtree->type = TREE;
char symbol; char symbol;
bool intree = false; bool intree = false;
bool incomment = false; bool incomment = false;
@ -72,7 +72,7 @@ struct SyntaxElement* parse(FILE* file) {
syntaxtree = se_bottom(syntaxtree); syntaxtree = se_bottom(syntaxtree);
break; break;
case ')': case ')':
if (syntaxtree->top->type == TOPTREE) { if (syntaxtree->top->type == TREE) {
intree = false; intree = false;
syntaxtree = syntaxtree->top; syntaxtree = syntaxtree->top;
syntaxtree = se_next(syntaxtree); syntaxtree = se_next(syntaxtree);
@ -107,7 +107,7 @@ struct SyntaxElement* parse(FILE* file) {
continue; continue;
case '(': case '(':
intree = true; intree = true;
syntaxtree->type = TOPTREE; syntaxtree->type = TREE;
syntaxtree = se_bottom(syntaxtree); syntaxtree = se_bottom(syntaxtree);
syntaxtree->type = TREE; syntaxtree->type = TREE;
continue; continue;

View File

@ -9,10 +9,6 @@ void printtree(struct SyntaxElement* syntaxtree, int depth) {
for (int i = 1; i <= depth; i++) for (int i = 1; i <= depth; i++)
putc(' ',stdout); putc(' ',stdout);
switch (syntaxtree->type) { switch (syntaxtree->type) {
case TOPTREE:
printf("TOPTREE\n");
printtree((struct SyntaxElement*)syntaxtree->content, depth + 1);
break;
case TREE: case TREE:
printf("TREE\n"); printf("TREE\n");
printtree((struct SyntaxElement*)syntaxtree->content, depth + 1); printtree((struct SyntaxElement*)syntaxtree->content, depth + 1);

View File

@ -30,7 +30,6 @@ void se_free(struct SyntaxElement* syntaxtree) {
free(syntaxtree); free(syntaxtree);
return; return;
case TREE: case TREE:
case TOPTREE:
if (syntaxtree->content != NULL) { if (syntaxtree->content != NULL) {
se_free((struct SyntaxElement*)syntaxtree->content); se_free((struct SyntaxElement*)syntaxtree->content);
} }
@ -58,7 +57,7 @@ void se_clean(struct SyntaxElement* syntaxtree) {
break; break;
} }
} }
if (syntaxtree->content != NULL && (syntaxtree->type == TOPTREE || syntaxtree->type == TREE)) { if (syntaxtree->content != NULL && (syntaxtree->type == TREE)) {
switch (((struct SyntaxElement*)syntaxtree->content)->type) { switch (((struct SyntaxElement*)syntaxtree->content)->type) {
case NONE: case NONE:
free(syntaxtree->content); free(syntaxtree->content);

View File

@ -1,7 +1,6 @@
#ifndef SYNTAX_H #ifndef SYNTAX_H
#define SYNTAX_H #define SYNTAX_H
enum SyntaxElementType { enum SyntaxElementType {
TOPTREE,
TREE, TREE,
TOKEN, TOKEN,
STRING, STRING,