intercodes translate_ExtDecList(struct Node *node) { intercodes code1,code2; struct Node *child = node->child; assert(child != NULL); //VarDec if (child->sibling == NULL) return translate_VarDec(child,NULL); if (child->sibling != NULL && strcmp(child->sibling->type,"COMMA") == 0) { code1 = translate_VarDec(child,NULL); code2 = translate_ExtDecList(child->sibling->sibling); code1 = link(code1,code2); return code1; } return NULL; }
InterCodeNode translate_ExtDef(treenode *ExtDef_n){ if(ExtDef_n == NULL){ //deprintf("ExtDef is NULL\n"); return NULL; } if(ExtDef_n->child_num == 3 && strcmp(ExtDef_n->node[1]->name,"FunDec") == 0){ //extdef -> specifier fundec compst InterCodeNode node1 = translate_FunDec(ExtDef_n->node[1]); InterCodeNode node2 = translate_CompSt(ExtDef_n->node[2]); return produceNodeByNode(node1,node2); }else if(ExtDef_n->child_num == 3 && strcmp(ExtDef_n->node[1]->name,"ExtDecList") == 0){ //extdef -> specifier extdeclist ; return translate_ExtDecList(ExtDef_n->node[1]); } return NULL; }
InterCodeNode translate_ExtDecList(treenode *ExtDecList_n){ if(ExtDecList_n == NULL){ //deprintf("ExtDecList is NULL"); return NULL; } if(ExtDecList_n->child_num == 1){ //extdeclist -> vardec Operand temp = new_Operand(); return translate_VarDec(ExtDecList_n->node[0],temp); } if(ExtDecList_n->child_num == 3){ Operand temp = new_Operand(); treenode *vardec_node = ExtDecList_n->node[0]; treenode *extdeclist_node = ExtDecList_n->node[2]; InterCodeNode node1 = translate_VarDec(vardec_node,temp); InterCodeNode node2 = translate_ExtDecList(extdeclist_node); return produceNodeByNode(node1,node2); } }
struct InterCodes* translate_ExtDecList(struct TreeNode* ExtDecList){ if(strcmp(ExtDecList->children->name, "VarDec") == 0){ printf("ExtDecList - VarDec\n"); struct InterCodes* code1 = translate_VarDec(ExtDecList->children); return code1; } if(strcmp(ExtDecList->children->name, "ExtDecList") == 0){ printf("ExtDecList - VarDec COMMA ExtDecList\n"); struct InterCodes* code1 = translate_VarDec(ExtDecList->children->neighbours->neighbours); struct InterCodes* code2 = translate_ExtDecList(ExtDecList->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }
intercodes translate_ExtDef(struct Node *node) { intercodes code1,code2; struct Node *child = node->child; assert(child != NULL); //Specifier ExtDecList SEMI if(child -> sibling!= NULL) { if (strcmp(child->sibling->type,"ExtDecList") == 0) { return translate_ExtDecList(child->sibling); } //Specifier FunDec CompSt if (strcmp(child->sibling->type,"FunDec") == 0) { code1 = translate_FunDec(child->sibling); code2 = translate_CompSt(child->sibling->sibling); code1 = link(code1,code2); return code1; } } //Specifier SIMI return NULL; }