all compilation errors are gone. Function Types are properly entering Symbol Table. Some Type checking is taking place among expressions.

This commit is contained in:
Partho Bhattacharya
2025-03-14 22:42:08 -04:00
parent 78f1cd3fbb
commit 1544f2b728
2 changed files with 31 additions and 12 deletions

View File

@ -35,7 +35,7 @@
}
%type <words> assignable
%type <words> expression
%type <words> constant
%type <words> id_or_types
@ -122,7 +122,8 @@ definition:
TYPE ID COLON dblock
| TYPE ID COLON constant ARROW ID
| function_declaration
| TYPE ID COLON id_or_types ARROW id_or_types
| TYPE ID COLON id_or_types ARROW id_or_types {
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6)));}
| ID parameter ASSIGN sblock
;
@ -155,7 +156,7 @@ declaration_list:
;
declaration:
id_or_types COLON ID {CreateEntry(cur,$<words>1,$<words>3,NULL); }
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
;
id_or_types:
@ -193,21 +194,33 @@ rec_op :
expression:
constant {printf("constant expression\n");} {$$ = $<words>1;}
| SUB_OR_NEG expression {if(strcmp($2,"integer") != 0) {printf("cant negate something not an integer at line %d and column %d\n",@2.first_line,@2.first_column);}} %prec UMINUS {printf("negative expression\n");}
| SUB_OR_NEG expression %prec UMINUS {printf("negative expression\n");if(strcmp($2,"integer") != 0)
{printf("cant negate something not an integer at line %d and column %d\n",@2.first_line,@2.first_column);
$$=strdup("undefined");}else{$$=$2;}}
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
printf("mismatch at line %d and column %d\n",@1.first_line,@1.first_column);}}
| NOT expression {printf("not expression\n");}
| expression ADD expression {printf("add expression\n");}
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
| expression MUL expression {printf("multiply expression\n");}
| expression DIV expression {printf("division expression\n");}
| expression REM expression {printf("remainder expression\n");}
| expression AND expression {printf("and expression\n");}
| expression OR expression {printf("or expression\n");}
| expression LESS_THAN expression {printf("less than expression\n");}
| expression EQUAL_TO expression {printf("equals check expression\n");}
| assignable {printf("assignable expression\n");}
| L_PAREN expression R_PAREN {printf("paren expression\n");}
| memOp assignable
| expression LESS_THAN expression {printf("less than expression\n");if(strcmp($1,$3)==0 &&
strcmp($1,"integer")==0){$$=strdup("Boolean");}else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
$$=strdup("Boolean");$$=strdup("undefined");}}
| expression EQUAL_TO expression {printf("equals check expression\n");
if(strcmp($1,$3)==0){$$=strdup("Boolean");}else if((strcmp($1,"array")==0||strcmp($1,"record")==0||
strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");}
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);$$=strdup("undefined");}}
| assignable {printf("assignable expression\n");$$=$1;}
| L_PAREN expression R_PAREN {printf("paren expression\n");$$=$2;}
| memOp assignable {$$ = strdup("address");}
;