updated symbol table entry add order
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/* Syntax Analyzer with Bison (3.8.2) */
|
/* Syntax Analyzer with Bison (3.8.2) */
|
||||||
/* The Translators - Spring 2025 */
|
/* The Translators - Spring 2025 */
|
||||||
|
|
||||||
@ -203,15 +204,22 @@ definition:
|
|||||||
}
|
}
|
||||||
if(type_of_param_type == TYPE_UNDEFINED){
|
if(type_of_param_type == TYPE_UNDEFINED){
|
||||||
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
|
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
|
||||||
|
// throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
} else {
|
} else {
|
||||||
if(type_of_param_type == TYPE_FUNCTION_TYPE){
|
if(type_of_param_type == TYPE_FUNCTION_TYPE){
|
||||||
CreateEntry(cur, TYPE_FUNCTION_DECLARATION, parameter,NULL, getAdInfo(parameter));
|
CreateEntry(cur, TYPE_FUNCTION_DECLARATION, parameter,NULL, getAdInfo(parameter));
|
||||||
|
// throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(type_of_param_type == TYPE_ARRAY_TYPE){
|
if(type_of_param_type == TYPE_ARRAY_TYPE){
|
||||||
CreateEntry(cur, TYPE_ARRAY, parameter,NULL, getAdInfo(parameter));
|
CreateEntry(cur, TYPE_ARRAY, parameter,NULL, getAdInfo(parameter));
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(type_of_param_type == TYPE_PRIMITIVE_TYPE){
|
if(type_of_param_type == TYPE_PRIMITIVE_TYPE){
|
||||||
CreateEntry(cur, TYPE_PRIMITIVE, parameter,NULL, getAdInfo(parameter));
|
CreateEntry(cur, TYPE_PRIMITIVE, parameter,NULL, getAdInfo(parameter))==undefined;
|
||||||
|
// throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -234,18 +242,29 @@ definition:
|
|||||||
if(type_of_param_type == TYPE_UNDEFINED){
|
if(type_of_param_type == TYPE_UNDEFINED){
|
||||||
printdebug("undefined type of parameter inside record");
|
printdebug("undefined type of parameter inside record");
|
||||||
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
|
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(type_of_param_type == TYPE_FUNCTION_DECLARATION){
|
if(type_of_param_type == TYPE_FUNCTION_DECLARATION){
|
||||||
printdebug("function declaration of parameter inside record");
|
printdebug("function declaration of parameter inside record");
|
||||||
CreateEntry(cur, TYPE_FUNCTION_DECLARATION, getTypeEntry(entry),NULL, getAdInfo(entry));
|
CreateEntry(cur, TYPE_FUNCTION_DECLARATION, getTypeEntry(entry),NULL, getAdInfo(entry));
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(type_of_param_type == TYPE_ARRAY){
|
if(type_of_param_type == TYPE_ARRAY){
|
||||||
printdebug("array type of parameter inside record");
|
printdebug("array type of parameter inside record");
|
||||||
CreateEntry(cur, TYPE_ARRAY, getTypeEntry(entry),NULL, getAdInfo(entry));
|
CreateEntry(cur, TYPE_ARRAY, getTypeEntry(entry),NULL, getAdInfo(entry));
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");
|
||||||
}
|
}
|
||||||
if(type_of_param_type == TYPE_PRIMITIVE){
|
if(type_of_param_type == TYPE_PRIMITIVE){
|
||||||
printdebug("primitive type of parameter inside record");
|
printdebug("primitive type of parameter inside record");
|
||||||
CreateEntry(cur, TYPE_PRIMITIVE, getTypeEntry(entry),NULL, getAdInfo(entry));
|
CreateEntry(cur, TYPE_PRIMITIVE, getTypeEntry(entry),NULL, getAdInfo(entry));
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");}
|
||||||
|
}
|
||||||
|
if(type_of_param_type == TYPE_RECORD){
|
||||||
|
printdebug("record type of parameter inside record");
|
||||||
|
CreateEntry(cur, TYPE_RECORD, getTypeEntry(entry),NULL, getAdInfo(entry));
|
||||||
|
//throw_error(ERROR_TYPE, "Duplicate defination of parameter in function definition.");}
|
||||||
}
|
}
|
||||||
/*printdebug("creating entry of type %s for function", getType(entry));
|
/*printdebug("creating entry of type %s for function", getType(entry));
|
||||||
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
|
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
|
||||||
@ -455,22 +474,30 @@ declaration:
|
|||||||
else if(d == TYPE_FUNCTION_TYPE) {
|
else if(d == TYPE_FUNCTION_TYPE) {
|
||||||
printdebug("invalid (function) type passed in declaration list in dblock", @2.first_line, @2.first_column);
|
printdebug("invalid (function) type passed in declaration list in dblock", @2.first_line, @2.first_column);
|
||||||
d = TYPE_FUNCTION_DECLARATION;
|
d = TYPE_FUNCTION_DECLARATION;
|
||||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
if(CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)) == undefined){
|
||||||
|
throw_error(ERROR_TYPE, "Duplicate defination of function in declaration list");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(d == TYPE_ARRAY_TYPE){
|
else if(d == TYPE_ARRAY_TYPE){
|
||||||
printdebug("array variable at line %d and column %d", @2.first_line, @2.first_column);
|
printdebug("array variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||||
d = TYPE_ARRAY;
|
d = TYPE_ARRAY;
|
||||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
if(CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)) == undefined){
|
||||||
|
throw_error(ERROR_TYPE, "Duplicate defination of array in declaration list");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(d == TYPE_RECORD_TYPE){
|
else if(d == TYPE_RECORD_TYPE){
|
||||||
printdebug("record variable at line %d and column %d", @2.first_line, @2.first_column);
|
printdebug("record variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||||
d = TYPE_RECORD;
|
d = TYPE_RECORD;
|
||||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
if(CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1))== undefined){
|
||||||
|
throw_error(ERROR_TYPE, "Duplicate defination of record in declaration list");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(d == TYPE_PRIMITIVE_TYPE){
|
else if(d == TYPE_PRIMITIVE_TYPE){
|
||||||
printdebug("primitive variable at line %d and column %d", @2.first_line, @2.first_column);
|
printdebug("primitive variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||||
d = TYPE_PRIMITIVE;
|
d = TYPE_PRIMITIVE;
|
||||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
if(CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1)) == undefined){
|
||||||
|
throw_error(ERROR_TYPE, "Duplicate defination of primitive in declaration list");
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
throw_error(ERROR_TYPE, "%s is being defined with an undefined type", $3);
|
throw_error(ERROR_TYPE, "%s is being defined with an undefined type", $3);
|
||||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||||
|
@ -956,6 +956,11 @@ TableNode *CreateEntry(SymbolTable *table, int tag, TableNode *typeOf, char *id,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
if((id != NULL) && table_lookup(cur,id)!=undefined){
|
||||||
|
printdebug("This name is already defined in the current scope");
|
||||||
|
//throw_error(ERROR_TYPE, "Already defined.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
if (typeOf == NULL) {
|
if (typeOf == NULL) {
|
||||||
printdebug("Passing an NULL Type Node to Create Entry");
|
printdebug("Passing an NULL Type Node to Create Entry");
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -982,9 +987,14 @@ TableNode *CreateEntry(SymbolTable *table, int tag, TableNode *typeOf, char *id,
|
|||||||
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
||||||
return newEntry;
|
return newEntry;
|
||||||
} else {
|
} else {
|
||||||
TableNode *oldEntry = table->entries;
|
TableNode*oldEntry = table->entries;
|
||||||
table->entries = newEntry;
|
while (oldEntry->next != NULL) {
|
||||||
newEntry->next = oldEntry;
|
oldEntry = oldEntry->next;
|
||||||
|
}
|
||||||
|
oldEntry->next = newEntry;
|
||||||
|
newEntry->next = NULL;
|
||||||
|
//table->entries = newEntry;
|
||||||
|
//newEntry->next = oldEntry;
|
||||||
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
printdebug("[CreateEntry] Adding %s to the symbol table", id);
|
||||||
return newEntry;
|
return newEntry;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ function c: string2int_2_integer
|
|||||||
function d: iic2b
|
function d: iic2b
|
||||||
|
|
||||||
d(x,y,z) := {
|
d(x,y,z) := {
|
||||||
|
[string: s;integer: s]
|
||||||
return (x < y & z < 'm');
|
return (x < y & z < 'm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user