First the function printtree:
Then the recursive function printtree1:void printtree(TreeNode* p) { printf("Syntax tree:\n"); printtree1(p, 0); }
void printtree1(TreeNode* p, int level) { if (p == 0) ; else if (p->type == ID) { printf("%*s", 2*level, ""); printf("%s\n", symtable[p->leaf_value].lexptr); } else if (p->type == NUM) { printf("%*s", 2*level, ""); printf("%d\n", p->leaf_value); } else if (p->type == '+') { printf("%*s", 2*level, ""); printf("+\n"); printtree1(p->args[0], level + 1); printtree1(p->args[1], level + 1); } else if (p->type == ';') { printf("%*s", 2*level, ""); printtree1(p->args[0], level + 1); printf("%*s", 2*level, ""); printf(";\n"); printtree1(p->args[1], level); } }