updated to change strings to nodes in most locations
This commit is contained in:
151
src/grammar.y
151
src/grammar.y
@ -43,21 +43,23 @@
|
|||||||
TableNode * tn;
|
TableNode * tn;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%locations
|
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
int integ;
|
int integ;
|
||||||
char* words;
|
char* words;
|
||||||
TableNode* tn;
|
void* tn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%locations
|
||||||
|
|
||||||
%type <integ> idlist
|
%type <integ> idlist
|
||||||
%type <tn> assignable
|
%type <tn> assignable
|
||||||
%type <tn> expression
|
%type <tn> expression
|
||||||
%type <tn> constant
|
%type <tn> constant
|
||||||
%type <tn> id_or_types
|
%type <tn> id_or_types
|
||||||
%type <tn> types
|
%type <tn> types
|
||||||
%token <tn> ID 101
|
%type <integ> argument_list
|
||||||
|
%type <integ> ablock
|
||||||
|
%token <words> ID 101
|
||||||
%token <tn> T_INTEGER 201
|
%token <tn> T_INTEGER 201
|
||||||
%token <tn> T_ADDRESS 202
|
%token <tn> T_ADDRESS 202
|
||||||
%token <tn> T_BOOLEAN 203
|
%token <tn> T_BOOLEAN 203
|
||||||
@ -143,13 +145,15 @@ definition:
|
|||||||
TYPE ID COLON
|
TYPE ID COLON
|
||||||
{
|
{
|
||||||
printdebug("Currently see a record definition for %s", $2);
|
printdebug("Currently see a record definition for %s", $2);
|
||||||
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
tn = CreateEntry(getAncestor(cur),TYPE_RECORD_TYPE, recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
||||||
if (look_up(cur, $2) == undefined) {
|
if (look_up(cur, $2) == undefined) {
|
||||||
printdebug("rec not found ");
|
printdebug("rec not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dblock
|
dblock
|
||||||
{
|
{
|
||||||
|
//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(cur, $2), getRecSize(cur));
|
setRecSize(look_up(cur, $2), getRecSize(cur));
|
||||||
cur = getParent(cur);
|
cur = getParent(cur);
|
||||||
}
|
}
|
||||||
@ -157,7 +161,7 @@ definition:
|
|||||||
| TYPE ID COLON C_INTEGER ARROW id_or_types
|
| TYPE ID COLON C_INTEGER ARROW id_or_types
|
||||||
{
|
{
|
||||||
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName($6), $4);
|
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName($6), $4);
|
||||||
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, $6));
|
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, $6));
|
||||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6));
|
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +169,8 @@ definition:
|
|||||||
|
|
||||||
| TYPE ID COLON id_or_types ARROW id_or_types
|
| TYPE ID COLON id_or_types ARROW id_or_types
|
||||||
{
|
{
|
||||||
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", getName($2), getName($4), getName($6));
|
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", $2, getName($4), getName($6));
|
||||||
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6));
|
CreateEntry(cur,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6));
|
||||||
}
|
}
|
||||||
|
|
||||||
| ID
|
| ID
|
||||||
@ -185,11 +189,25 @@ definition:
|
|||||||
L_PAREN ID
|
L_PAREN ID
|
||||||
{
|
{
|
||||||
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s", $1,$4);
|
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s", $1,$4);
|
||||||
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $4, NULL);
|
TableNode* type_of_param = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1))));
|
||||||
}
|
int type_of_param_type = getAdInfoType(type_of_param);
|
||||||
R_PAREN ASSIGN sblock
|
if( type_of_param_type == TYPE_UNDEFINED
|
||||||
|
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|
||||||
|
|| type_of_param_type == TYPE_ARRAY
|
||||||
|
|| type_of_param_type == TYPE_ALL_ELSE
|
||||||
|
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|
||||||
|
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||||
|
printdebug("type of parameter is undefined or invalid at line %d, column %d", @4.first_line, @4.first_column);
|
||||||
|
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
|
||||||
|
}else{
|
||||||
|
printdebug("type of parameter is %s at line %d, column %d", getName(type_of_param), @4.first_line, @4.first_column);
|
||||||
|
}
|
||||||
|
|
||||||
| ID
|
CreateEntry(cur,type_of_param_type, type_of_param, $4, getAdInfo(type_of_param));
|
||||||
|
}
|
||||||
|
R_PAREN ASSIGN sblock //leaving scope is being taken care of in sblock
|
||||||
|
|
||||||
|
/* | ID
|
||||||
{
|
{
|
||||||
TableNode *node = table_lookup(getAncestor(cur), $1);
|
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||||
if (node == undefined) {
|
if (node == undefined) {
|
||||||
@ -208,13 +226,13 @@ definition:
|
|||||||
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s",
|
printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s",
|
||||||
$1,$4);
|
$1,$4);
|
||||||
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
|
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
|
||||||
}R_PAREN ASSIGN sblock
|
}R_PAREN ASSIGN sblock */
|
||||||
| ID {
|
| ID {
|
||||||
TableNode *node = table_lookup(getAncestor(cur), $1);
|
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||||
if (node == undefined) {
|
if (node == undefined) {
|
||||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
printdebug(" undefined nodedeclared at line %d, column %d", @1.first_line, @1.first_column);
|
||||||
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
|
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
|
||||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
printdebug("not a valid function declaration at line %d, column %d", @1.first_line, @1.first_column);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printdebug("setting as keyword to true");
|
printdebug("setting as keyword to true");
|
||||||
@ -232,9 +250,26 @@ definition:
|
|||||||
printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column);
|
printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column);
|
||||||
}else {
|
}else {
|
||||||
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
|
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
|
||||||
printdebug("creating entry of type %s for function", getType(entry));
|
int type_of_param_type = getAdInfoType(entry);
|
||||||
CreateEntry(cur, entry, "undefined", NULL);
|
if( type_of_param_type == TYPE_UNDEFINED
|
||||||
|
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|
||||||
|
|| type_of_param_type == TYPE_ARRAY
|
||||||
|
|| type_of_param_type == TYPE_ALL_ELSE
|
||||||
|
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|
||||||
|
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||||
|
printdebug("type of parameter being passed in to AS function definition is %s which is invalid", getName(entry));
|
||||||
|
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
|
||||||
|
}else{
|
||||||
|
printdebug("type of parameter correctly being passed in to AS function definition is %s which is valid", getName(entry));
|
||||||
|
}
|
||||||
|
if(type_of_param_type == TYPE_UNDEFINED){
|
||||||
|
CreateEntry(cur,type_of_param_type, undefined, NULL, NULL);
|
||||||
|
} else {
|
||||||
|
CreateEntry(cur,type_of_param_type, entry, NULL, getAdInfo(entry));
|
||||||
|
/*printdebug("creating entry of type %s for function", getType(entry));
|
||||||
|
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} idlist {printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d",
|
} idlist {printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d",
|
||||||
$1,$6);} R_PAREN ASSIGN sblock //check sblock type
|
$1,$6);} R_PAREN ASSIGN sblock //check sblock type
|
||||||
@ -244,12 +279,12 @@ definition:
|
|||||||
function_declaration:
|
function_declaration:
|
||||||
FUNCTION ID COLON ID
|
FUNCTION ID COLON ID
|
||||||
{
|
{
|
||||||
CreateEntry(cur, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $4), $2, CreateFunctionDeclarationInfo(-1, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
| EXTERNAL FUNCTION ID COLON ID
|
| EXTERNAL FUNCTION ID COLON ID
|
||||||
{
|
{
|
||||||
CreateEntry(cur, look_up(cur, $5), $3, NULL);
|
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, NULL);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -265,7 +300,7 @@ idlist:
|
|||||||
if (getNextEntry(entry) == NULL) {
|
if (getNextEntry(entry) == NULL) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
COMMA idlist
|
COMMA idlist
|
||||||
{
|
{
|
||||||
@ -290,8 +325,11 @@ idlist:
|
|||||||
sblock:
|
sblock:
|
||||||
L_BRACE
|
L_BRACE
|
||||||
{
|
{
|
||||||
if (getLine(cur) != 0 && getColumn(cur)) {
|
if (getLine(cur) != 0) {
|
||||||
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
||||||
|
} else {
|
||||||
|
setLineNumber(cur, @1.first_line);
|
||||||
|
setColumnNumber(cur,@1.first_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statement_list
|
statement_list
|
||||||
@ -302,8 +340,11 @@ sblock:
|
|||||||
|
|
||||||
| L_BRACE
|
| L_BRACE
|
||||||
{
|
{
|
||||||
if (getLine(cur) != 0 && getColumn(cur)) {
|
if (getLine(cur) != 0) {
|
||||||
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
||||||
|
} else {
|
||||||
|
setLineNumber(cur, @1.first_line);
|
||||||
|
setColumnNumber(cur,@1.first_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dblock
|
dblock
|
||||||
@ -320,7 +361,15 @@ sblock:
|
|||||||
|
|
||||||
|
|
||||||
dblock:
|
dblock:
|
||||||
L_BRACKET declaration_list R_BRACKET;
|
L_BRACKET
|
||||||
|
{if(getLine(cur)==0){
|
||||||
|
setLineNumber(cur, @1.first_line);
|
||||||
|
setColumnNumber(cur,@1.first_line);}
|
||||||
|
else{
|
||||||
|
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declaration_list R_BRACKET;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -335,7 +384,7 @@ declaration:
|
|||||||
id_or_types COLON ID
|
id_or_types COLON ID
|
||||||
{
|
{
|
||||||
printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ;
|
printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ;
|
||||||
CreateEntry(cur,$1,$3,NULL);
|
CreateEntry(cur,getAdInfoType($1),$1,$3,getAdInfo($1));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -377,14 +426,14 @@ compound_statement:
|
|||||||
simple_statement:
|
simple_statement:
|
||||||
assignable ASSIGN expression
|
assignable ASSIGN expression
|
||||||
{
|
{
|
||||||
if(strcmp(getType($1), getType($3)) == 0) {
|
if(strcmp(getName($1), getName($3)) == 0) {
|
||||||
printdebug("Passed standard type check; assignable = expression");
|
printdebug("Passed standard type check; assignable = expression");
|
||||||
} else if((strcmp(getType($1), "array") == 0) && (strcmp($3, "address") == 0)) {
|
} else if((strcmp(getName($1), "array") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||||
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
|
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||||
} else if((strcmp(getType($1), "record") == 0) && (strcmp($3, "address") == 0)) {
|
} else if((strcmp(getName($1), "record") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||||
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
|
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||||
} else if((strcmp(getType($1), "function type primitive") == 0) && (strcmp(getType($3), "address") == 0)) {
|
} else if((strcmp(getName($1), "function type primitive") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||||
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getType($1), getType($3));
|
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||||
// } else if () {
|
// } else if () {
|
||||||
|
|
||||||
// } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) {
|
// } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) {
|
||||||
@ -419,14 +468,14 @@ ablock:
|
|||||||
argument_list:
|
argument_list:
|
||||||
expression COMMA argument_list
|
expression COMMA argument_list
|
||||||
{
|
{
|
||||||
CreateEntry(cur, $1, getName($1), NULL);
|
CreateEntry(cur,getAdInfoType($1), $1, getName($1), NULL);
|
||||||
$$ = $3 + 1;
|
$$ = $3 + 1;
|
||||||
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||||
}
|
}
|
||||||
|
|
||||||
| expression
|
| expression
|
||||||
{
|
{
|
||||||
CreateEntry(cur, $1, getName($1), NULL);
|
CreateEntry(cur,getAdInfoType($1),$1, getName($1), NULL);
|
||||||
$$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
$$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -498,7 +547,7 @@ expression:
|
|||||||
| expression DIV expression
|
| expression DIV expression
|
||||||
{
|
{
|
||||||
printdebug("divide expression");
|
printdebug("divide expression");
|
||||||
if(strcmp($1 == $3 && $1 == integ) {
|
if((strcmp(getName($1),getName($3))==0) && ($1 == integ)) {
|
||||||
$$=$1;
|
$$=$1;
|
||||||
} else {
|
} else {
|
||||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||||
@ -520,7 +569,7 @@ expression:
|
|||||||
| expression AND expression
|
| expression AND expression
|
||||||
{
|
{
|
||||||
printdebug("AND expression");
|
printdebug("AND expression");
|
||||||
if($1 == $3 && $1 == boo {
|
if($1 == $3 && $1 == boo){
|
||||||
$$=$1;
|
$$=$1;
|
||||||
} else{
|
} else{
|
||||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||||
@ -531,7 +580,7 @@ expression:
|
|||||||
| expression OR expression
|
| expression OR expression
|
||||||
{
|
{
|
||||||
printdebug("OR");
|
printdebug("OR");
|
||||||
if(strcmp($1 == $3 && $1 == boo) {
|
if((strcmp(getName($1),getName($3))==0) && $1 == boo) {
|
||||||
$$=$1;
|
$$=$1;
|
||||||
} else {
|
} else {
|
||||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||||
@ -599,17 +648,17 @@ assignable:
|
|||||||
}
|
}
|
||||||
ablock
|
ablock
|
||||||
{
|
{
|
||||||
int type = getAdInfoType(look_up(getParent(cur), $1));
|
int type = getAdInfoType(look_up(cur, getName($1)));
|
||||||
printdebug("%stype is %d", COLOR_PURPLE, type);
|
printdebug("%stype is %d", COLOR_PURPLE, type);
|
||||||
printdebug("%s", $1);
|
printdebug("%s", $1);
|
||||||
|
|
||||||
if (type == TYPE_FUNCTION_DECLARATION) {
|
if (type == TYPE_FUNCTION_DECLARATION) {
|
||||||
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
|
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
|
||||||
if (look_up(getParent(cur), $1)->additionalinfo->FunDecAdInfo->regularoras) {
|
if (look_up(getParent(cur), getName($1))->additionalinfo->FunDecAdInfo->regularoras) {
|
||||||
printdebug("as function");
|
printdebug("as function");
|
||||||
//char *funtype = getType(look_up(cur, $1));
|
//char *funtype = getType(look_up(cur, $1));
|
||||||
printdebug("%s", getType(look_up(cur, $1)));
|
printdebug("%s", getType(look_up(cur, getName($1))));
|
||||||
TableNode *param = getParameter(look_up(cur, getType(look_up(cur, $1))));
|
TableNode *param = getParameter(look_up(cur, getType(look_up(cur, getName($1)))));
|
||||||
SymbolTable *recList = getRecList(param);
|
SymbolTable *recList = getRecList(param);
|
||||||
TableNode *lastCheckedRef = getFirstEntry(recList);
|
TableNode *lastCheckedRef = getFirstEntry(recList);
|
||||||
TableNode *lastCheckedAct = getFirstEntry(cur);
|
TableNode *lastCheckedAct = getFirstEntry(cur);
|
||||||
@ -636,32 +685,32 @@ assignable:
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
char *expected = getName(getParameter(look_up(getParent(cur), $1)));
|
char *expected = getName(getParameter(look_up(getParent(cur), getName($1))));
|
||||||
char *actual = getType(getFirstEntry(cur));
|
char *actual = getType(getFirstEntry(cur));
|
||||||
if (strcmp(expected, actual) != 0) {
|
if (strcmp(expected, actual) != 0) {
|
||||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
|
printdebug("expected %s expression in function call but got %s at line %d and column %d",expected, actual, @3.first_line, @3.first_column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$$ = getName(getReturn((look_up(cur, getType(look_up(cur, $1))))));
|
$$ = getReturn((look_up(cur, getType(look_up(cur, getName($1))))));
|
||||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
|
||||||
|
|
||||||
} else if (type == TYPE_ARRAY_TYPE) {
|
} else if (type == TYPE_ARRAY_TYPE) {
|
||||||
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
|
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
|
||||||
if (getNumArrDim(look_up(getParent(cur), $1)) != $<integ>2) {
|
if (getNumArrDim(look_up(getParent(cur), getName($1))) != $<integ>2) {
|
||||||
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, $1)), $<integ>2, @2.first_line, @2.first_column);
|
printdebug("expected %d arguments but had %d at line %d and column %d\n", getNumArrDim(look_up(cur, getName($1))), $<integ>2, @2.first_line, @2.first_column);
|
||||||
}
|
}
|
||||||
$$ = getName(getArrType(look_up(getParent(cur), $1)));
|
$$ = getArrType(look_up(getParent(cur), getName($1)));
|
||||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
|
||||||
}
|
}
|
||||||
cur = getParent(cur);
|
cur = getParent(cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
| assignable rec_op ID
|
| assignable rec_op ID
|
||||||
{
|
{
|
||||||
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)) {
|
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), getName($1))), $3)) {
|
||||||
$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));
|
$$ = table_lookup(getRecList(table_lookup(getAncestor(cur), getName($1))), $3);
|
||||||
}
|
}
|
||||||
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", $$, $1);
|
printdebug("[ASSIGNABLE - RULE 3] assignable = type: %s | ID = %s", getName($$), $1);
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -85,7 +85,8 @@ typedef enum {
|
|||||||
TYPE_ALL_ELSE = 7,
|
TYPE_ALL_ELSE = 7,
|
||||||
TYPE_UNDEFINED = 8,
|
TYPE_UNDEFINED = 8,
|
||||||
TYPE_RECORD = 9,
|
TYPE_RECORD = 9,
|
||||||
TYPE_ARRAY = 10
|
TYPE_ARRAY = 10,
|
||||||
|
TYPE_SYSTEM_DEFINED = 11 // for system defined entries like funprimetype etc.
|
||||||
|
|
||||||
} types;
|
} types;
|
||||||
|
|
||||||
@ -314,7 +315,7 @@ int getRecSize(SymbolTable *tn) {
|
|||||||
"passed in NULL SymbolTable for getRecSize. Invalid");
|
"passed in NULL SymbolTable for getRecSize. Invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int s = 0;
|
int s = 1;
|
||||||
TableNode *cur = getFirstEntry(tn);
|
TableNode *cur = getFirstEntry(tn);
|
||||||
if (cur != NULL) {
|
if (cur != NULL) {
|
||||||
while (getNextEntry(cur) != NULL) {
|
while (getNextEntry(cur) != NULL) {
|
||||||
@ -551,6 +552,7 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
prime->theType = NULL;
|
prime->theType = NULL;
|
||||||
prime->additionalinfo = NULL;
|
prime->additionalinfo = NULL;
|
||||||
prime->next = NULL;
|
prime->next = NULL;
|
||||||
|
prime->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
// not sure exatly how to get array types to look right so using a dummy
|
// not sure exatly how to get array types to look right so using a dummy
|
||||||
// Table Node below and updating the print symbol table function to
|
// Table Node below and updating the print symbol table function to
|
||||||
@ -560,7 +562,8 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
arrayprim->theName = "array";
|
arrayprim->theName = "array";
|
||||||
arrayprim->theType = NULL;
|
arrayprim->theType = NULL;
|
||||||
arrayprim->additionalinfo = NULL;
|
arrayprim->additionalinfo = NULL;
|
||||||
prime->next = NULL;
|
arrayprim->next = NULL;
|
||||||
|
prime->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
// funprime = CreateEntry(NULL,NULL,strdup("function primitive"),NULL);
|
// funprime = CreateEntry(NULL,NULL,strdup("function primitive"),NULL);
|
||||||
|
|
||||||
@ -570,6 +573,7 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
funprime->theType = NULL;
|
funprime->theType = NULL;
|
||||||
funprime->additionalinfo = NULL;
|
funprime->additionalinfo = NULL;
|
||||||
funprime->next = NULL;
|
funprime->next = NULL;
|
||||||
|
funprime->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
// record
|
// record
|
||||||
recprime = (TableNode *)malloc(sizeof(TableNode));
|
recprime = (TableNode *)malloc(sizeof(TableNode));
|
||||||
@ -577,18 +581,21 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
recprime->theType = NULL;
|
recprime->theType = NULL;
|
||||||
recprime->additionalinfo = NULL;
|
recprime->additionalinfo = NULL;
|
||||||
recprime->next = NULL;
|
recprime->next = NULL;
|
||||||
|
recprime->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
funtypeprime = (TableNode *)malloc(sizeof(TableNode));
|
funtypeprime = (TableNode *)malloc(sizeof(TableNode));
|
||||||
funtypeprime->theName = "primitive function type";
|
funtypeprime->theName = "primitive function type";
|
||||||
funtypeprime->theType = NULL;
|
funtypeprime->theType = NULL;
|
||||||
funtypeprime->additionalinfo = NULL;
|
funtypeprime->additionalinfo = NULL;
|
||||||
funtypeprime->next = NULL;
|
funtypeprime->next = NULL;
|
||||||
|
funtypeprime->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
undefined = (TableNode *)malloc(sizeof(TableNode));
|
undefined = (TableNode *)malloc(sizeof(TableNode));
|
||||||
undefined->theName = "undefined";
|
undefined->theName = "undefined";
|
||||||
undefined->theType = NULL;
|
undefined->theType = NULL;
|
||||||
undefined->additionalinfo = NULL;
|
undefined->additionalinfo = NULL;
|
||||||
undefined->next = NULL;
|
undefined->next = NULL;
|
||||||
|
undefined->tag = TYPE_SYSTEM_DEFINED;
|
||||||
|
|
||||||
// Undefined_function_type_info = CreateFunctionTypeInfo(undefined,
|
// Undefined_function_type_info = CreateFunctionTypeInfo(undefined,
|
||||||
// undefined);
|
// undefined);
|
||||||
@ -605,11 +612,17 @@ SymbolTable *init(SymbolTable *start) {
|
|||||||
// be the size of these primitive types. We can change these if needed
|
// be the size of these primitive types. We can change these if needed
|
||||||
// to not be hard coded numbers as a reminder, stri below is defined as
|
// to not be hard coded numbers as a reminder, stri below is defined as
|
||||||
// a one dimensional array of characters
|
// a one dimensional array of characters
|
||||||
integ->additionalinfo = CreatePrimitiveInfo(4);
|
integ->additionalinfo = CreatePrimitiveInfo(SIZE_INT);
|
||||||
addr->additionalinfo = CreatePrimitiveInfo(8);
|
addr->additionalinfo = CreatePrimitiveInfo(SIZE_ADDR);
|
||||||
chara->additionalinfo = CreatePrimitiveInfo(1);
|
chara->additionalinfo = CreatePrimitiveInfo(SIZE_CHAR);
|
||||||
stri->additionalinfo = CreateArrayInfo(1, chara);
|
stri->additionalinfo = CreateArrayInfo(1, chara);
|
||||||
boo->additionalinfo = CreatePrimitiveInfo(1);
|
boo->additionalinfo = CreatePrimitiveInfo(SIZE_BOOL);
|
||||||
|
|
||||||
|
integ->tag = TYPE_PRIMITIVE; // explicitly set the type for integ
|
||||||
|
addr->tag = TYPE_PRIMITIVE; // explicitly set the type for addr
|
||||||
|
chara->tag = TYPE_PRIMITIVE; // explicitly set the type for chara
|
||||||
|
stri->tag = TYPE_ARRAY_TYPE; // explicitly set the type for stri
|
||||||
|
boo->tag = TYPE_PRIMITIVE; // explicitly set the type for boo
|
||||||
// addr->additionalinfo = CreatePrimitiveInfo(8);
|
// addr->additionalinfo = CreatePrimitiveInfo(8);
|
||||||
|
|
||||||
start->Line_Number = 1;
|
start->Line_Number = 1;
|
||||||
@ -661,12 +674,33 @@ TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
|
|||||||
return tn;
|
return tn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AdInfo *getAdInfo(TableNode *tn) {
|
||||||
|
if (tn == NULL) {
|
||||||
|
printdebug("passed a NULL table entry to getAdInfo. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (tn == undefined) {
|
||||||
|
printdebug(
|
||||||
|
"passed an undefined table entry to getAdInfo. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (tn->additionalinfo == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"no additional info found in the table node. Invalid.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return tn->additionalinfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
//simplified getAdInfoType
|
||||||
int getAdInfoType(TableNode *tn) {
|
int getAdInfoType(TableNode *tn) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug(
|
printdebug(
|
||||||
"passing in NULL table entry to getAdInfoType. Invalid");
|
"passing in NULL table entry to getAdInfoType. Invalid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return tn->tag;
|
||||||
|
/*
|
||||||
if (tn == undefined) {
|
if (tn == undefined) {
|
||||||
printdebug("passing in undefined table entry to getAdInfoType. "
|
printdebug("passing in undefined table entry to getAdInfoType. "
|
||||||
"Invalid");
|
"Invalid");
|
||||||
@ -725,11 +759,10 @@ int getAdInfoType(TableNode *tn) {
|
|||||||
"passed in an entry that is not a primitive type, array, "
|
"passed in an entry that is not a primitive type, array, "
|
||||||
"or record. Invalid.");
|
"or record. Invalid.");
|
||||||
return TYPE_FUNCTION_DECLARATION;
|
return TYPE_FUNCTION_DECLARATION;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
TableNode *CreateEntry(SymbolTable *table, int tag, TableNode *typeOf, char *id, AdInfo *ad) {
|
||||||
AdInfo *ad) {
|
|
||||||
|
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
printdebug("Null reference to table");
|
printdebug("Null reference to table");
|
||||||
@ -752,7 +785,14 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
|
||||||
|
if(tag<1 && tag>11){
|
||||||
|
printdebug("Note- not passing in valid 'tag' identifier to create entry function. Setting tag to undefined");
|
||||||
|
newEntry->tag = TYPE_UNDEFINED;
|
||||||
|
} else{
|
||||||
|
newEntry->tag = tag;
|
||||||
|
}
|
||||||
newEntry->theType = typeOf /*topDef*/;
|
newEntry->theType = typeOf /*topDef*/;
|
||||||
newEntry->theName = id;
|
newEntry->theName = id;
|
||||||
newEntry->additionalinfo = ad;
|
newEntry->additionalinfo = ad;
|
||||||
@ -769,6 +809,8 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TableNode *getTypeEntry(TableNode *tn) {
|
TableNode *getTypeEntry(TableNode *tn) {
|
||||||
if (tn == NULL) {
|
if (tn == NULL) {
|
||||||
printdebug("passed a NULL table entry to getType");
|
printdebug("passed a NULL table entry to getType");
|
||||||
@ -853,9 +895,9 @@ TableNode *addName(TableNode *tn, char *str) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if (tn->theName != NULL) {
|
if (tn->theName != NULL) {
|
||||||
printdebug(
|
//printdebug(
|
||||||
"Name doesn't look like it is empty before you change. "
|
//"Name doesn't look like it is empty before you change. "
|
||||||
"Are you sure you need to update name?");
|
//"Are you sure you need to update name?");
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
tn->theName = str;
|
tn->theName = str;
|
||||||
return tn;
|
return tn;
|
||||||
@ -1011,178 +1053,177 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
|
||||||
|
if (table == NULL) {
|
||||||
|
printdebug(
|
||||||
|
"%s[FATAL] passed in NULL table to print_symbol_table",
|
||||||
|
COLOR_RED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (table == NULL) {
|
if (table->Parent_Scope == NULL) {
|
||||||
printdebug(
|
fprintf(file_ptr, "%-25s: %-6s : %-6s : %-25s: %-30s\n", "NAME",
|
||||||
"%s[FATAL] passed in NULL table to print_symbol_table",
|
"SCOPE", "PARENT", "TYPE", "Extra annotation");
|
||||||
COLOR_RED);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (table->Parent_Scope == NULL) {
|
TableNode *entrie = table->entries;
|
||||||
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
|
fprintf(file_ptr,
|
||||||
"SCOPE", "PARENT", "TYPE", "Extra annotation");
|
"-------------------------:--------:--------:------------------"
|
||||||
}
|
"--------:------------------------------\n");
|
||||||
|
int parant_scope = 0;
|
||||||
|
int current_scope = 0;
|
||||||
|
if (table->Parent_Scope != NULL) {
|
||||||
|
parant_scope = getParent(table)->Line_Number * 1000 +
|
||||||
|
getParent(table)->Column_Number;
|
||||||
|
current_scope =
|
||||||
|
table->Line_Number * 1000 + table->Column_Number;
|
||||||
|
} else {
|
||||||
|
current_scope = 1001;
|
||||||
|
}
|
||||||
|
if (entrie == NULL) {
|
||||||
|
fprintf(file_ptr, "%-25s: %06d : %06d : %-25s: %-30s\n", "",
|
||||||
|
current_scope, parant_scope, "", "Empty Scope");
|
||||||
|
}
|
||||||
|
for (; entrie != NULL; entrie = getNextEntry(entrie)) {
|
||||||
|
if (getAdInfoType(entrie) == TYPE_ARRAY_TYPE) {
|
||||||
|
if (parant_scope == 0) {
|
||||||
|
|
||||||
TableNode *entrie = table->entries;
|
fprintf(file_ptr,
|
||||||
fprintf(file_ptr, "-----------------:--------:--------:----------------"
|
"%-25s: %06d : : %d -> %-20s: "
|
||||||
"------:---------"
|
"%-30s\n",
|
||||||
"--------------------\n");
|
|
||||||
int parant_scope = 0;
|
|
||||||
int current_scope = 0;
|
|
||||||
if (table->Parent_Scope != NULL) {
|
|
||||||
parant_scope = getParent(table)->Line_Number * 1000 +
|
|
||||||
getParent(table)->Column_Number;
|
|
||||||
current_scope =
|
|
||||||
table->Line_Number * 1000 + table->Column_Number;
|
|
||||||
} else {
|
|
||||||
current_scope = 1001;
|
|
||||||
}
|
|
||||||
if (entrie == NULL) {
|
|
||||||
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "",
|
|
||||||
current_scope, parant_scope, "", "Empty Scope");
|
|
||||||
}
|
|
||||||
for (; entrie != NULL; entrie = getNextEntry(entrie)) {
|
|
||||||
if (getAdInfoType(entrie) == TYPE_ARRAY_TYPE) {
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : : %-21d -> "
|
|
||||||
"%-21s: %-28s\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo
|
|
||||||
->numofdimensions,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo
|
|
||||||
->typeofarray->theName,
|
|
||||||
"Type of Array");
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : %06d : %-21d -> %-21s: "
|
|
||||||
"%-28s\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
parant_scope,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo
|
|
||||||
->numofdimensions,
|
|
||||||
entrie->additionalinfo->ArrayAdInfo
|
|
||||||
->typeofarray->theName,
|
|
||||||
"Type of Array");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_RECORD) {
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : :%-21s: "
|
|
||||||
"elements-%-28d\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
"record",
|
|
||||||
entrie->additionalinfo->RecAdInfo
|
|
||||||
->numofelements);
|
|
||||||
} else {
|
|
||||||
fprintf(file_ptr,
|
|
||||||
"%-17s: %06d : %06d : %-21s: "
|
|
||||||
"elements-%-28d\n",
|
|
||||||
entrie->theName, current_scope,
|
|
||||||
parant_scope, "record",
|
|
||||||
entrie->additionalinfo->RecAdInfo
|
|
||||||
->numofelements);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_PRIMITIVE) {
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(
|
|
||||||
file_ptr,
|
|
||||||
"%-17s: %06d : :%-21s: size-%-28d "
|
|
||||||
"bytes\n",
|
|
||||||
entrie->theName, current_scope, "Primitive",
|
|
||||||
entrie->additionalinfo->PrimAdInfo->size);
|
|
||||||
} else {
|
|
||||||
fprintf(
|
|
||||||
file_ptr,
|
|
||||||
"%-17s: %06d : %06d : %-21s: size-%-28d "
|
|
||||||
"bytes\n",
|
|
||||||
entrie->theName, current_scope,
|
entrie->theName, current_scope,
|
||||||
parant_scope, "Primitive",
|
entrie->additionalinfo->ArrayAdInfo
|
||||||
entrie->additionalinfo->PrimAdInfo->size);
|
->numofdimensions,
|
||||||
}
|
entrie->additionalinfo->ArrayAdInfo
|
||||||
}
|
->typeofarray->theName,
|
||||||
if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE) {
|
"Type of Array");
|
||||||
if (parant_scope == 0) {
|
} else {
|
||||||
|
fprintf(file_ptr,
|
||||||
|
"%-25s: %06d : : %d -> %-20s: "
|
||||||
|
"%-30s\n",
|
||||||
|
entrie->theName, current_scope,
|
||||||
|
parant_scope,
|
||||||
|
entrie->additionalinfo->ArrayAdInfo
|
||||||
|
->numofdimensions,
|
||||||
|
entrie->additionalinfo->ArrayAdInfo
|
||||||
|
->typeofarray->theName,
|
||||||
|
"Type of Array");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getAdInfoType(entrie) == TYPE_RECORD) {
|
||||||
|
if (parant_scope == 0) {
|
||||||
|
|
||||||
fprintf(file_ptr,
|
fprintf(file_ptr,
|
||||||
"%-17s: %06d : : %-21s -> "
|
"%-25s: %06d : : %-25s: "
|
||||||
"%-21s: %-28s\n",
|
"elements-%-30d\n",
|
||||||
entrie->theName, current_scope,
|
entrie->theName, current_scope,
|
||||||
entrie->additionalinfo->FunTypeAdInfo
|
"record",
|
||||||
->parameter->theName,
|
entrie->additionalinfo->RecAdInfo
|
||||||
entrie->additionalinfo->FunTypeAdInfo
|
->numofelements);
|
||||||
->returntype->theName,
|
} else {
|
||||||
"Type of Function");
|
fprintf(file_ptr,
|
||||||
} else {
|
"%-25s: %06d : %06d : %-25s: "
|
||||||
fprintf(file_ptr,
|
"elements-%-30d\n",
|
||||||
"%-17s: %06d : %06d : %-21s -> %-21s: "
|
entrie->theName, current_scope,
|
||||||
"%-28s\n",
|
parant_scope, "record",
|
||||||
entrie->theName, current_scope,
|
entrie->additionalinfo->RecAdInfo
|
||||||
parant_scope,
|
->numofelements);
|
||||||
entrie->additionalinfo->FunTypeAdInfo
|
}
|
||||||
->parameter->theName,
|
}
|
||||||
entrie->additionalinfo->FunTypeAdInfo
|
if (getAdInfoType(entrie) == TYPE_PRIMITIVE) {
|
||||||
->returntype->theName,
|
if (parant_scope == 0) {
|
||||||
"Type of Function");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION) {
|
|
||||||
if (parant_scope == 0) {
|
|
||||||
|
|
||||||
fprintf(file_ptr,
|
fprintf(
|
||||||
"%-17s: %06d : :%-21s: %-28s\n",
|
file_ptr,
|
||||||
entrie->theName, current_scope,
|
"%-25s: %06d : : %-25s: size-%d "
|
||||||
getType(entrie), "User Defined");
|
"bytes\n",
|
||||||
} else {
|
entrie->theName, current_scope, "Primitive",
|
||||||
fprintf(file_ptr,
|
entrie->additionalinfo->PrimAdInfo->size);
|
||||||
"%-17s: %06d : %06d : %-21s: %-28s\n",
|
} else {
|
||||||
entrie->theName, current_scope,
|
fprintf(
|
||||||
parant_scope, getType(entrie),
|
file_ptr,
|
||||||
"User Defined");
|
"%-25s: %06d : %06d : %-25s: size-%-30d "
|
||||||
}
|
"bytes\n",
|
||||||
}
|
entrie->theName, current_scope,
|
||||||
if (getAdInfoType(entrie) == TYPE_UNDEFINED) {
|
parant_scope, "Primitive",
|
||||||
if (parant_scope == 0) {
|
entrie->additionalinfo->PrimAdInfo->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE) {
|
||||||
|
if (parant_scope == 0) {
|
||||||
|
|
||||||
fprintf(file_ptr,
|
fprintf(file_ptr,
|
||||||
"%-17s: %06d : :%-21s: %-28s\n",
|
"%-25s: %06d : : %-25s -> "
|
||||||
entrie->theName, current_scope,
|
"%-25s: %-30s\n",
|
||||||
"undefined", "undefined entry");
|
entrie->theName, current_scope,
|
||||||
} else {
|
entrie->additionalinfo->FunTypeAdInfo
|
||||||
fprintf(file_ptr,
|
->parameter->theName,
|
||||||
"%-17s: %06d : %06d : %-21s: %-28s\n",
|
entrie->additionalinfo->FunTypeAdInfo
|
||||||
entrie->theName, current_scope,
|
->returntype->theName,
|
||||||
parant_scope, "undefined",
|
"Type of Function");
|
||||||
"undefined entry");
|
} else {
|
||||||
}
|
fprintf(file_ptr,
|
||||||
}
|
"%-25s: %06d : %06d : %-25s -> %-21s: "
|
||||||
}
|
"%-30s\n",
|
||||||
if (getChildren(table) != NULL) {
|
entrie->theName, current_scope,
|
||||||
ListOfTable *node = getChildren(table);
|
parant_scope,
|
||||||
for (; node != NULL; node = node->next) {
|
entrie->additionalinfo->FunTypeAdInfo
|
||||||
if ((node->table) == NULL) {
|
->parameter->theName,
|
||||||
print_symbol_table(node->table, file_ptr);
|
entrie->additionalinfo->FunTypeAdInfo
|
||||||
} else {
|
->returntype->theName,
|
||||||
if ((node->table)->Line_Number == -1) {
|
"Type of Function");
|
||||||
continue;
|
}
|
||||||
} else {
|
}
|
||||||
print_symbol_table(node->table,
|
if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION) {
|
||||||
file_ptr);
|
if (parant_scope == 0) {
|
||||||
}
|
|
||||||
}
|
fprintf(file_ptr,
|
||||||
}
|
"%-25s: %06d : : %-25s: %-30s\n",
|
||||||
}
|
entrie->theName, current_scope,
|
||||||
if (getParent(table) == NULL) {
|
getType(entrie), "User Defined");
|
||||||
fprintf(file_ptr, "-----------------:--------:--------:--------"
|
} else {
|
||||||
"--------------:-------"
|
fprintf(file_ptr,
|
||||||
"----------------------\n");
|
"%-25s: %06d : %06d : %-25s: %-30s\n",
|
||||||
}
|
entrie->theName, current_scope,
|
||||||
|
parant_scope, getType(entrie),
|
||||||
|
"User Defined");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getAdInfoType(entrie) == TYPE_UNDEFINED) {
|
||||||
|
if (parant_scope == 0) {
|
||||||
|
|
||||||
|
fprintf(file_ptr,
|
||||||
|
"%-25s: %06d : : %-25s: %-30s\n",
|
||||||
|
entrie->theName, current_scope,
|
||||||
|
"undefined", "undefined entry");
|
||||||
|
} else {
|
||||||
|
fprintf(file_ptr,
|
||||||
|
"%-25s: %06d : %06d : %-25s: %-30s\n",
|
||||||
|
entrie->theName, current_scope,
|
||||||
|
parant_scope, "undefined",
|
||||||
|
"undefined entry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getChildren(table) != NULL) {
|
||||||
|
ListOfTable *node = getChildren(table);
|
||||||
|
for (; node != NULL; node = node->next) {
|
||||||
|
if ((node->table) == NULL) {
|
||||||
|
print_symbol_table(node->table, file_ptr);
|
||||||
|
} else {
|
||||||
|
if ((node->table)->Line_Number == -1) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
print_symbol_table(node->table,
|
||||||
|
file_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getParent(table) == NULL) {
|
||||||
|
fprintf(file_ptr,
|
||||||
|
"-------------------------:--------:--------:----------"
|
||||||
|
"----------------:------------------------------\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// get top most symbol table
|
// get top most symbol table
|
||||||
SymbolTable *getAncestor(SymbolTable *table) {
|
SymbolTable *getAncestor(SymbolTable *table) {
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define SIZE_INT 4
|
||||||
|
#define SIZE_ADDR 8
|
||||||
|
#define SIZE_CHAR 1
|
||||||
|
#define SIZE_BOOL 4 //TODO: Ask Carl what this size should be
|
||||||
|
|
||||||
|
|
||||||
struct TableNode;
|
struct TableNode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -58,9 +64,11 @@ typedef struct ListOfTable {
|
|||||||
struct ListOfTable *next;
|
struct ListOfTable *next;
|
||||||
} ListOfTable;
|
} ListOfTable;
|
||||||
|
|
||||||
|
//Table node to store
|
||||||
typedef struct TableNode {
|
typedef struct TableNode {
|
||||||
// reference to the type entry that this is
|
// reference to the type entry that this is
|
||||||
struct TableNode *theType;
|
struct TableNode *theType;
|
||||||
|
int tag;
|
||||||
char *theName;
|
char *theName;
|
||||||
AdInfo *additionalinfo;
|
AdInfo *additionalinfo;
|
||||||
struct TableNode *next;
|
struct TableNode *next;
|
||||||
|
Reference in New Issue
Block a user