InterCodeNode translate_Def(treenode *Def_n){ if(Def_n == NULL){ //deprintf("Def is NULL\n"); return NULL; } // def -> specifier declist ; assert(Def_n->child_num == 3); return translate_DecList(Def_n->node[1]); }
InterCodeNode translate_DecList(treenode *DecList_n){ if(DecList_n == NULL){ //deprintf("DecList is NULL\n"); return NULL; } if(DecList_n->child_num == 1){ //declist -> dec return translate_Dec(DecList_n->node[0]); } //declist -> dec , declist assert(DecList_n->child_num == 3); InterCodeNode node1 = translate_Dec(DecList_n->node[0]); InterCodeNode node2 = translate_DecList(DecList_n->node[2]); return produceNodeByNode(node1,node2); }
intercodes translate_DecList(struct Node *node) { struct Node *child = node->child; assert(child != NULL); intercodes code1 = NULL; intercodes code2 = NULL; //Dec if (child->sibling == NULL) return translate_Dec(child); //Dec COMMA DecList if (child->sibling != NULL && strcmp(child->sibling->type,"COMMA") == 0) { code1 = translate_Dec(child); code2 = translate_DecList(child->sibling->sibling); code1 = link(code1,code2); return code1; } }
struct InterCodes* translate_DecList(struct TreeNode* DecList){ if(strcmp(DecList->children->name, "Dec") == 0){ return translate_Dec(DecList->children); } if(strcmp(DecList->children->name, "DecList") == 0){ struct InterCodes* code1 = translate_Dec(DecList->children->neighbours->neighbours); struct InterCodes* code2 = translate_DecList(DecList->children); struct InterCodes* p = code1; while(p->next != NULL) p = p->next; p->next = code2; code2->prev = p; return code1; } }
MCAHead translate_DefList(Node *n, SymbolTable table, MCA mca) { assert(n->nodetype == DefList); Var v1, v2, v3; Node* deflist = n; Node *declist = NULL; MCAHead h = NULL; MCAHead h1, h2, h3; while(deflist->seq != 1) { declist = NT_getChild(NT_getChild(deflist, 0), 1); h1 = translate_DecList(declist, table, mca); h = LinkMulMCAHead(mca, 2, h, h1); deflist = NT_getChild(deflist, 1); } return h; }
struct InterCodes* translate_Def(struct TreeNode* Def){ return translate_DecList(Def->children->neighbours); }
intercodes translate_Def(struct Node *node) { struct Node *child = node->child; assert(child != NULL); //Specifier DecList SEMI return translate_DecList(child->sibling); }