diff --git a/src/extstring.c b/src/extstring.c index f2fb558..3886a60 100644 --- a/src/extstring.c +++ b/src/extstring.c @@ -1,34 +1,34 @@ #include #include "extstring.h" -void es_addsymbol(struct Extstring* string, char symbol) { +void es_addsymbol(tExtstring* string, char symbol) { if (string == NULL) return; - struct Extstring* ptr = string; + tExtstring* ptr = string; while (ptr->next != NULL) { ptr = ptr->next; }; - ptr->next = malloc(sizeof(struct Extstring)); + ptr->next = malloc(sizeof(tExtstring)); ptr->next->symbol = symbol; return; } -int es_size(struct Extstring* string) { +int es_size(tExtstring* string) { int size = 0; - struct Extstring* ptr = string; + tExtstring* ptr = string; for (; ptr != NULL; size++) { ptr = ptr->next; } return size; } -void es_free(struct Extstring* string) { +void es_free(tExtstring* string) { if (string->next == NULL) { free(string); return; } - struct Extstring* ptr = string; - struct Extstring* nextptr = ptr->next; + tExtstring* ptr = string; + tExtstring* nextptr = ptr->next; while (ptr->next != NULL) { nextptr = ptr->next; free(ptr); @@ -37,8 +37,8 @@ void es_free(struct Extstring* string) { free(ptr); } -char* es_tostring(struct Extstring* string) { - struct Extstring* ptr = string; +char* es_tostring(tExtstring* string) { + tExtstring* ptr = string; int size = es_size(string) + 1; char* cstring = malloc(size); for (int i = 0; i != size; i++) { diff --git a/src/extstring.h b/src/extstring.h index b4d7a16..6c77c33 100644 --- a/src/extstring.h +++ b/src/extstring.h @@ -1,9 +1,9 @@ -struct Extstring { +typedef struct Extstring { char symbol; struct Extstring* next; -}; +} tExtstring; -void es_addsymbol(struct Extstring* string, char symbol); -int es_size(struct Extstring* string); -void es_free(struct Extstring* string); -char* es_tostring(struct Extstring* string); +void es_addsymbol(tExtstring* string, char symbol); +int es_size(tExtstring* string); +void es_free(tExtstring* string); +char* es_tostring(tExtstring* string); diff --git a/src/main.c b/src/main.c index 3a6b8e6..103525c 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { fprintf(stderr,"Unable to open file.\n"); return 1; } - struct SyntaxElement* code = parse(file); + tSyntaxElement* code = parse(file); fclose(file); if (code == NULL) { fprintf(stderr, "Error during parsing.\n"); diff --git a/src/parser.c b/src/parser.c index b0e999f..46b92cd 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3,20 +3,20 @@ #include #include -#include "syntax.h" +#include "parser.h" #include "extstring.h" -struct SyntaxElement* parse(FILE* file) { - struct SyntaxElement* syntaxtree = se_create(); - struct SyntaxElement* syntaxtreestart = syntaxtree; +tSyntaxElement* parse(FILE* file) { + tSyntaxElement* syntaxtree = se_create(); + tSyntaxElement* syntaxtreestart = syntaxtree; syntaxtree->type = TREE; char symbol; bool intree = false; bool incomment = false; bool instring = false; bool intoken = false; - struct Extstring* exttoken = NULL; - struct Extstring* extstring = NULL; + tExtstring* exttoken = NULL; + tExtstring* extstring = NULL; while (1) { symbol = fgetc(file); if (feof(file)) @@ -29,7 +29,7 @@ struct SyntaxElement* parse(FILE* file) { if (instring) { if (symbol == '"') { if (extstring == NULL) { - extstring = malloc(sizeof(struct Extstring)); + extstring = malloc(sizeof(tExtstring)); extstring->next = NULL; } instring = false; @@ -41,7 +41,7 @@ struct SyntaxElement* parse(FILE* file) { syntaxtree = se_next(syntaxtree); } else { if (extstring == NULL) { - extstring = malloc(sizeof(struct Extstring)); + extstring = malloc(sizeof(tExtstring)); extstring->symbol = symbol; extstring->next = NULL; continue; @@ -90,7 +90,7 @@ struct SyntaxElement* parse(FILE* file) { instring = true; continue; default: - exttoken = malloc(sizeof(struct Extstring)); + exttoken = malloc(sizeof(tExtstring)); exttoken->symbol = symbol; exttoken->next = NULL; intoken = true; diff --git a/src/parser.h b/src/parser.h index 284b659..7cf713d 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,3 +1,5 @@ #include -struct SyntaxElement* parse(FILE* file); +#include "syntax.h" + +tSyntaxElement* parse(FILE* file); diff --git a/src/printtree.c b/src/printtree.c index f7c02e5..cb01238 100644 --- a/src/printtree.c +++ b/src/printtree.c @@ -3,7 +3,7 @@ #include "syntax.h" -void printtree(struct SyntaxElement* syntaxtree, int depth) { +void printtree(tSyntaxElement* syntaxtree, int depth) { if (syntaxtree == NULL) return; for (int i = 1; i <= depth; i++) @@ -11,7 +11,7 @@ void printtree(struct SyntaxElement* syntaxtree, int depth) { switch (syntaxtree->type) { case TREE: printf("TREE\n"); - printtree((struct SyntaxElement*)syntaxtree->content, depth + 1); + printtree((tSyntaxElement*)syntaxtree->content, depth + 1); break; case TOKEN: printf("TOKEN: %s\n", (char*)syntaxtree->content); diff --git a/src/printtree.h b/src/printtree.h index 87dd6d2..899e49a 100644 --- a/src/printtree.h +++ b/src/printtree.h @@ -1,2 +1,2 @@ #include "parser.h" -void printtree(struct SyntaxElement* syntaxtree, int depth); +void printtree(tSyntaxElement* syntaxtree, int depth); diff --git a/src/syntax.c b/src/syntax.c index c0fa0cf..91560ec 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -2,12 +2,12 @@ #include "syntax.h" -bool se_istraversable(struct SyntaxElement* syntaxtree) { +bool se_istraversable(tSyntaxElement* syntaxtree) { return syntaxtree->type == TREE && syntaxtree->content != NULL; } -struct SyntaxElement* se_create(void) { - struct SyntaxElement* syntaxelement = malloc(sizeof(struct SyntaxElement)); +tSyntaxElement* se_create(void) { + tSyntaxElement* syntaxelement = malloc(sizeof(tSyntaxElement)); syntaxelement->type = NONE; syntaxelement->content = NULL; syntaxelement->next = NULL; @@ -16,26 +16,26 @@ struct SyntaxElement* se_create(void) { } -struct SyntaxElement* se_bottom(struct SyntaxElement* syntaxelement) { +tSyntaxElement* se_bottom(tSyntaxElement* syntaxelement) { syntaxelement->content = se_create(); - ((struct SyntaxElement*)syntaxelement->content)->top = syntaxelement; - return ((struct SyntaxElement*)syntaxelement->content); + ((tSyntaxElement*)syntaxelement->content)->top = syntaxelement; + return ((tSyntaxElement*)syntaxelement->content); } -struct SyntaxElement* se_next(struct SyntaxElement* syntaxelement) { +tSyntaxElement* se_next(tSyntaxElement* syntaxelement) { syntaxelement->next = se_create(); syntaxelement->next->top = syntaxelement->top; return syntaxelement->next; } -void se_free(struct SyntaxElement* syntaxtree) { +void se_free(tSyntaxElement* syntaxtree) { switch (syntaxtree->type) { case NONE: free(syntaxtree); return; case TREE: if (syntaxtree->content != NULL) { - se_free((struct SyntaxElement*)syntaxtree->content); + se_free((tSyntaxElement*)syntaxtree->content); } break; default: @@ -49,7 +49,7 @@ void se_free(struct SyntaxElement* syntaxtree) { } // Remove NONEs from the syntax tree. -void se_clean(struct SyntaxElement* syntaxtree) { +void se_clean(tSyntaxElement* syntaxtree) { if (syntaxtree->next != NULL) { switch (syntaxtree->next->type) { case NONE: @@ -62,13 +62,13 @@ void se_clean(struct SyntaxElement* syntaxtree) { } } if (syntaxtree->content != NULL && (syntaxtree->type == TREE)) { - switch (((struct SyntaxElement*)syntaxtree->content)->type) { + switch (((tSyntaxElement*)syntaxtree->content)->type) { case NONE: free(syntaxtree->content); syntaxtree->content = NULL; break; default: - se_clean((struct SyntaxElement*)syntaxtree->content); + se_clean((tSyntaxElement*)syntaxtree->content); break; } } diff --git a/src/syntax.h b/src/syntax.h index 83e83a9..099f331 100644 --- a/src/syntax.h +++ b/src/syntax.h @@ -10,18 +10,18 @@ enum SyntaxElementType { NONE }; -struct SyntaxElement { +typedef struct SyntaxElement { enum SyntaxElementType type; void* content; struct SyntaxElement* next; struct SyntaxElement* top; -}; +} tSyntaxElement; -void se_clean(struct SyntaxElement* syntaxtree); -bool se_istraversable(struct SyntaxElement* syntaxtree); -struct SyntaxElement* se_create(void); -struct SyntaxElement* se_init(void); -struct SyntaxElement* se_bottom(struct SyntaxElement* syntaxelement); -struct SyntaxElement* se_next(struct SyntaxElement* syntaxelement); -void se_free(struct SyntaxElement* syntaxtree); +void se_clean(tSyntaxElement* syntaxtree); +bool se_istraversable(tSyntaxElement* syntaxtree); +tSyntaxElement* se_create(void); +tSyntaxElement* se_init(void); +tSyntaxElement* se_bottom(tSyntaxElement* syntaxelement); +tSyntaxElement* se_next(tSyntaxElement* syntaxelement); +void se_free(tSyntaxElement* syntaxtree); #endif