It worksgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit statusgit status!
This commit is contained in:
@ -130,20 +130,11 @@ prototype:
|
|||||||
definition:
|
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),TYPE_RECORD_TYPE, 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)));
|
||||||
printdebug("Created a new scope");
|
printdebug("Created a new scope");
|
||||||
//if (look_up(cur, $2) == undefined) {
|
} dblock {
|
||||||
// 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.
|
|
||||||
setRecSize(look_up(getParent(cur), $2), getRecSize(cur));
|
setRecSize(look_up(getParent(cur), $2), getRecSize(cur));
|
||||||
//putting in all the offsets
|
|
||||||
setRecOffsetInfo(cur, look_up(getParent(cur),$2));
|
setRecOffsetInfo(cur, look_up(getParent(cur),$2));
|
||||||
printdebug("Moving up a scope after seeing a record definition");
|
printdebug("Moving up a scope after seeing a record definition");
|
||||||
cur = getParent(cur);
|
cur = getParent(cur);
|
||||||
@ -155,9 +146,7 @@ definition:
|
|||||||
CreateEntry(cur,TYPE_ARRAY_TYPE, arrayprim, $2, CreateArrayInfo($4, (TableNode*)$6));
|
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));
|
printdebug("%sID: %s, dimensions: %d, typeOfArray: %s", COLOR_GREEN, $2, $4, getName((TableNode*)$6));
|
||||||
}
|
}
|
||||||
|
|
||||||
| function_declaration
|
| function_declaration
|
||||||
|
|
||||||
| 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", $2, getName((TableNode*)$4), getName((TableNode*)$6));
|
printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s", $2, getName((TableNode*)$4), getName((TableNode*)$6));
|
||||||
@ -655,7 +644,11 @@ rec_op:
|
|||||||
|
|
||||||
ablock:
|
ablock:
|
||||||
L_PAREN{
|
L_PAREN{
|
||||||
emit_push_all(S_Pop(stack));
|
if (stack == NULL){
|
||||||
|
stack = S_Init();
|
||||||
|
}
|
||||||
|
Stack * t = S_Init();
|
||||||
|
S_Push(stack, t, 0);
|
||||||
}
|
}
|
||||||
argument_list {
|
argument_list {
|
||||||
} R_PAREN
|
} R_PAREN
|
||||||
@ -675,12 +668,9 @@ argument_list:
|
|||||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||||
// this emits params for function and arrays TODO: fix
|
// this emits params for function and arrays TODO: fix
|
||||||
Stack * t = S_Peek(stack);
|
Stack * t = S_Peek(stack);
|
||||||
if (stack == NULL){
|
if(t==NULL){
|
||||||
stack = S_Init();
|
|
||||||
}
|
|
||||||
if(t == NULL){
|
|
||||||
t = S_Init();
|
t = S_Init();
|
||||||
S_Push(stack, t, 0);
|
S_Push(stack, t, 1);
|
||||||
}
|
}
|
||||||
emit_parameter(tn_or_const(NODE,arg));
|
emit_parameter(tn_or_const(NODE,arg));
|
||||||
S_Push(t, current, 1);
|
S_Push(t, current, 1);
|
||||||
@ -694,17 +684,7 @@ argument_list:
|
|||||||
|
|
||||||
{
|
{
|
||||||
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
TableNode* arg = CreateEntry(cur, getAdInfoType((TableNode*)$1), getTypeEntry((TableNode*)$1), arg_var_gen(), NULL);
|
||||||
Stack * t = S_Peek(stack);
|
|
||||||
if (stack == NULL){
|
|
||||||
stack = S_Init();
|
|
||||||
}
|
|
||||||
if(t == NULL){
|
|
||||||
t = S_Init();
|
|
||||||
S_Push(stack, t, 0);
|
|
||||||
}
|
|
||||||
emit_parameter(tn_or_const(NODE,arg));
|
emit_parameter(tn_or_const(NODE,arg));
|
||||||
S_Push(t, current, 1);
|
|
||||||
emit_detach();
|
|
||||||
$$ = 1;
|
$$ = 1;
|
||||||
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
printdebug("[ARGUMENT_LIST] argument list is %d", $$);
|
||||||
}
|
}
|
||||||
@ -940,7 +920,6 @@ assignable:
|
|||||||
$$ = pass;
|
$$ = pass;
|
||||||
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", getType(pass), getName(pass));
|
printdebug("[ASSIGNABLE - RULE 1] assignable = type: %s | ID = %s", getType(pass), getName(pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
| assignable
|
| assignable
|
||||||
{
|
{
|
||||||
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
|
printdebug("%sBeginning rule 2 of assignable.", COLOR_CYAN);
|
||||||
@ -1035,7 +1014,8 @@ assignable:
|
|||||||
int a = S_Size(S_Peek(stack));
|
int a = S_Size(S_Peek(stack));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
emit_push_all(S_Pop(stack));
|
emit_push_all(S_Peek(stack));
|
||||||
|
S_Pop(stack);
|
||||||
emit_function_call(node, a, tn_or_const(NODE, $1));
|
emit_function_call(node, a, tn_or_const(NODE, $1));
|
||||||
$$ = node;
|
$$ = node;
|
||||||
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK for function call)
|
//NOTE ADD ASSIGNMENT EMIT HERE (MIGHT NEED TO PUSH TO STACK for function call)
|
||||||
|
@ -25,7 +25,7 @@ void S_Push(Stack * s, void *v, int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void * S_Pop(Stack *s) {
|
void * S_Pop(Stack *s) {
|
||||||
if (s == NULL || !S_IsEmpty(s)) {
|
if (s == NULL || S_IsEmpty(s)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
__Node * node = s->n;
|
__Node * node = s->n;
|
||||||
@ -38,14 +38,14 @@ void * S_Pop(Stack *s) {
|
|||||||
|
|
||||||
|
|
||||||
void * S_Peek(Stack *s){
|
void * S_Peek(Stack *s){
|
||||||
if (s == NULL || !S_IsEmpty(s)) {
|
if (s == NULL || S_IsEmpty(s)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return s->n->v;
|
return s->n->v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool S_IsEmpty(Stack *s){
|
bool S_IsEmpty(Stack *s){
|
||||||
if(!s) {
|
if(s == NULL || s->size == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -69,7 +69,7 @@ char * temp = NULL;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void emit_push_all(Stack * s){
|
void emit_push_all(Stack * s){
|
||||||
for (Instruction * i = S_Pop(s); s; i = S_Pop(s)){
|
for (Instruction * i = S_Pop(s); i; i = S_Pop(s)){
|
||||||
current->next = i;
|
current->next = i;
|
||||||
i->prev = current;
|
i->prev = current;
|
||||||
current = i;
|
current = i;
|
||||||
|
@ -102,9 +102,6 @@ void print_tok(int tok) {
|
|||||||
int run(FILE *alpha) {
|
int run(FILE *alpha) {
|
||||||
int token;
|
int token;
|
||||||
top = cur = init(CreateScope(NULL, 1, 1));
|
top = cur = init(CreateScope(NULL, 1, 1));
|
||||||
Stack *stack = S_Init();
|
|
||||||
Stack *TrueList = S_Init();
|
|
||||||
Stack *FalseList = S_Init();
|
|
||||||
|
|
||||||
|
|
||||||
// If file is not found
|
// If file is not found
|
||||||
@ -130,6 +127,9 @@ int run(FILE *alpha) {
|
|||||||
fseek(alpha, 0, SEEK_SET);
|
fseek(alpha, 0, SEEK_SET);
|
||||||
|
|
||||||
yyin = alpha;
|
yyin = alpha;
|
||||||
|
stack = S_Init();
|
||||||
|
TrueList = S_Init();
|
||||||
|
FalseList = S_Init();
|
||||||
yyparse();
|
yyparse();
|
||||||
|
|
||||||
if (tok_flag != NULL) {
|
if (tok_flag != NULL) {
|
||||||
|
@ -70,6 +70,9 @@ TableNode *recprime;
|
|||||||
TableNode *funtypeprime;
|
TableNode *funtypeprime;
|
||||||
TableNode *undefined;
|
TableNode *undefined;
|
||||||
extern Instruction *begin;
|
extern Instruction *begin;
|
||||||
|
extern Stack* stack;
|
||||||
|
extern Stack* TrueList;
|
||||||
|
extern Stack* FalseList;
|
||||||
|
|
||||||
int main(int argc, char *argv[]);
|
int main(int argc, char *argv[]);
|
||||||
int check_flag(char *arg, char *alpha);
|
int check_flag(char *arg, char *alpha);
|
||||||
|
Reference in New Issue
Block a user