have to finish idlist rules
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
void yyerror(const char *err);
|
||||
int token_tracker;
|
||||
TableNode * tn;
|
||||
int counter;
|
||||
%}
|
||||
|
||||
%union {
|
||||
@ -137,6 +138,8 @@ definition:
|
||||
//We are scanning through the dblock scope to get the length of the dblock (num of elements) from getRecSize
|
||||
//and then putting it in the entry that we created above.
|
||||
setRecSize(look_up(getParent(cur), $2), getRecSize(cur));
|
||||
//putting in all the offsets
|
||||
setRecOffsetInfo(cur, look_up(getParent(cur),$2));
|
||||
printdebug("Moving up a scope after seeing a record definition");
|
||||
cur = getParent(cur);
|
||||
}
|
||||
@ -236,6 +239,8 @@ definition:
|
||||
}
|
||||
}
|
||||
}
|
||||
counter = 0;
|
||||
printdebug("Created a new scope after seeing a function definition");
|
||||
} idlist {
|
||||
printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d", $1,$5);
|
||||
} R_PAREN ASSIGN sblock //check sblock type
|
||||
@ -273,7 +278,15 @@ function_declaration:
|
||||
idlist:
|
||||
ID
|
||||
{
|
||||
counter ++;
|
||||
TableNode *entry = getFirstEntry(cur);
|
||||
int count = 1;
|
||||
while(count<counter){
|
||||
entry = getNextEntry(entry);
|
||||
count++;
|
||||
}
|
||||
printdebug("RAAAAAAAAAAAAAAAAAAAAAAAAAAAAH");
|
||||
printTableNode(entry);
|
||||
while (strcmp(getName(entry),"undefined") != 0) {
|
||||
entry = getNextEntry(entry);
|
||||
}
|
||||
@ -281,6 +294,8 @@ idlist:
|
||||
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
|
||||
}
|
||||
addName(entry, $1);
|
||||
printdebug("name added to entry is %s", $1);
|
||||
printTableNode(entry);
|
||||
}
|
||||
COMMA idlist
|
||||
{
|
||||
@ -289,7 +304,13 @@ idlist:
|
||||
|
||||
| ID
|
||||
{
|
||||
counter ++;
|
||||
TableNode *entry = getFirstEntry(cur);
|
||||
int count = 1;
|
||||
while(count<counter){
|
||||
entry = getNextEntry(entry);
|
||||
count++;
|
||||
}
|
||||
while (strcmp(getName(entry),"undefined") != 0) {
|
||||
entry = getNextEntry(entry);
|
||||
}
|
||||
@ -701,8 +722,8 @@ expression:
|
||||
assignable:
|
||||
ID
|
||||
{
|
||||
$$ = look_up(cur,$1);
|
||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", getTypeEntry((TableNode*)$$), $1);
|
||||
$$ = getTypeEntry(look_up(cur,$1));
|
||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", getName((TableNode*)$$), $1);
|
||||
}
|
||||
|
||||
| assignable
|
||||
|
@ -176,25 +176,25 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
int total_size = 0;
|
||||
int counter = 0;
|
||||
int *offsets = (int *)calloc(2 * k, sizeof(int));
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_TYPE){
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
|
||||
offsets[counter] = 8;
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = 8;
|
||||
counter++;
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_RECORD_TYPE){
|
||||
offsets[counter] = getRecTotal(this);
|
||||
else if((getAdInfoType(this) == TYPE_RECORD) && (node != getTypeEntry(this))){
|
||||
offsets[counter] = getRecTotal(getTypeEntry(this));
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
counter++;
|
||||
}
|
||||
else if(getAdInfoType(this)==TYPE_PRIMITIVE){
|
||||
offsets[counter] = getPrimSize(this);
|
||||
offsets[counter] = getPrimSize(getTypeEntry(this));
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
counter++;
|
||||
}
|
||||
else if(getAdInfoType(this)==TYPE_ARRAY_TYPE){
|
||||
else if(getAdInfoType(this)==TYPE_ARRAY){
|
||||
offsets[counter] = 8;
|
||||
total_size = total_size + offsets[counter];
|
||||
largest = offsets[counter];
|
||||
@ -202,12 +202,12 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
}
|
||||
else {
|
||||
printdebug(
|
||||
"[TYPE CHECK] passed an invalid (first) parameter to a function definition.");
|
||||
"[TYPE CHECK] passed an invalid (first) parameter to a function definition. seeing %d",getAdInfoType(this));
|
||||
return undefined;
|
||||
}
|
||||
this = getNextEntry(this);
|
||||
while(this != NULL){
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_TYPE){
|
||||
if(getAdInfoType(this) == TYPE_FUNCTION_DECLARATION){
|
||||
int s = 8;
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -222,7 +222,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_ARRAY_TYPE){
|
||||
else if(getAdInfoType(this) == TYPE_ARRAY){
|
||||
int s = 8;
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
@ -237,12 +237,14 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
counter++;
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_RECORD_TYPE){
|
||||
int s = getRecTotal(this);
|
||||
else if((getAdInfoType(this) == TYPE_RECORD) && (node != getTypeEntry(this))){
|
||||
int s = getRecTotal(getTypeEntry(this));
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
}
|
||||
//make sure current location is aligned properly
|
||||
printTableNode(this);
|
||||
printTableNode(node);
|
||||
offsets[counter] = (total_size % s);
|
||||
total_size = total_size + offsets[counter];
|
||||
counter++;
|
||||
@ -253,7 +255,7 @@ TableNode *setRecOffsetInfo(SymbolTable* scope, TableNode *node) {
|
||||
this = getNextEntry(this);
|
||||
}
|
||||
else if(getAdInfoType(this) == TYPE_PRIMITIVE){
|
||||
int s = getPrimSize(this);
|
||||
int s = getPrimSize(getTypeEntry(this));
|
||||
if (s > largest) {
|
||||
largest = s;
|
||||
}
|
||||
@ -1049,8 +1051,12 @@ TableNode *look_up(SymbolTable *table, char *x) {
|
||||
}
|
||||
|
||||
int col_widths[5] = {30, 8, 8, 35, 35};
|
||||
void printline(FILE *file_ptr);
|
||||
void printline(FILE *file_ptr) {
|
||||
void printline(FILE *file_ptr, bool b);
|
||||
void printline(FILE *file_ptr, bool b) {
|
||||
if (b) {
|
||||
fprintf(file_ptr, "oop\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
for (int ii = 0; ii < col_widths[i]; ii++) {
|
||||
fprintf(file_ptr, "-");
|
||||
@ -1095,7 +1101,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
|
||||
TableNode *entry = table->entries;
|
||||
printline(file_ptr);
|
||||
printline(file_ptr, false);
|
||||
int parentScopeNum = 0;
|
||||
int currentScopeNum = 0;
|
||||
|
||||
@ -1213,7 +1219,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||
}
|
||||
|
||||
if (getParent(table) == NULL) {
|
||||
printline(file_ptr);
|
||||
printline(file_ptr, true);
|
||||
}
|
||||
}
|
||||
// get top most symbol table
|
||||
|
@ -111,6 +111,7 @@ char *getType(TableNode *tn);
|
||||
char *getName(TableNode *tn);
|
||||
int getLine(SymbolTable *st);
|
||||
int getColumn(SymbolTable *st);
|
||||
TableNode *getTypeEntry(TableNode *tn);
|
||||
TableNode *addName(TableNode *tn, char *str);
|
||||
SymbolTable *setLineNumber(SymbolTable *st, int line);
|
||||
SymbolTable *setColumnNumber(SymbolTable *st, int column);
|
||||
|
2
tests/sprint3/test/sp3_record_size_check.alpha
Normal file
2
tests/sprint3/test/sp3_record_size_check.alpha
Normal file
@ -0,0 +1,2 @@
|
||||
type tom : [integer : x; integer: y]
|
||||
type rec : [integer : x; tom : prev; character : c; character : d; Boolean: b; integer : y]
|
Reference in New Issue
Block a user