diff --git a/src/grammar.y b/src/grammar.y index c9136c4..6c3cf9f 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -35,7 +35,7 @@ } - +%type assignable %type expression %type constant %type 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,$1,$3,NULL); } + id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$1),$3,NULL); } ; id_or_types: @@ -193,21 +194,33 @@ rec_op : expression: constant {printf("constant expression\n");} {$$ = $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");} ; diff --git a/src/symbol_table.c b/src/symbol_table.c index 6f26b89..31abdf1 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -316,19 +316,25 @@ SymbolTable* init(SymbolTable* start){ return start; } -TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, AdInfo* ad) { +TableNode* CreateEntry(SymbolTable* table, TableNode* typeOf, char* id, AdInfo* ad) { if(table ==NULL){ printf("Null reference to table"); return NULL; } +/* TableNode* topDef = (table_lookup(getAncestor(table),typeOf)); if(topDef == NULL){ printf("This type is not defined at the top level\n"); return NULL; +} +*/ +if(typeOf == NULL){ + printf("This is not pointing to a proper definition\n"); + return NULL; } TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode)); - newEntry->theType = topDef; + newEntry->theType = typeOf/*topDef*/; newEntry->theName = id; newEntry->additionalinfo = ad; if (table->entries == NULL) {