entries are working but not freeing memory so potential for leaks
This commit is contained in:
28
grammar.y
28
grammar.y
@ -10,8 +10,8 @@
|
||||
extern char* yytext;
|
||||
extern int yychar;
|
||||
SymbolTable * st;
|
||||
char* cur_value;
|
||||
char* cur_type;
|
||||
//char* cur_value;
|
||||
//char* cur_type;
|
||||
int token_tracker;
|
||||
extern int line_number;
|
||||
extern int column_number;
|
||||
@ -120,8 +120,8 @@ idlist:
|
||||
;
|
||||
|
||||
sblock:
|
||||
L_BRACE {st = CreateScope(st,1,1);} statement_list {st = getParent(st);} R_BRACE
|
||||
| L_BRACE {st = CreateScope(st,1,1);} dblock statement_list {st = getParent(st);} R_BRACE
|
||||
L_BRACE {st = CreateScope(st,2,2);} statement_list {st = getParent(st);} R_BRACE
|
||||
| L_BRACE {st = CreateScope(st,2,2);} dblock statement_list {st = getParent(st);} R_BRACE
|
||||
;
|
||||
|
||||
dblock:
|
||||
@ -143,22 +143,24 @@ declaration_list:
|
||||
|
||||
declaration:
|
||||
ID COLON ID {
|
||||
printf("declaration rule encountered");
|
||||
|
||||
CreateEntry(st,strdup($1),strdup($3));
|
||||
// printf("declaration rule encountered");
|
||||
// if(cur_value != NULL){
|
||||
// char* delete1 = cur_value;
|
||||
printf("delete1 var assigned to cur_value");
|
||||
// printf("delete1 var assigned to cur_value");
|
||||
// free(delete1);
|
||||
printf("delete1 var freed");
|
||||
// printf("delete1 var freed");
|
||||
// }
|
||||
// if(cur_type != NULL){
|
||||
// char* delete2 = cur_type;
|
||||
// free(delete2);}
|
||||
// int len = strlen($1);
|
||||
printf("length determined");
|
||||
// printf("length determined");
|
||||
// cur_value = malloc(len + 1);
|
||||
printf("space allocated");
|
||||
// printf("space allocated");
|
||||
// strcpy(cur_value, $1);
|
||||
printf("string copied over");
|
||||
// printf("string copied over");
|
||||
|
||||
// len = strlen($3);
|
||||
// cur_type = malloc(len + 1);
|
||||
@ -255,9 +257,9 @@ void yyerror(const char *err) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *str = strdup("taco");
|
||||
cur_value = NULL;
|
||||
cur_type = NULL;
|
||||
//char *str = strdup("taco");
|
||||
//cur_value = NULL;
|
||||
//cur_type = NULL;
|
||||
|
||||
token_tracker = 1;
|
||||
st=CreateScope(NULL,1,1);
|
||||
|
Reference in New Issue
Block a user