From 929e257a8e9d5162d565b820c7d2b265bba77396 Mon Sep 17 00:00:00 2001 From: xerox Date: Thu, 2 Jan 2020 17:46:39 -0800 Subject: [PATCH] Finished cleaning, found/documented issues. --- README.md | 54 +------------- deon.l | 43 +++++------ deon.y | 2 - functions/functions.c | 10 +-- functions/functions.h | 5 +- includes/include.h | 21 +----- linked_list/linked_list.c | 35 ++++----- linked_list/linked_list.h | 5 +- logic/logic.c | 35 ++++----- logic/logic.h | 7 +- networking/main.c | 12 ---- networking/socket.h | 134 ---------------------------------- networking/template.dn | 17 ----- networking/test.c | 87 ----------------------- parser/parser.c | 146 +++++++++++--------------------------- parser/parser.h | 5 +- print/print.c | 35 +++------ print/print.h | 5 +- vars/vars.c | 47 ++++++------ vars/vars.h | 5 +- 20 files changed, 144 insertions(+), 566 deletions(-) delete mode 100755 networking/main.c delete mode 100755 networking/socket.h delete mode 100755 networking/template.dn delete mode 100755 networking/test.c diff --git a/README.md b/README.md index 1615889..770532b 100755 --- a/README.md +++ b/README.md @@ -1,24 +1,7 @@ -# Deon programming language V0.9.2 +# Deon programming language V0.9.2.1 My computer programming language made with LEX/YACC written in C. (interpreted) -V0.9.2 Update notes: - -* major cleaning of the project -* issues found and documented - -V0.9.1 Update notes: - -* Prep for doubly linked lists -* Prep for VOID data type -* Prep for merge/clean - -V0.8 - -* Prep for TCP/IP implementation -* Prep for VOID data type - # Hello World. - ``` def Main : { printf[ "hello world" ]; @@ -26,12 +9,9 @@ def Main : { call Main; ``` Requirements to making a program: - 1.) a struct/function. - 2.) a call statement. - # Variables Variables are stored in a hashmap for quick and easy access. Variables also support type juggling. When you define a variable its type will be assumed when parsed. @@ -42,34 +22,6 @@ mystring = "cool string"; mychar = 'c'; // char myfunction = { printf[ "hello world" ]; }; (statement list) ``` -Variables are scoped to the struct that they are defined in. This is so everything is not global. An example of this would look: -``` -def MyDog : { - age = -153000; - name = "i dont have a name"; - printfMyName = { - printf[ name ]; - }; -}; - -def Main : { - someOtherAge = 2; - myRealDogsName = "cat"; // because variable naming is the hardest thing in computer science. - printfMyName = { - printf[ someOtherAge ]; - }; - - call MyDog::printfMyName; - /* - When you do not use the scope resolution modifier then it will only check local functions. - The local function hashmap is stored in the head of your functions linked list. - /* - call printfMyName; -}; - -call Main; -``` - # Logic Logic is first evaluated and if deemed valid then a list of statements will be executed. ``` @@ -82,18 +34,14 @@ if [ {int} newInt > 99 ]: { printf [ "newInt is bigger than 99" ]; }; ``` - # Functions - Functions can be declared inside of a struct and accessed by anyone who uses the scope resolution operator. Do not mistake structs as functions just because you can interact with them in the same way. Functions do not have "scope" like structs do. Functions can interact with all elements in the parenting struct including other functions, and those functions local variables. - ``` def NewStruct : { someFunction = { printf[ "hello world" ]; }; }; - call NewStruct; ``` diff --git a/deon.l b/deon.l index 3771927..fb4d034 100755 --- a/deon.l +++ b/deon.l @@ -43,43 +43,38 @@ int yywrap(void) { } -int main(int argc, char* argv[]) { - +int main(int argc, char* argv[]) +{ FILE *fh; - - if (argc > 1) { - + if (argc > 1) + { if (strcmp(argv[1],"help") == 0 || strcmp(argv[1],"-help") == 0 || strcmp(argv[1],"--help") == 0 || strcmp(argv[1],"h") == 0 - || strcmp(argv[1],"-h") == 0) { - + || strcmp(argv[1],"-h") == 0) + { printf("[ HELP ] put a file/path as the first flag.\n"); printf("[ HELP ] -h, -help, --help, help, h: Prints this.\n"); printf("[ HELP ] -d, d, -debug, debug: Enter REPL mode.\n"); - - } else if (strcmp(argv[1],"-debug") == 0 || strcmp(argv[1],"-d") == 0 - || strcmp(argv[1],"d") == 0 || strcmp(argv[1],"debug") == 0) { + } + else if (strcmp(argv[1],"-debug") == 0 || strcmp(argv[1],"-d") == 0 + || strcmp(argv[1],"d") == 0 || strcmp(argv[1],"debug") == 0) + { _DEBUG = 1; printf(">>> "); - yyparse(); - - } else if (fh = fopen(argv[1], "r")){ - + yyparse(); + } + else if (fh = fopen(argv[1], "r")) + { yyin = fh; yyparse(); fclose(fh); - - } else { - + } + else + { printf("[ ERROR ] please enter a correct command. try --help\n"); - + fclose(fh); } - - } else { - + } else printf("[ ERROR ] missing input file. Try --help?\n"); - - } - return 0; } \ No newline at end of file diff --git a/deon.y b/deon.y index 3c54322..d3ee10e 100755 --- a/deon.y +++ b/deon.y @@ -126,8 +126,6 @@ print: %% void yyerror(char *s) { - fprintf(stderr, "Error on line %d, %s\n", yylineno, s); - } diff --git a/functions/functions.c b/functions/functions.c index 80eb30a..155e7f9 100755 --- a/functions/functions.c +++ b/functions/functions.c @@ -13,7 +13,6 @@ * @return nodeInfo * to head */ node_info *create_function(char *pName, node_info *pStmts) { - node_info *newNode = malloc(sizeof(node_info)); newNode->type = FUNCTION; newNode->name = pName; @@ -21,7 +20,6 @@ node_info *create_function(char *pName, node_info *pStmts) { newNode->_function_body->next = copy_linked_list(pStmts); _free_linked_list(pStmts); return newNode; - } /** @@ -31,7 +29,6 @@ node_info *create_function(char *pName, node_info *pStmts) { * @return a node_info pointer to the head of the function */ node_info *create_function_call(char *pName) { - node_info *newNode = malloc(sizeof(node_info)); newNode->type = FUNCTION_CALL; newNode->name = pName; @@ -49,17 +46,13 @@ node_info *create_compound_statement(node_info *new_statement_list, node_info *s if(statement_head == NULL) { statement_head = malloc(sizeof(node_info)); - node_info *newNode = malloc(sizeof(node_info)); - statement_head->opperation = 5; statement_head->next = new_statement_list; statement_head->next->next = NULL; statement_head->statement_list = NULL; - } else { - - node_info *p = statement_head; //make a temp of list head, so we can traverse it. + node_info *p = statement_head; //TODO update with doubly linked list while(p->statement_list != NULL) p = p->statement_list; @@ -70,5 +63,4 @@ node_info *create_compound_statement(node_info *new_statement_list, node_info *s } return statement_head; - } \ No newline at end of file diff --git a/functions/functions.h b/functions/functions.h index 154e059..506269e 100755 --- a/functions/functions.h +++ b/functions/functions.h @@ -1,5 +1,8 @@ +#ifndef FUNCTIONS +#define FUNCTIONS #include "../includes/include.h" node_info *create_function(char *pName, node_info *pStmts); node_info *create_function_call(char *pName); -node_info *create_compound_statement(node_info *new_statement_list, node_info *statement_head); \ No newline at end of file +node_info *create_compound_statement(node_info *new_statement_list, node_info *statement_head); +#endif \ No newline at end of file diff --git a/includes/include.h b/includes/include.h index b524c86..ff913b8 100644 --- a/includes/include.h +++ b/includes/include.h @@ -9,44 +9,34 @@ * VariableType is a enum of varible types that will be inside of my language. */ typedef enum variable_type { - VAR_STRING, VAR_INT, VAR_CHAR, VAR_DOUBLE, VAR_VOID - } variable_type; /** * VariableValues is a struct that holds all possible variable values */ typedef struct variable_values { - variable_type type; char _char; char *_string; int _int; double _double; void* _void_pointer; //TODO create a concept of "void" - - } variable_values; - /** * Variables is a struct that has all the information needed for a variables */ typedef struct variable{ - char *name; variable_values *value; struct Variable *next; - } variable; - - typedef struct print { int opperation; @@ -56,20 +46,16 @@ typedef struct print { } print; typedef struct logic { - int opperation; int expr; struct node_info *if_true; struct node_info *else_false; struct node_info *while_true; - } logic; typedef struct node_info { - - int opperation; - + int opperation; enum type{ ASSIGNMENT, @@ -80,8 +66,6 @@ typedef struct node_info { FUNCTION_CALL }type; - - char *name; variable *var; print printExpression; @@ -91,8 +75,5 @@ typedef struct node_info { struct node_info *statement_list; struct node_info *local_list; struct map_void_t *_var_list; - - } node_info; - #endif \ No newline at end of file diff --git a/linked_list/linked_list.c b/linked_list/linked_list.c index c7e24d2..d620fe9 100644 --- a/linked_list/linked_list.c +++ b/linked_list/linked_list.c @@ -1,5 +1,4 @@ #include - #include "linked_list.h" /** @@ -7,18 +6,13 @@ * @param head of linked list to be freed * @return void */ -void _free_linked_list(node_info *pList) { - +void _free_linked_list(node_info *p_list) { node_info *temp; - - while(pList->next != NULL) { - - temp = pList; - pList = pList->next; + while(p_list->next != NULL) { + temp = p_list; + p_list = p_list->next; free(temp); - } - } /** @@ -26,19 +20,14 @@ void _free_linked_list(node_info *pList) { * @param nodeInfo list to be copied * @return copied list */ -node_info *copy_linked_list(node_info *pList) { - - node_info *newList = malloc(sizeof(node_info)); - newList->next = NULL; - node_info *copy_list = newList; - while(pList->next != NULL) { - - pList = pList->next; - copy_list->next = pList; +node_info *copy_linked_list(node_info *p_list) { + node_info *new_list = malloc(sizeof(node_info)); + new_list->next = NULL; + node_info *copy_list = new_list; + while(p_list->next != NULL) { + p_list = p_list->next; + copy_list->next = p_list; copy_list = copy_list->next; - } - - return newList; - + return new_list; } \ No newline at end of file diff --git a/linked_list/linked_list.h b/linked_list/linked_list.h index df73f0e..4407d27 100644 --- a/linked_list/linked_list.h +++ b/linked_list/linked_list.h @@ -1,4 +1,7 @@ +#ifndef LINKED_LIST_H +#define LINKED_LIST_H #include "../includes/include.h" void _free_linked_list(node_info *pList); -node_info *copy_linked_list(node_info *pList); \ No newline at end of file +node_info *copy_linked_list(node_info *pList); +#endif \ No newline at end of file diff --git a/logic/logic.c b/logic/logic.c index 7ea9f77..4dd3a61 100644 --- a/logic/logic.c +++ b/logic/logic.c @@ -1,39 +1,30 @@ #include "../includes/include.h" -node_info *create_logic(int opperation, int expr, node_info *statement_list, node_info *else_false) { - +/* + * WARNING! do not use this function, it is old and outdated, and is missing alot of new features! + */ +node_info *create_logic(int opperation, int expr, node_info *statement_list, node_info *else_false) +{ node_info *n = malloc(sizeof(node_info)); - - switch (opperation) { - //if statement - case 1: - //logical expression, see node_info for opperation info + switch (opperation) + { + case 1: //if statement n->opperation = 4; logic a; a.opperation = 1; a.expr = expr; - - while (statement_list->statement_list != NULL) { - + while (statement_list->statement_list) statement_list = statement_list->statement_list; - - } - - //now that we have the statement list, we need to make the head opperation 5 node_info *newNode = malloc(sizeof(node_info)); newNode->opperation = 5; newNode->next = copy_linked_list(statement_list); _free_linked_list(statement_list); a.if_true = newNode; - - //this removes the last statement list in statementHead statement_list = NULL; n->logicalExpression = a; return n; - break; - //while loop - case 2: - + + case 2: //while loop /*n->opperation = 4; logic b; b.opperation = 2; @@ -43,10 +34,8 @@ node_info *create_logic(int opperation, int expr, node_info *statement_list, nod n->logicalExpression = b; return n;*/ break; - default: printf("check your yacc file for logical statements\n"); - } - + } } \ No newline at end of file diff --git a/logic/logic.h b/logic/logic.h index 9f84c1b..95c3ad8 100644 --- a/logic/logic.h +++ b/logic/logic.h @@ -1 +1,6 @@ -node_info *createLogic(int opperation, int expr, node_info *statement_list, node_info *else_false); \ No newline at end of file +#ifndef LOGIC_H +#define LOGIC_H + +node_info *createLogic(int opperation, int expr, node_info *statement_list, node_info *else_false); + +#endif \ No newline at end of file diff --git a/networking/main.c b/networking/main.c deleted file mode 100755 index bf7c74f..0000000 --- a/networking/main.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "socket.h" - -int main() { - - Socket news = create_lsocket(5001, 5); - - printf("Created socket!\n"); - sleep(10); - - return 0; -} \ No newline at end of file diff --git a/networking/socket.h b/networking/socket.h deleted file mode 100755 index 8ed70f3..0000000 --- a/networking/socket.h +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/** - * - * socket struct for building sockets... - * This will hold both listening sockets and connection sockets - * TCP AND UDP! - * - */ -typedef struct Socket { - - int socketfd; //socket id - int client_socketfd; // this is the int you get when you call accept() - int port; // port information - struct sockaddr_in address; // sockaddr_in struct - struct Socket *next; // next in the linked list - -} Socket; -//head of the linked list of sockets -struct Socket *_socket_head = NULL; -/** - * This is used by a thread to listen for incoming - * connections - * - */ - -void doprocessing (int sock) { - int n; - char buffer[256]; - bzero(buffer,256); - while(1) { - n = read(sock,buffer,255); - - if (n < 0) { - perror("ERROR reading from socket"); - exit(1); - } - - printf("Here is the message: %s\n",buffer); - n = write(sock,"I got your message",18); - - if (n < 0) { - perror("ERROR writing to socket"); - exit(1); - } - } - -} -/** - * - * This function creates a listening function... - * @params takes a an int for a port. - * @return An active listening socket for incoming connections - * - */ -Socket create_lsocket(int _port, int _connection_amount) { - - Socket *newSocket = malloc(sizeof(Socket)); - - //sockaddr_in struct stuff (making a new sockaddr_in and giving it details) - struct sockaddr_in address; // make a struct of type sockaddr_in - int addr_size = sizeof(address); // size of addess in decimal form - - // filling our struct with info - address.sin_family = AF_INET; //ipv4.... - address.sin_addr.s_addr = INADDR_ANY; // any local address I.E :0.0.0.0 - address.sin_port = htons(_port); // htons takes a decimal number and converts it to network - - - //this is a socket handler, like a file handler... - int socketfd = socket(AF_INET, SOCK_STREAM, 0); - - // if the socks returns 0 then exit - if (socketfd == 0) { - - printf("SOCKET FAILED!\n"); - exit(1); - - } - - //lets bind that socket now - int bindRes = bind(socketfd, (struct sockaddr *)&address, sizeof(address)); - if(bindRes < 0) { - - printf("BIND FAILED! WITH CODE: %d\n", bindRes); - exit(1); - - } - - listen(socketfd, 5); - while(1) { - - int newsockfd = accept(socketfd, (struct sockaddr *) &address, &addr_size); - - if (newsockfd < 0) { - - printf("ERROR LISTENING!\n"); - exit(1); - - } - int pid = fork(); - if (pid == 0) { - - printf("NEW CLIENT!\n"); - doprocessing(newsockfd); - exit(0); - - } - - } - - newSocket->socketfd = socketfd; - newSocket->port = _port; - newSocket->address = address; - newSocket->next = NULL; - // if the socket head is empty we are going to malloc the head and then start - // the linked list of sockets - if (_socket_head == NULL) { - - _socket_head = malloc(sizeof(Socket)); - _socket_head->next = newSocket; - - - } - - -} - - diff --git a/networking/template.dn b/networking/template.dn deleted file mode 100755 index 6c25805..0000000 --- a/networking/template.dn +++ /dev/null @@ -1,17 +0,0 @@ -socket = l_SOCKET("0.0.0.0", 90); //creates a server socket -client = C_SOCKET("127.0.0.1", 90); // creates a client -socket.template = { - - "HEADER-DATA" : varToSaveData : call responce;, - "SOMEOTHER-HEADER" : varToSaveData : call responce; - -} - - -client.plan = { - - - - - -} \ No newline at end of file diff --git a/networking/test.c b/networking/test.c deleted file mode 100755 index d9147e2..0000000 --- a/networking/test.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include -#include -#include - - -void doprocessing (int sock) { - int n; - char buffer[256]; - bzero(buffer,256); - while(1) { - n = read(sock,buffer,255); - - if (n < 0) { - perror("ERROR reading from socket"); - exit(1); - } - - printf("Here is the message: %s\n",buffer); - n = write(sock,"I got your message",18); - - if (n < 0) { - perror("ERROR writing to socket"); - exit(1); - } - } - -} - -int main() { - - int port = 5001; - struct sockaddr_in address; - int clilen = sizeof(address); - address.sin_family = AF_INET; - address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = htons(port); - - int socketHandler = socket(AF_INET, SOCK_STREAM, 0); - - if (socketHandler == 0) { - - printf("SOCKET FAILED!\n"); - return 1; - - } else { - - printf("SETUP SOCKET!\n"); - } - int bindRes = bind(socketHandler, (struct sockaddr *)&address, sizeof(address)); - if(bindRes < 0) { - - printf("BIND FAILED! CODE: %d\n", bindRes); - - } else { - - printf("BINDED SOCKET!\n"); - - } - listen(socketHandler, 5); - while(1) { - - int newsockfd = accept(socketHandler, (struct sockaddr *) &address, &clilen); - - if (newsockfd < 0) { - - printf("ERROR LISTENING!\n"); - exit(1); - - } - int pid = fork(); - if (pid == 0) { - - printf("NEW CLIENT!\n"); - doprocessing(newsockfd); - exit(0); - - } - - - - } - - return 0; -} \ No newline at end of file diff --git a/parser/parser.c b/parser/parser.c index 0e86ba8..ff9701c 100755 --- a/parser/parser.c +++ b/parser/parser.c @@ -5,53 +5,44 @@ //hashmaps/link list heads extern map_void_t *_var_map; extern node_info *_temp_statement_head; -//struct variable *_var_head = NULL; +//struct variable *_var_head = NULL; extern map_void_t *_function_list; -node_info* create_var_assignment_string(char *pName, char *pString) { - - node_info *newNode = malloc(sizeof(node_info)); - variable *newVar = make_variable_string(pName, pString); +node_info* create_var_assignment_string(char *p_name, char *value) { + node_info *new_node = malloc(sizeof(node_info)); + variable *new_var = make_variable_string(p_name, value); newNode->type = ASSIGNMENT; newNode->opperation = 1; - newNode->var = newVar; - return newNode; - + newNode->var = new_var; + return new_node; } -node_info* create_var_assignment_int(char *pName, int number) { - - node_info *newNode = malloc(sizeof(node_info)); - variable *newVar = make_variable_int(pName, number); +node_info* create_var_assignment_int(char *p_name, int value) { + node_info *new_node = malloc(sizeof(node_info)); + variable *new_var = make_variable_int(p_name, value); newNode->type = ASSIGNMENT; newNode->opperation = 1; - newNode->var = newVar; - return newNode; - + newNode->var = new_var; + return new_node; } -node_info* create_var_assignment_char(char *pName, char Char) { - - node_info *newNode = malloc(sizeof(node_info)); - variable *newVar = make_variable_char(pName, Char); +node_info* create_var_assignment_char(char *p_name, char value) { + node_info *new_node = malloc(sizeof(node_info)); + variable *new_var = make_variable_char(p_name, value); newNode->type = ASSIGNMENT; newNode->opperation = 1; - newNode->var = newVar; - return newNode; - + newNode->var = new_var; + return new_node; } -node_info* create_var_assignment_double(char *pName, double Double) { - - node_info *newNode = malloc(sizeof(node_info)); - variable *newVar = make_variable_double(pName, Double); - +node_info* create_var_assignment_double(char *p_name, double value) { + node_info *new_node = malloc(sizeof(node_info)); + variable *new_var = make_variable_double(p_name, value); //new node stuff newNode->type = ASSIGNMENT; newNode->opperation = 1; newNode->var = newVar; - return newNode; - + return new_node; } @@ -74,27 +65,20 @@ node_info* add_to_compound_statement(node_info *new_statement, node_info *statem } else { node_info *p = statement_head; //make a temp of list head, so we can traverse it. - + //TODO replace with double linked list end - while (p->statement_list != NULL) { - + while (p->statement_list) p = p->statement_list; - - } + //TODO replace with double linked list end - while (p->next != NULL) { - + while (p->next) p = p->next; - - } p->next = malloc(sizeof(node_info)); p->next = new_statement; p->next->next = NULL; - } return statement_head; - } /* @@ -105,21 +89,18 @@ Executes a statment. */ //TODO return bool or int detailing the status of execution. -void ex(node_info *n) { - - switch(n->opperation){ - +void ex(node_info *n) +{ + switch(n->opperation) + { case 1: add_var(n->var->name, n->var->value, _var_map); break; //TODO expression stuff case 2: - break; - //print case 3: - switch(n->printExpression.opperation) { case 1: @@ -128,102 +109,64 @@ void ex(node_info *n) { case 2: printf("%s\n", n->printExpression.string); break; - case 3: printf("%s%lf\n", n->printExpression.string, n->printExpression.value); break; - default: printf("{ERROR} CHECK YACC FILE FOR INCORRECT PRINT\n"); - } - break; //logic (if, while, for, etc) case 4: - switch(n->logicalExpression.opperation) { case 1: - - if (n->logicalExpression.expr == 1) { - + if (n->logicalExpression.expr == 1) ex(n->logicalExpression.if_true); - - } break; - case 2: - - while (n->logicalExpression.expr == 1) { - + while (n->logicalExpression.expr == 1) ex(n->logicalExpression.while_true); - - } break; - default: - printf("{ERROR} SOMETHING WRONG WITH LOGICAL EXPRESSION CHECK YACC\n"); - exit(1); - } break; - case 5: - while(n->next != NULL) { - + while(n->next != NULL) + { n = n->next; - ex(n); - + ex(n); } break; - case 6: ; variable_values *value = get_value(n->name, _var_map); - - switch(value->type) { - - case VAR_STRING: - + switch(value->type) + { + case VAR_STRING: printf("%s\n", value->_string); - break; - case VAR_INT: - printf("%d\n", value->_int); break; - case VAR_CHAR: - printf("%c\n", value->_char); break; - - case VAR_DOUBLE: - printf("%f\n", value->_double); break; - case VAR_VOID: //TODO add void variable type break; - default: - printf("{ERROR} NO SUCH VARIABLE TYPE CHECK YACC!\n"); - exit(1); - } - break; //TODO update default to case 7 for functions default: ; - - switch(n->type) { - + switch(n->type) + { case FUNCTION_CALL: ; //gets the statements of a function with the provided name @@ -233,33 +176,26 @@ void ex(node_info *n) { ex(_stmts); } break; - case FUNCTION: ; //if the list of functions already defined is null then we malloc space for it. - if (_function_list == NULL) { - + if (!_function_list) + { _function_list = malloc(sizeof(map_void_t)); n->_var_list = malloc(sizeof(node_info)); - n->next = NULL; n->local_list = NULL; map_init(&*((map_void_t *) _function_list)); map_init(&*((map_void_t *) n->_var_list)); //put the function in the hashmap map_set(&*((map_void_t* ) _function_list), n->name, &*n->_function_body); - } else { //else we dont malloc, we just put the function inside of the hashmap. - + } else //else we dont malloc, we just put the function inside of the hashmap. map_set(&*((map_void_t* ) _function_list), n->name, &*n->_function_body); - - } break; - default: ; //TODO add error here and close } - } } \ No newline at end of file diff --git a/parser/parser.h b/parser/parser.h index 90c509c..6f715e2 100755 --- a/parser/parser.h +++ b/parser/parser.h @@ -1,3 +1,5 @@ +#ifndef PARSER_H +#define PARSER_H #include "../includes/include.h" node_info* create_var_assignment_string(char *pName, char *pString); @@ -8,4 +10,5 @@ node_info* create_print_var_node(char *pVarname); node_info* create_print_statement(int opperation, int value, char *string); node_info* create_logic(int opperation, int expr, node_info *statement_list, node_info *else_false); node_info* add_to_compound_statement(node_info *new_statement, node_info *statement_head); -void ex(node_info *n); \ No newline at end of file +void ex(node_info *n); +#endif \ No newline at end of file diff --git a/print/print.c b/print/print.c index 1cdc3c7..c416168 100644 --- a/print/print.c +++ b/print/print.c @@ -6,13 +6,12 @@ * @param pVarName name of variable to print * @return node_info print statement */ -node_info *create_print_var_node(char *pVarName) { - - node_info *newNode = malloc(sizeof(node_info)); - newNode->opperation = 6; - newNode->name = pVarName; - return newNode; - +node_info *create_print_var_node(char *p_var_name) +{ + node_info *new_node = malloc(sizeof(node_info)); + new_node->opperation = 6; + new_node->name = p_var_name; + return new_node; } /** @@ -23,47 +22,33 @@ node_info *create_print_var_node(char *pVarName) { * */ -node_info *create_print_statement(int opperation, int value, char *string) { - +node_info *create_print_statement(int opperation, int value, char *string) +{ node_info *n = malloc(sizeof(node_info)); print a; - switch(opperation) { - + switch(opperation) + { case 1: - n->opperation = 3;//this needs to not be a magic number lol a.value = value; a.opperation = 1; n->printExpression = a; return n; - break; - //else we are printing a string case 2: - n->opperation = 3; a.string = string; a.opperation = 2; n->printExpression = a; return n; - break; - case 3: - n->opperation = 3; a.string = string; a.opperation = 3; a.value = value; n->printExpression = a; return n; - break; - - - default: - printf("{ERROR} PRINT STATEMENT ERROR IN YACC\n"); - } - } \ No newline at end of file diff --git a/print/print.h b/print/print.h index 0f8c9dc..7bce8ba 100644 --- a/print/print.h +++ b/print/print.h @@ -1,2 +1,5 @@ +#ifndef PRINT_H +#define PRINT_H node_info *create_print_var_node(char *pVarName); -node_info *create_print_statement(int opperation, int value, char *string); \ No newline at end of file +node_info *create_print_statement(int opperation, int value, char *string); +#endif \ No newline at end of file diff --git a/vars/vars.c b/vars/vars.c index 9d3b858..ccdf95d 100755 --- a/vars/vars.c +++ b/vars/vars.c @@ -13,14 +13,14 @@ * @param string for var name * */ -void add_var(char *pName, variable_values *pValues, map_void_t* pVarMap) { - +void add_var(char *p_name, variable_values *p_values, map_void_t* p_var_map) +{ //if variable map is null - if(pVarMap == NULL) { - pVarMap = malloc(sizeof(map_void_t)); - map_init(&*((map_void_t *) pVarMap)); + if(p_var_map == NULL) { + p_var_map = malloc(sizeof(map_void_t)); + map_init(&*((map_void_t *) p_var_map)); } - map_set(&*((map_void_t* ) pVarMap), pName, &*pValues); + map_set(&*((map_void_t* ) p_var_map), p_name, &*p_values); } /** @@ -32,10 +32,9 @@ void add_var(char *pName, variable_values *pValues, map_void_t* pVarMap) { * @param [char *string] Variable name. * */ -variable_values *get_value(char *pName, map_void_t* pVarMap) { - +variable_values *get_value(char *pName, map_void_t* pVarMap) +{ return *map_get(&*((map_void_t* ) pVarMap), pName); - } /** @@ -45,16 +44,15 @@ variable_values *get_value(char *pName, map_void_t* pVarMap) { * @return the head of the linked list which just points to all of the vars * */ -variable* make_variable_int(char *pName, int value) { - +variable* make_variable_int(char *p_name, int value) +{ variable *p = malloc(sizeof(variable)); variable_values *int_value = malloc(sizeof(variable_values)); int_value->type = VAR_INT; int_value->_int = value; - p->name = pName; + p->name = p_name; p->value = int_value; return p; - } @@ -63,16 +61,15 @@ variable* make_variable_int(char *pName, int value) { * @param name of the varible. * @param double data to be stored in the variable. */ -variable* make_variable_double(char *pName, double value) { - +variable* make_variable_double(char *p_name, double value) +{ variable *new_var = malloc(sizeof(variable)); variable_values *double_value = malloc(sizeof(variable_values)); double_value->type = VAR_DOUBLE; double_value->_double = value; - new_var->name = pName; + new_var->name = p_name; new_var->value = double_value; return new_var; - } /** @@ -81,16 +78,15 @@ variable* make_variable_double(char *pName, double value) { * @param name of the variable. * @param char value to be stored. */ -variable* make_variable_char(char *pName, char value) { - +variable* make_variable_char(char *p_name, char value) +{ variable *p = malloc(sizeof(variable)); variable_values *char_value = malloc(sizeof(variable_values)); char_value->type = VAR_CHAR; char_value->_char = value; - p->name = pName; + p->name = p_name; p->value = char_value; - return p; - + return p; } /** @@ -99,14 +95,13 @@ variable* make_variable_char(char *pName, char value) { * @param name of the variable. * @param value to be stored. */ -variable* make_variable_string(char *pName, char *value) { - +variable* make_variable_string(char *p_name, char *value) +{ variable *p = malloc(sizeof(variable)); variable_values *string_value = malloc(sizeof(variable_values)); string_value->type = VAR_STRING; string_value->_string = value; - p->name = pName; + p->name = p_name; p->value = string_value; return p; - } diff --git a/vars/vars.h b/vars/vars.h index 75bc7fc..0770d4f 100755 --- a/vars/vars.h +++ b/vars/vars.h @@ -1,6 +1,9 @@ +#ifndef VARS_H +#define VARS_H void add_var(char *name, variable_values *values, map_void_t* pVarMap); variable_values *get_value(char *pName, map_void_t* pVarMap); variable* make_variable_int(char *pName, int value); variable* make_variable_double(char *pName, double value); variable* make_variable_char(char *pName, char value); -variable* make_variable_string(char *pName, char *value); \ No newline at end of file +variable* make_variable_string(char *pName, char *value); +#endif \ No newline at end of file