InterCodeNode translate_CompSt(treenode *CompSt_n){ if(CompSt_n == NULL){ //deprintf("CompSt is NULL\n"); return NULL; } //compst -> { deflist stmtlist } assert(CompSt_n->child_num == 4); InterCodeNode node1 = translate_DefList(CompSt_n->node[1]); InterCodeNode node2 = translate_StmtList(CompSt_n->node[2]); return produceNodeByNode(node1,node2); }
struct InterCodes* translate_CompSt(struct TreeNode* CompSt){ printf("CompSt - LC DefList StmtList RC\n"); struct InterCodes* code1 = translate_DefList(CompSt->children->neighbours->neighbours); struct InterCodes* code2 = translate_StmtList(CompSt->children->neighbours); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; }
intercodes translate_StmtList(struct Node *node) { intercodes code1 = NULL; intercodes code2 = NULL; //NULL if (node == NULL) return NULL; struct Node *child = node->child; assert(child != NULL); //Stmt StmtList code1 = translate_Stmt(child); code2 = translate_StmtList(child->sibling); //code1 = link(code1,code2); return code1; }
InterCodeNode translate_StmtList(treenode *StmtList_n){ if(StmtList_n == NULL){ //deprintf("StmtList is NULL\n"); return NULL; } if(StmtList_n->child_num != 2){ //stmtlist -> empty assert(StmtList_n->child_num == 0); //deprintf("StmtList is empty\n"); return NULL; } //stmtlist -> stmt stmtlist InterCodeNode node1 = translate_Stmt(StmtList_n->node[0]); //show(node1); InterCodeNode node2 = translate_StmtList(StmtList_n->node[1]); return produceNodeByNode(node1,node2); }
intercodes translate_CompSt(struct Node *node) { intercodes code1 = NULL; intercodes code2 = NULL; struct Node *child = node->child; assert(child != NULL); //LC DefList StmtList RC child = child->sibling; if (child != NULL && strcmp(child->type,"DefList") == 0) { code1 = translate_DefList(child); } if (child->sibling != NULL && strcmp(child->sibling->type,"StmtList") == 0) { code2 = translate_StmtList(child->sibling); } if (code1 != NULL) code1 = link(code1,code2); else code1 = code2; return code1; }
struct InterCodes* translate_StmtList(struct TreeNode* StmtList){ if(StmtList->children == NULL){ struct InterCodes* code1 = (struct InterCodes*)malloc(sizeof(struct InterCodes)); code1->code.kind = NONE_; return code1; } else{ struct InterCodes* code1 = translate_Stmt(StmtList->children->neighbours); struct InterCodes* code2 = translate_StmtList(StmtList->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }