entries are working but not freeing memory so potential for leaks
This commit is contained in:
BIN
.Makefile.swp
BIN
.Makefile.swp
Binary file not shown.
28
grammar.y
28
grammar.y
@ -10,8 +10,8 @@
|
|||||||
extern char* yytext;
|
extern char* yytext;
|
||||||
extern int yychar;
|
extern int yychar;
|
||||||
SymbolTable * st;
|
SymbolTable * st;
|
||||||
char* cur_value;
|
//char* cur_value;
|
||||||
char* cur_type;
|
//char* cur_type;
|
||||||
int token_tracker;
|
int token_tracker;
|
||||||
extern int line_number;
|
extern int line_number;
|
||||||
extern int column_number;
|
extern int column_number;
|
||||||
@ -120,8 +120,8 @@ idlist:
|
|||||||
;
|
;
|
||||||
|
|
||||||
sblock:
|
sblock:
|
||||||
L_BRACE {st = CreateScope(st,1,1);} 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,1,1);} dblock statement_list {st = getParent(st);} R_BRACE
|
| L_BRACE {st = CreateScope(st,2,2);} dblock statement_list {st = getParent(st);} R_BRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
dblock:
|
dblock:
|
||||||
@ -143,22 +143,24 @@ declaration_list:
|
|||||||
|
|
||||||
declaration:
|
declaration:
|
||||||
ID COLON ID {
|
ID COLON ID {
|
||||||
printf("declaration rule encountered");
|
|
||||||
|
CreateEntry(st,strdup($1),strdup($3));
|
||||||
|
// printf("declaration rule encountered");
|
||||||
// if(cur_value != NULL){
|
// if(cur_value != NULL){
|
||||||
// char* delete1 = cur_value;
|
// char* delete1 = cur_value;
|
||||||
printf("delete1 var assigned to cur_value");
|
// printf("delete1 var assigned to cur_value");
|
||||||
// free(delete1);
|
// free(delete1);
|
||||||
printf("delete1 var freed");
|
// printf("delete1 var freed");
|
||||||
// }
|
// }
|
||||||
// if(cur_type != NULL){
|
// if(cur_type != NULL){
|
||||||
// char* delete2 = cur_type;
|
// char* delete2 = cur_type;
|
||||||
// free(delete2);}
|
// free(delete2);}
|
||||||
// int len = strlen($1);
|
// int len = strlen($1);
|
||||||
printf("length determined");
|
// printf("length determined");
|
||||||
// cur_value = malloc(len + 1);
|
// cur_value = malloc(len + 1);
|
||||||
printf("space allocated");
|
// printf("space allocated");
|
||||||
// strcpy(cur_value, $1);
|
// strcpy(cur_value, $1);
|
||||||
printf("string copied over");
|
// printf("string copied over");
|
||||||
|
|
||||||
// len = strlen($3);
|
// len = strlen($3);
|
||||||
// cur_type = malloc(len + 1);
|
// cur_type = malloc(len + 1);
|
||||||
@ -255,9 +257,9 @@ void yyerror(const char *err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char *str = strdup("taco");
|
//char *str = strdup("taco");
|
||||||
cur_value = NULL;
|
//cur_value = NULL;
|
||||||
cur_type = NULL;
|
//cur_type = NULL;
|
||||||
|
|
||||||
token_tracker = 1;
|
token_tracker = 1;
|
||||||
st=CreateScope(NULL,1,1);
|
st=CreateScope(NULL,1,1);
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
STARCOM [^\*]|\*+[^\)\*]+
|
STARCOM [^\*]|\*+[^\)\*]+
|
||||||
@ -79,7 +81,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}}
|
"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}}
|
||||||
"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}}
|
"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}}
|
||||||
|
|
||||||
{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}}
|
{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}}
|
||||||
|
|
||||||
\n {line_number++; column_number = 1;}
|
\n {line_number++; column_number = 1;}
|
||||||
\t {column_number++;}
|
\t {column_number++;}
|
||||||
|
Reference in New Issue
Block a user