added print statements to gramamr rules to check for debugging
This commit is contained in:
65
grammar.y
65
grammar.y
@ -39,7 +39,7 @@
|
|||||||
%left ASSIGN
|
%left ASSIGN
|
||||||
|
|
||||||
%token <words> ID 101
|
%token <words> ID 101
|
||||||
%token T_INTEGER
|
%token T_INTEGER 201
|
||||||
%token T_ADDRESS 202
|
%token T_ADDRESS 202
|
||||||
%token T_BOOLEAN 203
|
%token T_BOOLEAN 203
|
||||||
%token T_CHARACTER 204
|
%token T_CHARACTER 204
|
||||||
@ -120,20 +120,51 @@ idlist:
|
|||||||
;
|
;
|
||||||
|
|
||||||
sblock:
|
sblock:
|
||||||
L_BRACE /*{st = CreateScope(st,1,1);}*/ statement_list /*{st = getParent(st);}*/ R_BRACE
|
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,1,1);} dblock statement_list {st = getParent(st);} R_BRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
dblock:
|
dblock:
|
||||||
L_BRACKET declaration_list R_BRACKET;
|
L_BRACKET declaration_list R_BRACKET;
|
||||||
|
|
||||||
declaration_list:
|
declaration_list:
|
||||||
declaration /*{CreateEntry(st,cur_type,cur_value);}*/ SEMI_COLON declaration_list
|
declaration
|
||||||
| declaration //{CreateEntry(st,cur_type,cur_value);}
|
{printf(
|
||||||
|
"declaration list a rule encountered");
|
||||||
|
//CreateEntry(st,cur_type,cur_value);
|
||||||
|
}
|
||||||
|
SEMI_COLON declaration_list
|
||||||
|
| declaration
|
||||||
|
{printf(
|
||||||
|
"declaration rule b encountered");
|
||||||
|
//CreateEntry(st,cur_type,cur_value);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
declaration:
|
declaration:
|
||||||
ID COLON ID //{cur_value = strdup($1);cur_type = strdup($3);}
|
ID COLON ID {
|
||||||
|
printf("declaration rule encountered");
|
||||||
|
// if(cur_value != NULL){
|
||||||
|
// char* delete1 = cur_value;
|
||||||
|
printf("delete1 var assigned to cur_value");
|
||||||
|
// free(delete1);
|
||||||
|
printf("delete1 var freed");
|
||||||
|
// }
|
||||||
|
// if(cur_type != NULL){
|
||||||
|
// char* delete2 = cur_type;
|
||||||
|
// free(delete2);}
|
||||||
|
// int len = strlen($1);
|
||||||
|
printf("length determined");
|
||||||
|
// cur_value = malloc(len + 1);
|
||||||
|
printf("space allocated");
|
||||||
|
// strcpy(cur_value, $1);
|
||||||
|
printf("string copied over");
|
||||||
|
|
||||||
|
// len = strlen($3);
|
||||||
|
// cur_type = malloc(len + 1);
|
||||||
|
// strcpy(cur_type, $3);
|
||||||
|
// printf("value var is %s type var is %s\n",cur_value,cur_type);
|
||||||
|
}
|
||||||
| types COLON ID
|
| types COLON ID
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -220,25 +251,27 @@ types:
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
void yyerror(const char *err) {
|
void yyerror(const char *err) {
|
||||||
fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number);
|
// fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//cur_value = NULL;
|
char *str = strdup("taco");
|
||||||
//cur_type = NULL;
|
cur_value = NULL;
|
||||||
|
cur_type = NULL;
|
||||||
|
|
||||||
token_tracker = 1;
|
token_tracker = 1;
|
||||||
st=CreateScope(NULL,1,1);
|
st=CreateScope(NULL,1,1);
|
||||||
int a;
|
//int a;
|
||||||
while ((a = yyparse()) != EOF){
|
yyparse();
|
||||||
token_tracker++;
|
//while ((a = yyparse() != EOF){
|
||||||
|
// token_tracker++;
|
||||||
//printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker);
|
//printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker);
|
||||||
if(yytext[0] == '\n'){
|
//if(yytext[0] == '\n'){
|
||||||
FILE* f = fdopen(1,"w");
|
FILE* f = fdopen(1,"w");
|
||||||
print_symbol_table(getAncestor(st),f);
|
print_symbol_table(getAncestor(st),f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
break;
|
// break;
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user