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