added get number of entries function
This commit is contained in:
@ -157,8 +157,66 @@ declaration_list:
|
||||
;
|
||||
|
||||
declaration:
|
||||
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
||||
id_or_types COLON ID {
|
||||
TableNode* type = table_lookup(getAncestor(cur), $<words>1);
|
||||
AdInfo* info = NULL;
|
||||
|
||||
// Check for NULL type
|
||||
if (type == NULL) {
|
||||
printf("Error: Type '%s' not found\n", $<words>1);
|
||||
} else {
|
||||
// Create appropriate AdInfo based on the type
|
||||
if (type == integ) {
|
||||
// Integer type
|
||||
info = CreatePrimitiveInfo(4); // 4 bytes for integer
|
||||
}
|
||||
else if (type == addr) {
|
||||
// Address type
|
||||
info = CreatePrimitiveInfo(8); // 8 bytes for address
|
||||
}
|
||||
else if (type == chara) {
|
||||
// Character type
|
||||
info = CreatePrimitiveInfo(1); // 1 byte for character
|
||||
}
|
||||
else if (type == boo) {
|
||||
// Boolean type
|
||||
info = CreatePrimitiveInfo(1); // 1 byte for boolean
|
||||
}
|
||||
else if (type == stri) {
|
||||
// String type (array of characters)
|
||||
info = CreateArrayInfo(1, chara); // 1-dimensional array of characters
|
||||
}
|
||||
else if (type == arrayprim) {
|
||||
// Array type
|
||||
// Need to determine dimensions and element type from context
|
||||
// This is a placeholder - you'll need to adjust based on your grammar
|
||||
info = CreateArrayInfo(1, NULL); // Default to 1D array of unknown type
|
||||
}
|
||||
else if (type == recprime) {
|
||||
// Record type
|
||||
// Need to determine elements from context
|
||||
// This is a placeholder - you'll need to adjust based on your grammar
|
||||
info = CreateRecordInfo(0, NULL); // Default to empty record
|
||||
}
|
||||
else if (type == funprime) {
|
||||
// Function declaration
|
||||
info = CreateFunctionDeclarationInfo(0, false); // Start at line 0, regular function
|
||||
}
|
||||
else if (type == funtypeprime) {
|
||||
// Function type
|
||||
// Need parameter and return types from context
|
||||
// This is a placeholder - you'll need to adjust based on your grammar
|
||||
info = CreateFunctionTypeInfo(NULL, NULL); // Default to no parameter/return type
|
||||
}
|
||||
// Add additional type cases as needed
|
||||
}
|
||||
|
||||
// Create the entry with the appropriate AdInfo
|
||||
CreateEntry(cur, type, $<words>3, info);
|
||||
}
|
||||
;
|
||||
// id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
||||
// ;
|
||||
|
||||
id_or_types:
|
||||
ID {printf("string of id in id_or_type is %s\n",$<words>1);} {$$ = $<words>1;}
|
||||
@ -200,17 +258,35 @@ expression:
|
||||
| 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"); 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"); 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"); 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"); 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"); 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"); 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");}
|
||||
{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 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);
|
||||
| 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||
|
||||
|
@ -103,6 +103,14 @@ AdInfo *CreatePrimitiveInfo(int size) {
|
||||
|
||||
// only gets the size of a primitive type
|
||||
int getPrimSize(TableNode *definition) {
|
||||
if (definition == NULL){
|
||||
printf("passed an NULL entry to getPrimSize function. Invalid.\n");
|
||||
return -1;
|
||||
}
|
||||
if (definition->additionalinfo == NULL){
|
||||
printf("node has NULL additionalinfo. Invalid.\n");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(getType(definition), "primitive") != 0) {
|
||||
printf("not checking the size of a primitive -- invalid op\n");
|
||||
return 0;
|
||||
@ -133,6 +141,11 @@ AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
|
||||
}
|
||||
// This gets the number of dimensions from array info
|
||||
int getNumArrDim(TableNode *definition) {
|
||||
if (definition == NULL){
|
||||
printf("passed an NULL entry to getNumArrDim function. Invalid.\n");
|
||||
return -1;
|
||||
}
|
||||
if(
|
||||
if (strcmp(getType(definition), "array") != 0) {
|
||||
printf("not checking the dim of an array -- invalid op\n");
|
||||
return 0;
|
||||
@ -181,6 +194,16 @@ SymbolTable *getRecList(TableNode *definition) {
|
||||
return definition->additionalinfo->RecAdInfo->recordScope;
|
||||
}
|
||||
|
||||
int getRecSize(SymbolTable* tn){
|
||||
int s = 0;
|
||||
TableNode* cur = getFirstEntry(tn);
|
||||
while(getNextEntry(cur) != NULL){
|
||||
s++;
|
||||
cur = getNextEntry(cur);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// below function takes a bool to see if parameter should be decomposed or not
|
||||
// note that functions only take one input and have one output
|
||||
// using "as" the input record can be decomposed to give the illusion of
|
||||
@ -484,7 +507,7 @@ char *getName(TableNode *tn) {
|
||||
printf("passed a NULL table entry to getName\n");
|
||||
return "";
|
||||
}
|
||||
if(tn->theType == NULL){
|
||||
if(tn->theName == NULL){
|
||||
printf("name of entry is currently NULL, undefined \n");
|
||||
return "";
|
||||
}
|
||||
|
Reference in New Issue
Block a user