Sometimes, the obvious program can be tempting but tedious.
I estimate that the 4200 lines of output code could have been replaced by an interpreter of at most a few dozen lines of code and a schema [note: template] of 400 lines.
Programming Pearls, Data Structures programs, p25
Separating the data from the control will pay off handsomely.
Programming Pearls, Data Structures programs, p25