added more helper functions

This commit is contained in:
Partho Bhattacharya
2025-03-28 02:02:44 -04:00
parent d7f6272d37
commit 38a1d0b091
3 changed files with 43 additions and 24 deletions

View File

@ -145,7 +145,8 @@ idlist:
sblock:
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);}
dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE
;
dblock:
@ -157,10 +158,7 @@ declaration_list:
;
declaration:
id_or_types COLON ID {
TableNode* type = table_lookup(getAncestor(cur), $<words>1);
AdInfo* info = NULL;
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(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:
@ -202,46 +200,49 @@ expression:
$$=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);}}
| expression ADD expression {printf("add expression\n");}
{printf("less than expression\n");
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression ADD expression
{printf("add 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 SUB_OR_NEG expression {printf("subtract expression\n");}
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression SUB_OR_NEG 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 MUL expression {printf("multiply expression\n");}
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression MUL expression
{printf("multiply expression\n");
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 DIV expression {printf("division expression\n");}
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression DIV 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 REM expression {printf("remainder expression\n");}
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression REM 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 AND expression {printf("and expression\n");}
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
| expression AND 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 OR expression {printf("or expression\n");}
| expression OR expression
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
strcmp($1,"integer")==0){$$=strdup("Boolean");
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 LESS_THAN expression
{printf("less than expression\n");if(strcmp($1,$3)==0 &&
strcmp($1,"integer")==0){$$=strdup("Boolean");
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||
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;}