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); }
intercodes translate_DefList(struct Node *node) { intercodes code1,code2; //NULL if (node == NULL) return NULL; struct Node *child = node->child; assert(child != NULL); //Def DefList code1 = translate_Def(child); code2 = translate_DefList(child->sibling); code1 = link(code1,code2); return code1; }
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; }
InterCodeNode translate_DefList(treenode *DefList_n){ if(DefList_n == NULL){ //deprintf("DefList is NULL\n"); return NULL; } if(DefList_n->child_num != 2){ // deflist -> empty //deprintf("DefList is empty\n"); return NULL; } //deflist -> def deflist InterCodeNode node1 = translate_Def(DefList_n->node[0]); InterCodeNode node2 = translate_DefList(DefList_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_DefList(struct TreeNode* DefList){ if(DefList->children == NULL){ struct InterCodes* code1 = (struct InterCodes*)malloc(sizeof(struct InterCodes)); code1->code.kind = NONE_; return code1; } else{ struct InterCodes* code1 = translate_Def(DefList->children->neighbours); struct InterCodes* code2 = translate_DefList(DefList->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }
MCAHead translate_CompSt(Node *n, SymbolTable table, MCA mca) { assert(n->nodetype == CompSt); Var v1, v2, v3; Node* stmtlist = NT_getChild(n, 2); Node* deflist = NT_getChild(n, 1); Node *stmt; MCAHead h = NULL; MCAHead h1, h2, h3; h = translate_DefList(deflist, table, mca); while(stmtlist->seq != 1) { stmt = NT_getChild(stmtlist, 0); h1 = translate_Stmt(stmt, table, mca); h = LinkMulMCAHead(mca, 2, h, h1); stmtlist = NT_getChild(stmtlist, 1); } return h; }