I merged IR-Linting to Dev
This commit is contained in:
316
src/grammar.y
316
src/grammar.y
@ -122,7 +122,7 @@ prototype_or_definition_list:
|
||||
|
||||
prototype:
|
||||
L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -130,40 +130,29 @@ prototype:
|
||||
definition:
|
||||
TYPE ID COLON
|
||||
{
|
||||
|
||||
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)));
|
||||
printdebug("Created a new scope");
|
||||
//if (look_up(cur, $2) == undefined) {
|
||||
// printdebug("rec not found");
|
||||
//}
|
||||
}
|
||||
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.
|
||||
} dblock {
|
||||
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);
|
||||
}
|
||||
|
||||
| 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((TableNode*)$6), $4);
|
||||
printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d", $2, getName((TableNode*)$6), $4);
|
||||
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, (TableNode*)$6));
|
||||
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName((TableNode*)$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, getName((TableNode*)$4), getName((TableNode*)$6));
|
||||
CreateEntry(cur,TYPE_FUNCTION_TYPE,funtypeprime,$2,CreateFunctionTypeInfo((TableNode*)$4 ,(TableNode*)$6));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
| ID {
|
||||
emit_function_start(table_lookup(cur,$1));
|
||||
//printf("ID: %s\n", $1);
|
||||
@ -174,11 +163,11 @@ definition:
|
||||
printdebug("Undefined node declared.");
|
||||
}else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
|
||||
throw_error(ERROR_SYNTAX, "Not a valid function declaration.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printdebug("setting as keyword to true");
|
||||
setStartLine(node, @1.first_line);
|
||||
setAsKeyword(node, true);
|
||||
setAsKeyword(node, true);
|
||||
}
|
||||
cur = CreateScope(cur, 0, 0);
|
||||
printdebug("Created a new scope");
|
||||
@ -194,10 +183,10 @@ definition:
|
||||
|| type_of_param_type == TYPE_FUNCTION_DECLARATION
|
||||
|| type_of_param_type == TYPE_ARRAY
|
||||
|| type_of_param_type == TYPE_PRIMITIVE
|
||||
|| type_of_param_type == TYPE_ALL_ELSE
|
||||
|| type_of_param_type == TYPE_ALL_ELSE
|
||||
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|
||||
|| type_of_param_type == TYPE_RECORD
|
||||
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||
throw_error(ERROR_TYPE, "Invalid type (%s) of parameter in function definition.", getAdInfo(parameter));
|
||||
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
|
||||
}
|
||||
@ -222,10 +211,10 @@ definition:
|
||||
|| type_of_param_type == TYPE_FUNCTION_TYPE
|
||||
|| type_of_param_type == TYPE_ARRAY_TYPE
|
||||
|| type_of_param_type == TYPE_PRIMITIVE_TYPE
|
||||
|| type_of_param_type == TYPE_ALL_ELSE
|
||||
|| type_of_param_type == TYPE_ALL_ELSE
|
||||
|| type_of_param_type == TYPE_SYSTEM_DEFINED
|
||||
|| type_of_param_type == TYPE_RECORD_TYPE
|
||||
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||
|| type_of_param_type == TYPE_STRING){ // note that strings are actually arrays so this is unused
|
||||
throw_error(ERROR_TYPE, "Invalid type (%s) of parameter in function definition.", getAdInfo(entry));
|
||||
type_of_param_type = TYPE_UNDEFINED; // setting tag as undefined in these cases
|
||||
}else{
|
||||
@ -246,7 +235,7 @@ definition:
|
||||
if(type_of_param_type == TYPE_PRIMITIVE){
|
||||
printdebug("primitive type of parameter inside record");
|
||||
CreateEntry(cur, TYPE_PRIMITIVE, getTypeEntry(entry),NULL, getAdInfo(entry));
|
||||
}
|
||||
}
|
||||
/*printdebug("creating entry of type %s for function", getType(entry));
|
||||
CreateEntry(cur, getTypeEntry(entry), "undefined", NULL);*/
|
||||
}
|
||||
@ -270,13 +259,13 @@ definition:
|
||||
}
|
||||
//printf("Ending ID: %s\n", $1);
|
||||
//printf("Ending Type: %s\n", getType(table_lookup(getAncestor(cur), $1)));
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
function_declaration:
|
||||
FUNCTION ID COLON ID
|
||||
{
|
||||
{
|
||||
if(getAdInfoType(table_lookup(cur, $4))==TYPE_FUNCTION_TYPE){
|
||||
//printf("%s\n",$2);
|
||||
//printf("%s\n",getName(table_lookup(cur, $4)));
|
||||
@ -290,7 +279,7 @@ function_declaration:
|
||||
}
|
||||
|
||||
| EXTERNAL FUNCTION ID COLON ID
|
||||
{
|
||||
{
|
||||
if(getAdInfoType(look_up(cur, $5))==TYPE_FUNCTION_TYPE){
|
||||
CreateEntry(cur,TYPE_FUNCTION_DECLARATION, look_up(cur, $5), $3, CreateFunctionDeclarationInfo(-1, false));
|
||||
}
|
||||
@ -338,7 +327,7 @@ idlist:
|
||||
{
|
||||
$$ = $4 + 1;
|
||||
}
|
||||
|
||||
|
||||
| ID
|
||||
{ printdebug("idlist rule 2 ID: %s", $1);
|
||||
TableNode *entry = getFirstEntry(cur);
|
||||
@ -360,13 +349,14 @@ idlist:
|
||||
printdebug("Type of entry is %s", getType(entry));
|
||||
printdebug("tag is %d", getAdInfoType(entry));
|
||||
}
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
sblock:
|
||||
L_BRACE
|
||||
{
|
||||
// emit_label(label_gen());
|
||||
if (getLine(cur) != 0) {
|
||||
cur = CreateScope(cur,@1.first_line,@1.first_column);
|
||||
printdebug("Created a new scope");
|
||||
@ -383,7 +373,7 @@ sblock:
|
||||
}
|
||||
R_BRACE
|
||||
{$$ = $3;}
|
||||
|
||||
|
||||
| L_BRACE
|
||||
{
|
||||
if (getLine(cur) != 0) {
|
||||
@ -404,79 +394,79 @@ sblock:
|
||||
printdebug("Moving up a scope after seeing sblock with dblock");
|
||||
cur = getParent(cur);
|
||||
//$<tn>$ = $5;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
R_BRACE
|
||||
{$$ = $5;}
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
dblock:
|
||||
|
||||
L_BRACKET
|
||||
L_BRACKET
|
||||
{
|
||||
if (getLine(cur) == 0) {
|
||||
setLineNumber(cur, @1.first_line);
|
||||
setLineNumber(cur, @1.first_line);
|
||||
setColumnNumber(cur,@1.first_line);
|
||||
printdebug("Did not create a new scope when saw dblock, set line number to %d instead", @1.first_line);
|
||||
} else{
|
||||
//cur = CreateScope(cur,@1.first_line,@1.first_column); // <----- What is this?
|
||||
printdebug("Created a new scope when seeing a dblock");
|
||||
}
|
||||
}
|
||||
}
|
||||
declaration_list R_BRACKET
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
declaration_list:
|
||||
declaration SEMI_COLON declaration_list
|
||||
| declaration
|
||||
declaration SEMI_COLON declaration_list
|
||||
| declaration
|
||||
| error SEMI_COLON { yyerrok; } declaration_list //only perform error recovery once we see semi-colon
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
declaration:
|
||||
id_or_types COLON ID
|
||||
id_or_types COLON ID
|
||||
{
|
||||
printdebug("ID/TYPE: %s, ID: %s", getName((TableNode*)$1), $3) ;
|
||||
int d = getAdInfoType((TableNode*)$1);
|
||||
if(d == TYPE_UNDEFINED) {
|
||||
throw_error(ERROR_TYPE, "Undefined type passed in declaration list");
|
||||
printdebug("Undefined type passed in declaration list");
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}
|
||||
else if(d == TYPE_FUNCTION_TYPE) {
|
||||
printdebug("invalid (function) type passed in declaration list in dblock", @2.first_line, @2.first_column);
|
||||
d = TYPE_FUNCTION_DECLARATION;
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}
|
||||
else if(d == TYPE_ARRAY_TYPE){
|
||||
printdebug("array variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||
d = TYPE_ARRAY;
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}
|
||||
else if(d == TYPE_RECORD_TYPE){
|
||||
printdebug("record variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||
d = TYPE_RECORD;
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}
|
||||
else if(d == TYPE_PRIMITIVE_TYPE){
|
||||
printdebug("primitive variable at line %d and column %d", @2.first_line, @2.first_column);
|
||||
d = TYPE_PRIMITIVE;
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}else {
|
||||
throw_error(ERROR_TYPE, "%s is being defined with an undefined type", $3);
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
CreateEntry(cur,d,(TableNode*)$1,$3,getAdInfo((TableNode*)$1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -487,13 +477,13 @@ id_or_types:
|
||||
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.",getName((TableNode*)$1));
|
||||
$$ = (TableNode*)$1;
|
||||
}
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -521,7 +511,7 @@ compound_statement statement_list {
|
||||
}
|
||||
| compound_statement {
|
||||
$$ = $1;
|
||||
}
|
||||
}
|
||||
| simple_statement SEMI_COLON statement_list{
|
||||
if ($1 == undefined && $3 != undefined) {
|
||||
$$ = $3;
|
||||
@ -552,24 +542,55 @@ compound_statement statement_list {
|
||||
|
||||
|
||||
compound_statement:
|
||||
WHILE L_PAREN expression R_PAREN sblock {
|
||||
$$ = $5;
|
||||
}
|
||||
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock {
|
||||
if ($6 == undefined && $8 != undefined) {
|
||||
WHILE L_PAREN {
|
||||
S_Push(TrueList, S_Init(), 0);
|
||||
S_Push(FalseList, S_Init(), 0);
|
||||
int *l = calloc(1, sizeof(int));
|
||||
*l = label_gen();
|
||||
emit_label(*l);
|
||||
S_Push(stack, l, 2);
|
||||
} expression R_PAREN {
|
||||
emit_label(label_gen());
|
||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||
} sblock {
|
||||
$$ = $7;
|
||||
int l = label_gen();
|
||||
emit_backpatch(S_Pop(FalseList), l);
|
||||
emit_goto(*(int*)(S_Pop(stack)));
|
||||
emit_label(l);
|
||||
}
|
||||
| IF L_PAREN {
|
||||
S_Push(TrueList, S_Init(), 0);
|
||||
S_Push(FalseList, S_Init(), 0);
|
||||
}expression R_PAREN THEN {
|
||||
emit_label(label_gen());
|
||||
emit_backpatch(S_Pop(TrueList), getLabel(current));
|
||||
} sblock ELSE {
|
||||
// NOTE we are not going back to
|
||||
int l = label_gen();
|
||||
emit_backpatch(S_Pop(FalseList), l);
|
||||
S_Push(FalseList, S_Init(), 0);
|
||||
emit_goto(0);
|
||||
S_Push(S_Peek(FalseList), current, 1);
|
||||
emit_label(l);
|
||||
} sblock {
|
||||
int l = label_gen();
|
||||
emit_backpatch(S_Pop(FalseList), l);
|
||||
emit_label(l);
|
||||
if ($8 == undefined && $11 != undefined) {
|
||||
$$ = $11;
|
||||
} else if ($8 != undefined && $11 == undefined) {
|
||||
$$ = $8;
|
||||
} else if ($6 != undefined && $8 == undefined) {
|
||||
$$ = $6;
|
||||
} else if ($6 == $8) {
|
||||
$$ = $6;
|
||||
}else if((getAdInfoType((TableNode*)$6) == TYPE_ARRAY_TYPE) && ((TableNode*)$8)==addr){
|
||||
$$ = $6;
|
||||
}else if((getAdInfoType((TableNode*)$6) == TYPE_RECORD_TYPE) && ((TableNode*)$8)==addr){
|
||||
$$ = $6;
|
||||
}else if(((TableNode*)$6)==addr && (getAdInfoType((TableNode*)$8) == TYPE_ARRAY_TYPE)){
|
||||
} else if ($8 == $11) {
|
||||
$$ = $8;
|
||||
}else if(((TableNode*)$6)==addr && (getAdInfoType((TableNode*)$8) == TYPE_RECORD_TYPE)){
|
||||
}else if((getAdInfoType((TableNode*)$8) == TYPE_ARRAY_TYPE) && ((TableNode*)$11)==addr){
|
||||
$$ = $8;
|
||||
}else if((getAdInfoType((TableNode*)$8) == TYPE_RECORD_TYPE) && ((TableNode*)$11)==addr){
|
||||
$$ = $8;
|
||||
}else if(((TableNode*)$8)==addr && (getAdInfoType((TableNode*)$11) == TYPE_ARRAY_TYPE)){
|
||||
$$ = $11;
|
||||
}else if(((TableNode*)$8)==addr && (getAdInfoType((TableNode*)$11) == TYPE_RECORD_TYPE)){
|
||||
$$ = $11;
|
||||
} else {
|
||||
printdebug("3 differing return types within same function at line %d, column %d", @1.first_line, @1.first_column);
|
||||
//printf("%s\n", getName((TableNode*)$6));
|
||||
@ -577,7 +598,7 @@ WHILE L_PAREN expression R_PAREN sblock {
|
||||
$$ = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
| sblock {
|
||||
$$ = $1;
|
||||
}
|
||||
@ -587,14 +608,14 @@ WHILE L_PAREN expression R_PAREN sblock {
|
||||
|
||||
|
||||
simple_statement:
|
||||
assignable ASSIGN expression
|
||||
{ printdebug("simple statement");
|
||||
assignable ASSIGN expression
|
||||
{ printdebug("simple statement");
|
||||
TableNode* node;
|
||||
if((getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_FUNCTION_TYPE)||
|
||||
(getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_ARRAY_TYPE)||
|
||||
(getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_RECORD_TYPE)||
|
||||
(getAdInfoType((getTypeEntry((TableNode*)$1))) == TYPE_PRIMITIVE_TYPE)){
|
||||
|
||||
|
||||
node = ((TableNode*)$1);
|
||||
} else {
|
||||
//printf("%d\n",getAdInfoType((getTypeEntry((TableNode*)$1))));
|
||||
@ -616,8 +637,8 @@ simple_statement:
|
||||
emit_assignment($1, tn_or_const(NODE, $3));
|
||||
printdebug("%s[☺] Passed type check; %s = %s", COLOR_GREEN, getType(node), getType((TableNode*)$3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else {
|
||||
//printf("%d\n",getAdInfoType((TableNode*)$1));
|
||||
//printf("%d\n",getAdInfoType((TableNode*)$3));
|
||||
@ -635,7 +656,7 @@ simple_statement:
|
||||
emit_return(tn_or_const(NODE,(TableNode*)$2));}
|
||||
|simple_statement error {yyerrok; yyclearin; printdebug("error in simple statement");}
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -643,49 +664,61 @@ simple_statement:
|
||||
rec_op:
|
||||
DOT
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
ablock:
|
||||
L_PAREN argument_list R_PAREN
|
||||
L_PAREN{
|
||||
if (stack == NULL){
|
||||
stack = S_Init();
|
||||
}
|
||||
Stack * t = S_Init();
|
||||
S_Push(stack, t, 0);
|
||||
}
|
||||
argument_list {
|
||||
} R_PAREN
|
||||
{
|
||||
$$ = $2;
|
||||
// here
|
||||
$$ = $3;
|
||||
printdebug("ablock is %d", $$);
|
||||
}
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
argument_list:
|
||||
//NEED TO EMIT PARAMETERS HERE. MAYBE USE STACK STRUCTURE
|
||||
expression{
|
||||
char* name = arg_var_gen();
|
||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), name, NULL);
|
||||
emit_parameter(tn_or_const(NODE,arg));
|
||||
//S_Push(stack,current);
|
||||
//emit_detach();
|
||||
//printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||
// ----------------------------------------------------------------------------
|
||||
// this is emitting the param withthe wrong TableNode
|
||||
// We need to fiture out how to get the right one.
|
||||
Stack * t = S_Peek(stack);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(stack, t, 1);
|
||||
}
|
||||
emit_parameter(tn_or_const(NODE,$1));
|
||||
S_Push(t, current, 1);
|
||||
emit_detach();
|
||||
// ----------------------------------------------------------------------------
|
||||
}
|
||||
COMMA argument_list
|
||||
{$$ = $4 + 1;}
|
||||
|
||||
| expression
|
||||
|
||||
{
|
||||
char* name = arg_var_gen();
|
||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), name, NULL);
|
||||
emit_parameter(tn_or_const(NODE,arg));
|
||||
//S_Push(stack,current);
|
||||
//emit_detach();
|
||||
{
|
||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||
emit_parameter(tn_or_const(NODE,$1));
|
||||
$$ = 1;
|
||||
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -828,14 +861,27 @@ expression:
|
||||
throw_error(ERROR_TYPE, "Object %s of type %s and Object %s of type %s must both be Boolean", getName((TableNode*)$1), getType((TableNode*)$1), getName((TableNode*)$3), getType((TableNode*)$3));
|
||||
}
|
||||
}
|
||||
|
||||
| expression LESS_THAN expression
|
||||
|
||||
| expression LESS_THAN expression
|
||||
{
|
||||
emit_conditional_jump(E_LESS_THAN, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||
Stack * t = S_Peek(TrueList);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(TrueList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
emit_goto(0);
|
||||
t = S_Peek(FalseList);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(FalseList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
printdebug("less than expression");
|
||||
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==integ) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
emit_binary_op(E_LESS_THAN,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
$$ = node;
|
||||
} else if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1)==boo){
|
||||
char* temp = temp_var_gen();
|
||||
@ -854,9 +900,22 @@ expression:
|
||||
if(getTypeEntry((TableNode*)$1) == getTypeEntry((TableNode*)$3) && getTypeEntry((TableNode*)$1) != undefined) {
|
||||
char* temp = temp_var_gen();
|
||||
TableNode* node = CreateEntry(cur,TYPE_PRIMITIVE, boo, temp, NULL);
|
||||
emit_binary_op(E_EQUAL_TO,node,tn_or_const(NODE,$1),tn_or_const(NODE,$3));
|
||||
emit_conditional_jump(E_EQUAL_TO, 0, tn_or_const(NODE,$1), tn_or_const(NODE,$3));
|
||||
Stack * t = S_Peek(TrueList);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(TrueList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
emit_goto(0);
|
||||
t = S_Peek(FalseList);
|
||||
if(t==NULL){
|
||||
t = S_Init();
|
||||
S_Push(FalseList, t, 1);
|
||||
}
|
||||
S_Push(t, current, 1);
|
||||
$$ = node;
|
||||
|
||||
|
||||
} else {
|
||||
$$ = undefined;
|
||||
throw_error(ERROR_TYPE, "Object %s of type %s and Object %s of type %s must both be the same type", getName((TableNode*)$1), getType((TableNode*)$1), getName((TableNode*)$3), getType((TableNode*)$3));
|
||||
@ -867,15 +926,19 @@ expression:
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
|
||||
|
||||
| L_PAREN expression R_PAREN
|
||||
{
|
||||
printdebug("paren expression. current type is %s",getType((TableNode*)$2));
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
| RESERVE assignable
|
||||
{
|
||||
// TODO: We need to type check this.
|
||||
| RESERVE ID {$$ = undefined; }
|
||||
| RELEASE ID {$$ = undefined; }
|
||||
| RESERVE ID L_PAREN argument_list R_PAREN {$$ = undefined; }
|
||||
| RELEASE ID L_PAREN argument_list R_PAREN
|
||||
{
|
||||
int d = getAdInfoType((TableNode*)$2);
|
||||
//commenting out type checks for now since assignable is being resolved to something before reserve is being applied which is tricky
|
||||
//if(d == TYPE_ARRAY ||d == TYPE_RECORD) {
|
||||
@ -888,6 +951,7 @@ expression:
|
||||
// $$=undefined;
|
||||
// }
|
||||
}
|
||||
/*
|
||||
| RELEASE assignable
|
||||
{
|
||||
int d = getAdInfoType((TableNode*)$2);
|
||||
@ -902,7 +966,8 @@ expression:
|
||||
// $$=undefined;
|
||||
// }
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
;
|
||||
|
||||
//UPDATED $$ for tablenodes to this point
|
||||
@ -911,17 +976,16 @@ expression:
|
||||
// add array case
|
||||
// include type check for ablock in arrays - ablock is always the int of the elements in array/rec
|
||||
assignable:
|
||||
ID
|
||||
ID
|
||||
{
|
||||
TableNode* pass = look_up(cur,$1);
|
||||
if(pass == undefined){
|
||||
throw_error(ERROR_TYPE, "Undefined variable %s", $1);
|
||||
}
|
||||
$$ = pass;
|
||||
$$ = pass;
|
||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", getType(pass), getName(pass));
|
||||
}
|
||||
|
||||
| assignable
|
||||
| assignable
|
||||
{
|
||||
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
|
||||
//Creating a dummy scope where we create entries for all the arguments of a function call
|
||||
@ -929,13 +993,13 @@ assignable:
|
||||
cur = CreateScope(cur, -1,-1);
|
||||
}
|
||||
//we have to consider emmissions in ablocks
|
||||
ablock
|
||||
ablock
|
||||
{
|
||||
//int type = getAdInfoType(look_up(getParent(cur), getName((TableNode*)$1)));
|
||||
int type = getAdInfoType(getTypeEntry((TableNode*)$1));
|
||||
printdebug("%stype is %d", COLOR_PURPLE, type);
|
||||
printdebug("%s", getName((TableNode*)$1));
|
||||
|
||||
|
||||
if (type == TYPE_FUNCTION_TYPE) {
|
||||
printdebug("%sEntering function call", COLOR_LIGHTGREEN);
|
||||
//getting the parameter. The type of assignable is a function type so we need to access the paramater of the type
|
||||
@ -1007,6 +1071,14 @@ assignable:
|
||||
throw_error(ERROR_TYPE, "Undefined type returned by function.");
|
||||
}
|
||||
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
|
||||
//-----------------------------------------------------------------------------
|
||||
// Please don't touch
|
||||
// the + 1 is here because I don't detach the last param
|
||||
int a = S_Size(S_Peek(stack)) + 1;
|
||||
emit_push_all(S_Peek(stack));
|
||||
S_Pop(stack);
|
||||
emit_function_call(node, a, tn_or_const(NODE, $1));
|
||||
//-----------------------------------------------------------------------------
|
||||
$$ = node;
|
||||
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK for function call)
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getName(typeNode2), getName((TableNode*)$1));
|
||||
@ -1035,8 +1107,8 @@ assignable:
|
||||
throw_error(ERROR_TYPE, "Undefined type stored in array.");
|
||||
}
|
||||
TableNode* node = CreateEntry(cur,t, typeNode2, temp, NULL);
|
||||
//emit assign here
|
||||
//emit_array_access(char* node, char* array, ...)
|
||||
//TODO: emit assign here
|
||||
//TODO: emit_array_access(char* node, char* array, ...)
|
||||
$$ = node;
|
||||
printdebug("[ASSIGNABLE - RULE 2] assignable = type: %s | name_func = %s", getType((TableNode*)$1), getName((TableNode*)$1));
|
||||
}
|
||||
@ -1059,8 +1131,8 @@ assignable:
|
||||
}
|
||||
|
||||
| assignable rec_op ID
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
if(getAdInfoType((TableNode*)$1) != TYPE_RECORD){
|
||||
throw_error(ERROR_TYPE, "Invalid type passed to record access");
|
||||
$$ = undefined;
|
||||
@ -1088,16 +1160,16 @@ assignable:
|
||||
|
||||
TableNode* node = CreateEntry(cur,t, type, temp, NULL);
|
||||
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK)
|
||||
//emit_field_access(char* node, char* record, $3)
|
||||
//emit_field_access(char* node, char* record, $3)
|
||||
$$=node;
|
||||
}else{
|
||||
throw_error(ERROR_TYPE, "Invalid field access %s", $3);
|
||||
$$=undefined;
|
||||
}
|
||||
}
|
||||
printdebug("[ASSIGNABLE - RULE 3] record = name: %s | field = %s", getName((TableNode*)($1)), getName((TableNode*)$3));
|
||||
}
|
||||
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
||||
@ -1119,7 +1191,7 @@ constant:
|
||||
printdebug("number of C_INTEGER in constant is %d", $1);
|
||||
$$ = node;
|
||||
}
|
||||
|
||||
|
||||
| C_NULL
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
@ -1128,7 +1200,7 @@ constant:
|
||||
printdebug("string of C_NULL in constant is NULL");
|
||||
$$ = node;
|
||||
}
|
||||
|
||||
|
||||
| C_CHARACTER
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
@ -1137,7 +1209,7 @@ constant:
|
||||
printdebug("string of C_CHARACTER in constant is %s",$1);
|
||||
$$ = node;
|
||||
}
|
||||
|
||||
|
||||
| C_TRUE
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
@ -1147,7 +1219,7 @@ constant:
|
||||
printdebug("string of C_TRUE in constant is true");
|
||||
$$ = node;
|
||||
}
|
||||
|
||||
|
||||
| C_FALSE
|
||||
{
|
||||
char* temp = temp_var_gen();
|
||||
@ -1162,25 +1234,25 @@ constant:
|
||||
|
||||
|
||||
|
||||
types:
|
||||
types:
|
||||
T_INTEGER
|
||||
{
|
||||
$$ = $1;
|
||||
printdebug("string of T_INTEGER in types is %s",getName((TableNode*)$1));
|
||||
}
|
||||
|
||||
|
||||
| T_ADDRESS
|
||||
{
|
||||
$$ = $1;
|
||||
printdebug("string of T_ADDRESS in types is %s",getName((TableNode*)$1));
|
||||
}
|
||||
|
||||
|
||||
| T_CHARACTER
|
||||
{
|
||||
$$ = $1;
|
||||
printdebug("string of T_CHARACTER in types is %s",getName((TableNode*)$1));
|
||||
}
|
||||
|
||||
|
||||
| T_BOOLEAN
|
||||
{
|
||||
$$ = $1;
|
||||
@ -1267,7 +1339,7 @@ void throw_error(ErrorType error_type, const char *format, ...) {
|
||||
void yyerror(const char *err) {
|
||||
int line = yylloc.first_line;
|
||||
int column = yylloc.first_column;
|
||||
|
||||
|
||||
// Grammar Fallback Case
|
||||
if (strcmp(err, "syntax error") == 0) {
|
||||
if (asc_flag != NULL) {
|
||||
|
Reference in New Issue
Block a user