InterCodeNode translate_Program(treenode *root){ if(root == NULL){ //deprintf("Root is NULL\n"); return NULL; }else{ //program -> extdeflist translate_ExtDefList(root->node[0]); } }
InterCodeNode translate_ExtDefList(treenode *ExtDefList_n){ if(ExtDefList_n == NULL){ //deprintf("ExtDefList is NULL\n"); return NULL; } if(ExtDefList_n->child_num != 2){ //extdeflist -> empty //deprintf("ExtDefList is empty\n"); return NULL; }else{ //extdeflist -> extdef extdeflist InterCodeNode node1 = translate_ExtDef(ExtDefList_n->node[0]); InterCodeNode node2 = translate_ExtDefList(ExtDefList_n->node[1]); return produceNodeByNode(node1,node2); } }
struct InterCodes* translate_ExtDefList(struct TreeNode* ExtDefList){ if(ExtDefList->children == NULL){ struct InterCodes* code1 = (struct InterCodes*)malloc(sizeof(struct InterCodes)); code1->code.kind = NONE_; return code1; } else{ struct InterCodes* code1 = translate_ExtDef(ExtDefList->children->neighbours); struct InterCodes* code2 = translate_ExtDefList(ExtDefList->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }
struct InterCodes* GenerateInterCode(struct TreeNode* root){ return translate_ExtDefList(root->children); }