Merge branch 'Sprint3-Symbol_Table_Restructure-FE-t#NoTask' into Dev
This commit is contained in:
383
src/grammar.y
383
src/grammar.y
@ -24,31 +24,34 @@
|
||||
TableNode * tn;
|
||||
%}
|
||||
|
||||
%locations
|
||||
|
||||
%union {
|
||||
int integ;
|
||||
char * words;
|
||||
char* words;
|
||||
void* tn;
|
||||
}
|
||||
|
||||
%locations
|
||||
|
||||
%type <integ> idlist
|
||||
%type <words> assignable
|
||||
%type <words> expression
|
||||
%type <words> constant
|
||||
%type <words> id_or_types
|
||||
%type <words> types
|
||||
%type <tn> assignable
|
||||
%type <tn> expression
|
||||
%type <tn> constant
|
||||
%type <tn> id_or_types
|
||||
%type <tn> types
|
||||
%type <integ> argument_list
|
||||
%type <integ> ablock
|
||||
%token <words> ID 101
|
||||
%token <words> T_INTEGER 201
|
||||
%token <words> T_ADDRESS 202
|
||||
%token <words> T_BOOLEAN 203
|
||||
%token <words> T_CHARACTER 204
|
||||
%token <words> T_STRING 205
|
||||
%token <tn> T_INTEGER 201
|
||||
%token <tn> T_ADDRESS 202
|
||||
%token <tn> T_BOOLEAN 203
|
||||
%token <tn> T_CHARACTER 204
|
||||
%token <tn> T_STRING 205
|
||||
%token <integ> C_INTEGER 301
|
||||
%token <words> C_NULL 302
|
||||
%token <words> C_CHARACTER 303
|
||||
%token <words> C_STRING 304
|
||||
%token <words> C_TRUE 305
|
||||
%token <words> C_FALSE 306
|
||||
%token <tn> C_NULL 302
|
||||
%token <tn> C_CHARACTER 303
|
||||
%token <tn> C_STRING 304
|
||||
%token <tn> C_TRUE 305
|
||||
%token <tn> C_FALSE 306
|
||||
%token WHILE 401
|
||||
%token IF 402
|
||||
%token THEN 403
|
||||
@ -122,36 +125,39 @@ prototype:
|
||||
definition:
|
||||
TYPE ID COLON
|
||||
{
|
||||
printdebug("Currently see a record definition for %s", $<words>2);
|
||||
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
||||
if (table_lookup(getAncestor(cur), $2) == undefined) {
|
||||
|
||||
printdebug("Currently see a record definition for %s", $2);
|
||||
tn = CreateEntry(getAncestor(cur),TYPE_RECORD_TYPE, recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
|
||||
if (look_up(cur, $2) == undefined) {
|
||||
printdebug("rec not found");
|
||||
}
|
||||
}
|
||||
dblock
|
||||
{
|
||||
setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur));
|
||||
//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));
|
||||
cur = getParent(cur);
|
||||
}
|
||||
|
||||
| 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, $6, $4);
|
||||
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));
|
||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, $6);
|
||||
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName($6), $4);
|
||||
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, $6));
|
||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName($6));
|
||||
}
|
||||
|
||||
| function_declaration
|
||||
|
||||
| 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", $2, $4, $6);
|
||||
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$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,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo($4 ,$6));
|
||||
}
|
||||
|
||||
| ID
|
||||
{
|
||||
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
|
||||
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||
if (node == undefined) {
|
||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
||||
} else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
|
||||
@ -165,59 +171,84 @@ definition:
|
||||
L_PAREN ID
|
||||
{
|
||||
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)))), $<words>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);
|
||||
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);
|
||||
}
|
||||
|
||||
CreateEntry(cur,type_of_param_type, type_of_param, $4, getAdInfo(type_of_param));
|
||||
}
|
||||
R_PAREN ASSIGN sblock
|
||||
|
||||
| ID
|
||||
{
|
||||
TableNode *node = table_lookup(getAncestor(cur), $<words>1);
|
||||
R_PAREN ASSIGN sblock //leaving scope is being taken care of in sblock
|
||||
|
||||
| ID {
|
||||
TableNode *node = table_lookup(getAncestor(cur), $1);
|
||||
if (node == undefined) {
|
||||
printdebug("null check");
|
||||
}
|
||||
if (node == undefined) {
|
||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
||||
} else if (getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) {
|
||||
printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
|
||||
} else {
|
||||
|
||||
printdebug(" undefined nodedeclared at line %d, column %d", @1.first_line, @1.first_column);
|
||||
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
|
||||
printdebug("not a valid function declaration at line %d, column %d", @1.first_line, @1.first_column);
|
||||
}
|
||||
else {
|
||||
printdebug("setting as keyword to true");
|
||||
setStartLine(node, @1.first_line);
|
||||
setAsKeyword(node, true);
|
||||
}
|
||||
cur = CreateScope(cur, 0, 0);
|
||||
}
|
||||
AS L_PAREN
|
||||
{
|
||||
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1))));
|
||||
printdebug("%s", getType(parameter));
|
||||
}AS L_PAREN {
|
||||
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $1))));
|
||||
printdebug("parameter type: %s", getType(parameter));
|
||||
if (parameter == undefined) {
|
||||
printdebug("function defined with as, but parameter is undefined at line %d, column %d", @1.first_line, @1.first_column);
|
||||
} else if(getAdInfoType(parameter) != TYPE_RECORD) {
|
||||
}else if(getAdInfoType(parameter) != TYPE_RECORD){
|
||||
printdebug("record: %s., primitive: %s.", getType(parameter), getName(recprime));
|
||||
printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column);
|
||||
} else {
|
||||
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)) {
|
||||
CreateEntry(cur, entry->theType, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
;
|
||||
|
||||
}else {
|
||||
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
|
||||
int type_of_param_type = getAdInfoType(entry);
|
||||
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",
|
||||
$1,$6);} R_PAREN ASSIGN sblock //check sblock type
|
||||
;
|
||||
|
||||
|
||||
function_declaration:
|
||||
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
|
||||
{
|
||||
CreateEntry(cur, look_up(cur, $5), $3, NULL);
|
||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, NULL);
|
||||
}
|
||||
;
|
||||
|
||||
@ -233,11 +264,11 @@ idlist:
|
||||
if (getNextEntry(entry) == NULL) {
|
||||
printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
|
||||
}
|
||||
addName(entry, $<words>1);
|
||||
addName(entry, $1);
|
||||
}
|
||||
COMMA idlist
|
||||
{
|
||||
$$ = $<integ>4 + 1;
|
||||
$$ = $4 + 1;
|
||||
}
|
||||
|
||||
| ID
|
||||
@ -273,8 +304,11 @@ sblock:
|
||||
|
||||
| L_BRACE
|
||||
{
|
||||
if (getLine(cur) != 0 && getColumn(cur)) {
|
||||
if (getLine(cur) != 0) {
|
||||
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
||||
} else {
|
||||
setLineNumber(cur, @1.first_line);
|
||||
setColumnNumber(cur,@1.first_line);
|
||||
}
|
||||
}
|
||||
dblock
|
||||
@ -291,15 +325,16 @@ sblock:
|
||||
|
||||
|
||||
dblock:
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@ -314,8 +349,8 @@ declaration_list:
|
||||
declaration:
|
||||
id_or_types COLON ID
|
||||
{
|
||||
printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ;
|
||||
CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL);
|
||||
printdebug("ID/TYPE: %s, ID: %s", getName($1), $3) ;
|
||||
CreateEntry(cur,getAdInfoType($1),$1,$3,getAdInfo($1));
|
||||
}
|
||||
;
|
||||
|
||||
@ -324,12 +359,13 @@ declaration:
|
||||
id_or_types:
|
||||
ID
|
||||
{
|
||||
printdebug("string of id is %s in ID pattern of id_or_type rule.", $1); $$ = $1;
|
||||
printdebug("string of id is %s in ID pattern of id_or_type rule.", $1);
|
||||
$$ = table_lookup(getAncestor(cur), $1);
|
||||
}
|
||||
|
||||
| types
|
||||
{
|
||||
printdebug("string of type is %s in types pattern of id_or_type rule.",$1);
|
||||
printdebug("string of type is %s in types pattern of id_or_type rule.",getName($1));
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
@ -348,7 +384,7 @@ statement_list:
|
||||
compound_statement:
|
||||
WHILE L_PAREN expression R_PAREN sblock
|
||||
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock
|
||||
| sblock
|
||||
| sblock
|
||||
;
|
||||
|
||||
|
||||
@ -356,22 +392,22 @@ compound_statement:
|
||||
simple_statement:
|
||||
assignable ASSIGN expression
|
||||
{
|
||||
if(strcmp($1, $3) == 0) {
|
||||
if(strcmp(getName($1), getName($3)) == 0) {
|
||||
printdebug("Passed standard type check; assignable = expression");
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "array") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "record") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else if((strcmp(getType(look_up(cur, $1)), "function type primitive") == 0) && (strcmp($3, "address") == 0)) {
|
||||
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else if((strcmp(getType($1), "array") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||
printdebug("%s[☺] Passed array type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||
} else if((strcmp(getType($1), "record") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||
printdebug("%s[☺] Passed address type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||
} else if((strcmp(getType($1), "function type primitive") == 0) && (strcmp(getName($3), "address") == 0)) {
|
||||
printdebug("%s[☺] Passed function type primitive type check; %s = %s", COLOR_GREEN, getName($1), getName($3));
|
||||
// } else if () {
|
||||
|
||||
// } else if(strcmp(getType(table_lookup(cur, $1)), getType(table_lookup(cur, $3))) == 0) {
|
||||
// printdebug("%s[] Passed double lookup type check; %s = %s", COLOR_GREEN, $1, $3);
|
||||
} else {
|
||||
printdebug("%s[TYPE ERROR] %sMismatch at %sline %d and column %d%s", COLOR_ORANGE, COLOR_WHITE, COLOR_YELLOW, @2.first_line, @2.first_column, COLOR_WHITE);
|
||||
printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, $1, $3, COLOR_WHITE);
|
||||
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType(look_up(cur, $1)));
|
||||
printdebug(" - Invalid types %s$1: %s and $3: %s%s", COLOR_YELLOW, getType($1), getType($3), COLOR_WHITE);
|
||||
printdebug(" - %sgetType for address: %s", COLOR_YELLOW, getType($1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,8 +424,8 @@ rec_op:
|
||||
ablock:
|
||||
L_PAREN argument_list R_PAREN
|
||||
{
|
||||
$<integ>$ = $<integ>2;
|
||||
printdebug("ablock is %d", $<integ>$);
|
||||
$$ = $2;
|
||||
printdebug("ablock is %d", $$);
|
||||
}
|
||||
;
|
||||
|
||||
@ -398,34 +434,33 @@ ablock:
|
||||
argument_list:
|
||||
expression COMMA argument_list
|
||||
{
|
||||
CreateEntry(cur, look_up(cur, $1), "", NULL);
|
||||
$<integ>$ = $<integ>3 + 1;
|
||||
printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$);
|
||||
CreateEntry(cur,getAdInfoType($1), $1, getName($1), NULL);
|
||||
$$ = $3 + 1;
|
||||
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||
}
|
||||
|
||||
| expression
|
||||
{
|
||||
CreateEntry(cur, look_up(cur, $1), "", NULL);
|
||||
$<integ>$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $<integ>$);
|
||||
CreateEntry(cur,getAdInfoType($1),$1, getName($1), NULL);
|
||||
$$ = 1; printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
// will ALWAYS be a TYPE
|
||||
expression:
|
||||
constant
|
||||
{
|
||||
printdebug("constant expression");
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
}
|
||||
|
||||
| SUB_OR_NEG expression %prec UMINUS
|
||||
{
|
||||
printdebug("negative expression");
|
||||
if(strcmp($2,"integer") != 0) {
|
||||
if($2 != integ) {
|
||||
printdebug("cant negate something not an integer at line %d and column %d",@2.first_line,@2.first_column);
|
||||
$$=strdup("undefined");
|
||||
$$=undefined;
|
||||
} else {
|
||||
$$=$2;
|
||||
}
|
||||
@ -434,133 +469,133 @@ expression:
|
||||
| NOT expression
|
||||
{
|
||||
printdebug("not expression");
|
||||
if(strcmp($2,"Boolean")==0) {
|
||||
if($2 == boo) {
|
||||
$$=$2;
|
||||
} else {
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,$2);
|
||||
$$=undefined;
|
||||
printdebug("mismatch at line %d and column %d. Invalid type being negated is %s", @1.first_line,@1.first_column,getName($2));
|
||||
}
|
||||
}
|
||||
|
||||
| expression ADD expression
|
||||
{
|
||||
printdebug("add expression");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) {
|
||||
$$=strdup("integer");
|
||||
if($1 == $3 && $1 == integ) {
|
||||
$$=$1;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression SUB_OR_NEG expression
|
||||
{
|
||||
printdebug("sub or neg expression");
|
||||
if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) {
|
||||
$$=strdup("integer");
|
||||
if($1 == $3 && $1 == integ) {
|
||||
$$=$1;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression MUL expression
|
||||
{
|
||||
printdebug("multiply expression");
|
||||
if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0) {
|
||||
$$=strdup("integer");
|
||||
if($1 == $3 && $1 == integ) {
|
||||
$$=$1;
|
||||
} else{
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression DIV expression
|
||||
{
|
||||
printdebug("divide expression");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) {
|
||||
$$=strdup("integer");
|
||||
if((strcmp(getName($1),getName($3))==0) && ($1 == integ)) {
|
||||
$$=$1;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression REM expression
|
||||
{
|
||||
printdebug("remainder expression");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) {
|
||||
$$=strdup("integer");
|
||||
if($1 == $3 && $1 == integ) {
|
||||
$$=$1;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression AND expression
|
||||
{
|
||||
printdebug("AND expression");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) {
|
||||
$$=strdup("Boolean");
|
||||
if($1 == $3 && $1 == boo){
|
||||
$$=$1;
|
||||
} else{
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression OR expression
|
||||
{
|
||||
printdebug("OR");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0) {
|
||||
$$=strdup("Boolean");
|
||||
if((strcmp(getName($1),getName($3))==0) && $1 == boo) {
|
||||
$$=$1;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
| expression LESS_THAN expression
|
||||
{
|
||||
printdebug("less than expression");
|
||||
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0) {
|
||||
$$=strdup("Boolean");
|
||||
if($1 == $3 && $1==integ) {
|
||||
$$=boo;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s.", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| expression EQUAL_TO expression
|
||||
{
|
||||
printdebug("equals check expression");
|
||||
if(strcmp($1,$3)==0) {
|
||||
$$=strdup("Boolean");
|
||||
if($1 == $3 && $1 != undefined) {
|
||||
$$=boo;
|
||||
} else {
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,$1,$3);
|
||||
$$=strdup("undefined");
|
||||
printdebug("mismatch at line %d and column %d. Invalid types %s and %s", @2.first_line,@2.first_column,getName($1),getName($3));
|
||||
$$ = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
| assignable
|
||||
{
|
||||
printdebug("assignable expression. current type is %s",$1);
|
||||
$$=$1;
|
||||
$$= getTypeEntry($1);
|
||||
}
|
||||
|
||||
| L_PAREN expression R_PAREN
|
||||
{
|
||||
printdebug("paren expression. current type is %s",$2);
|
||||
printdebug("paren expression. current type is %s",getName($2));
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
| memOp assignable
|
||||
{
|
||||
$$ = strdup("address");
|
||||
$$ = addr;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
|
||||
//UPDATED $$ for tablenodes to this point
|
||||
|
||||
// prolly right, check back with me later
|
||||
// add array case
|
||||
@ -568,7 +603,7 @@ expression:
|
||||
assignable:
|
||||
ID
|
||||
{
|
||||
$$ = getType(look_up(cur,$1));
|
||||
$$ = look_up(cur,$1);
|
||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", $$, $1);
|
||||
}
|
||||
|
||||
@ -579,59 +614,69 @@ assignable:
|
||||
}
|
||||
ablock
|
||||
{
|
||||
int type = getAdInfoType(look_up(getParent(cur), $1));
|
||||
int type = getAdInfoType(look_up(getParent(cur), getName($1)));
|
||||
printdebug("%stype is %d", COLOR_PURPLE, type);
|
||||
printdebug("%s", $1);
|
||||
|
||||
if (type == TYPE_FUNCTION_DECLARATION) {
|
||||
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
|
||||
if (getAsKeyword(look_up(getParent(cur), $1))) {
|
||||
TableNode *param = getParameter(look_up(getParent(cur), $1));
|
||||
if (look_up(getParent(cur), getName($1))->additionalinfo->FunDecAdInfo->regularoras) {
|
||||
printdebug("as function");
|
||||
//char *funtype = getType(look_up(cur, $1));
|
||||
printdebug("%s", getType(look_up(cur, getName($1))));
|
||||
TableNode *param = getParameter(look_up(getParent(cur), getName($1)));
|
||||
SymbolTable *recList = getRecList(param);
|
||||
TableNode *lastCheckedRef = getFirstEntry(recList);
|
||||
TableNode *lastCheckedAct = getFirstEntry(cur);
|
||||
while (getNextEntry(lastCheckedRef) != NULL) {
|
||||
lastCheckedRef = getNextEntry(lastCheckedRef);
|
||||
lastCheckedRef = getNextEntry(lastCheckedRef);
|
||||
}
|
||||
|
||||
|
||||
//this isn't very efficient, but will hopefully work
|
||||
while (lastCheckedAct != NULL && lastCheckedRef != NULL) {
|
||||
if (strcmp(getName(lastCheckedAct), getName(lastCheckedRef)) != 0) {
|
||||
printdebug("expected %s expression in function call but got %s at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
printdebug("expected %s. expression in function call got %s. at line %d and column %d",getType(lastCheckedRef), getName(lastCheckedAct), @3.first_line, @3.first_column);
|
||||
printdebug("%d", strcmp(getName(lastCheckedAct), getName(lastCheckedRef)));
|
||||
}
|
||||
lastCheckedAct = getNextEntry(lastCheckedAct);
|
||||
TableNode *tn = getFirstEntry(recList);
|
||||
while (getNextEntry(tn) != lastCheckedRef) {
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
lastCheckedRef = tn;
|
||||
}
|
||||
|
||||
if (tn != lastCheckedRef) {
|
||||
while (getNextEntry(tn) != lastCheckedRef) {
|
||||
tn = getNextEntry(tn);
|
||||
}
|
||||
lastCheckedRef = tn;
|
||||
} else {break;}
|
||||
}
|
||||
|
||||
} 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));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$$ = getName(getReturn(table_lookup(getAncestor(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
$$ = getReturn((table_lookup(getAncestor(cur), getType($1))));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
|
||||
|
||||
} else if (type == TYPE_ARRAY_TYPE) {
|
||||
printdebug("%sEntering array call", COLOR_LIGHTGREEN);
|
||||
if (getNumArrDim(look_up(getParent(cur), $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);
|
||||
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, getName($1))), $<integ>2, @2.first_line, @2.first_column);
|
||||
}
|
||||
$$ = getName(getArrType(look_up(getParent(cur), $1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", $$, $1);
|
||||
$$ = getArrType(look_up(getParent(cur), getName($1)));
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName($$), getName($1));
|
||||
}
|
||||
cur = getParent(cur);
|
||||
}
|
||||
|
||||
| assignable rec_op ID
|
||||
{
|
||||
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3)) {
|
||||
$$ = getName(table_lookup(getRecList(table_lookup(getAncestor(cur), $1)), $3));
|
||||
if(undefined != table_lookup(getRecList(table_lookup(getAncestor(cur), getName($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);
|
||||
}
|
||||
|
||||
;
|
||||
@ -655,37 +700,37 @@ memOp:
|
||||
constant:
|
||||
C_STRING
|
||||
{
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
printdebug("string of C_STRING in constant is %s",$<words>1);
|
||||
}
|
||||
|
||||
| C_INTEGER
|
||||
{
|
||||
$$ = "integer";
|
||||
$$ = integ;
|
||||
printdebug("string of C_INTEGER in constant is integer");
|
||||
}
|
||||
|
||||
| C_NULL
|
||||
{
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
printdebug("string of C_NULL in constant is %s",$<words>1);
|
||||
}
|
||||
|
||||
| C_CHARACTER
|
||||
{
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
printdebug("string of C_CHARACTER in constant is %s",$<words>1);
|
||||
}
|
||||
|
||||
| C_TRUE
|
||||
{
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
printdebug("string of C_TRUE in constant is %s",$<words>1);
|
||||
}
|
||||
|
||||
| C_FALSE
|
||||
{
|
||||
$$ = $<words>1;
|
||||
$$ = $1;
|
||||
printdebug("string of C_FALSE in constant is %s",$<words>1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user