verifying grammar

This commit is contained in:
Scarlett
2025-04-01 17:02:24 -04:00
parent fac92f62f7
commit 5bd68ddb85
5 changed files with 52 additions and 43 deletions

View File

@ -267,16 +267,30 @@ simple_statement:
| RETURN expression
;
assignable:
ID {$$ = getType(look_up(cur,$1));}
| assignable ablock {$$ = getName(getReturn(look_up(cur, $1)));} //add array case here
| assignable rec_op ID {if(undefined != table_lookup(getRecList(look_up(cur, $1)), $3)){
{$$ = getName(table_lookup(getRecList(look_up(cur, $1)), $3));}};}
;
rec_op :
DOT
/////////// VERIFIED UP UNTIL THIS POINT
// assignable needs more code- specifically for arrays, records and ablock checks
ablock:
L_PAREN argument_list {$<integ>$ = $<integ>2;} R_PAREN
;
argument_list:
expression COMMA argument_list {$<integ>$ = $<integ>3 + 1; printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$);}
| expression {$<integ>$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$);}
;
// will ALWAYS be a TYPE
expression:
constant {printdebug("constant expression");} {$$ = $<words>1;}
@ -341,8 +355,8 @@ expression:
| expression EQUAL_TO expression {printdebug("equals check expression");
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 if((strcmp($1,"array")==0||strcmp($1,"record")==0||
// strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");}
else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s",
@2.first_line,@2.first_column,$1,$3);$$=strdup("undefined");}}
@ -353,17 +367,16 @@ expression:
| memOp assignable {$$ = strdup("address");}
;
ablock:
L_PAREN argument_list {$<integ>$ = $<integ>2;} R_PAREN
// prolly right, check back with me later
// add array case
// include type check for ablock in arrays - ablock is always the int of the elements in array/rec
assignable:
ID {$$ = getType(look_up(cur,$1)); printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);}
| assignable ablock {$$ = getName(getReturn(table_lookup(getAncestor(cur), $1))); printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);} // add array case
| assignable rec_op ID {if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)){
{$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));}}; printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);}
;
argument_list:
expression COMMA argument_list {$<integ>$ = $<integ>3 + 1;}
| expression {$<integ>$ = 1;}
;
memOp:
RESERVE {printdebug("reserve expression");}
| RELEASE {printdebug("release expression");}
@ -371,12 +384,12 @@ memOp:
constant:
C_STRING {$$ = $<words>1;}
| C_INTEGER {$$ = "integer";}
| C_NULL {$$ = $<words>1;}
| C_CHARACTER {$$ = $<words>1;}
| C_TRUE {$$ = $<words>1;}
| C_FALSE {$$ = $<words>1;}
C_STRING {$$ = $<words>1; printdebug("string of C_STRING in constant is %s",$<words>1);}
| C_INTEGER {$$ = "integer"; printdebug("string of C_INTEGER in constant is integer");}
| C_NULL {$$ = $<words>1; printdebug("string of C_NULL in constant is %s",$<words>1);}
| C_CHARACTER {$$ = $<words>1; printdebug("string of C_CHARACTER in constant is %s",$<words>1);}
| C_TRUE {$$ = $<words>1; printdebug("string of C_TRUE in constant is %s",$<words>1);}
| C_FALSE {$$ = $<words>1; printdebug("string of C_FALSE in constant is %s",$<words>1);}
;
types: