Question: Please explain this program function and test it if possible. It is based Linux. #include #include calc3.h #include y.tab.h static int lbl; int ex(nodeType *p)

Please explain this program function and test it if possible. It is based Linux.

#include #include "calc3.h" #include "y.tab.h"

static int lbl;

int ex(nodeType *p) { int lbl1, lbl2;

if (!p) return 0; switch(p->type) { case typeCon: printf("\tpush\t%d ", p->con.value); break; case typeId: printf("\tpush\t%c ", p->id.i + 'a'); break; case typeOpr: switch(p->opr.oper) { case WHILE: printf("L%03d: ", lbl1 = lbl++); ex(p->opr.op[0]); printf("\tjz\tL%03d ", lbl2 = lbl++); ex(p->opr.op[1]); printf("\tjmp\tL%03d ", lbl1); printf("L%03d: ", lbl2); break; case IF: ex(p->opr.op[0]); if (p->opr.nops > 2) { /* if else */ printf("\tjz\tL%03d ", lbl1 = lbl++); ex(p->opr.op[1]); printf("\tjmp\tL%03d ", lbl2 = lbl++); printf("L%03d: ", lbl1); ex(p->opr.op[2]); printf("L%03d: ", lbl2); } else { /* if */ printf("\tjz\tL%03d ", lbl1 = lbl++); ex(p->opr.op[1]); printf("L%03d: ", lbl1); } break; case PRINT: ex(p->opr.op[0]); printf("\tprint "); break; case '=': ex(p->opr.op[1]); printf("\tpop\t%c ", p->opr.op[0]->id.i + 'a'); break; case UMINUS: ex(p->opr.op[0]); printf("\tneg "); break; default: ex(p->opr.op[0]); ex(p->opr.op[1]); switch(p->opr.oper) { case '+': printf("\tadd "); break; case '-': printf("\tsub "); break; case '*': printf("\tmul "); break; case '/': printf("\tdiv "); break; case '<': printf("\tcompLT "); break; case '>': printf("\tcompGT "); break; case GE: printf("\tcompGE "); break; case LE: printf("\tcompLE "); break; case NE: printf("\tcompNE "); break; case EQ: printf("\tcompEQ "); break; } } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!