Correction: Whoops, in the originally posted lab 5 code (and the posted lab 4 sample solution) I believe the parse tree builder is adding extra terminators in parsagn when dealing with the chains of = var = var = value. The terminator is already being added in the parsestmt, it shouldn't be included in the parseasgn. To fix the parseasgn function, drop numChildren to 3 instead of 4 and remove the line assigning a leaf to children[3]. |
Whoops, no it hasn't!
What I envisioned was something like bool genCode(node* root); which would take a pointer to the root of the generated tree, after (or replacing) the call to printParseTree in main. The simplest approach might be to add the new function to parser.h/.cpp. |
int foo ; real rubberducky ; int i ; real r ; int x ; i = 10 ; r = 3.456 ; print r ; foo = x = i ; rubberducky = r ; print x ; | #include <iostream> int main() { long foo ; double rubberducky ; long i ; double r ; long x ; i = 10 ; r = 3.456 ; std::cout << r << std::endl; foo = x = i ; rubberducky = r; std::cout << x << std::endl; } |
Corrections added: the std:: and the endl were missing originally, and it should probably have been assigning foo = x = i (rather than r) for the sake of matching types. |