struct InterCodes* translate_ExtDef(struct TreeNode* ExtDef){ if(strcmp(ExtDef->children->name, "CompSt") == 0){ struct InterCodes* code1 = translate_FunDec(ExtDef->children->neighbours); struct InterCodes* code2 = translate_CompSt(ExtDef->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }
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; }
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; }
MCAHead translate_Program(Node *n, SymbolTable table, MCA mca) { assert(n->nodetype == Program); Var v1, v2, v3; Node* extdl = NT_getChild(n, 0); Node *ext, *comp, *funcdecid; MCAHead h = NULL; MCAHead h1, h2, h3; while(extdl->seq != 1) { ext = NT_getChild(extdl, 0); if(ext->seq == 2) { h1 = translate_FunDec(NT_getChild(ext, 1), table, mca); #ifdef debug printf("fundec\n"); printMCA(mca, h1); printf("fundec\n"); #endif comp = NT_getChild(ext, 2); h2 = translate_CompSt(comp, table, mca); if(h == NULL) h = LinkMulMCAHead(mca, 2, h1, h2); else h = LinkMulMCAHead(mca, 3, h, h1, h2); } extdl = NT_getChild(extdl, 1); } return h; }