Note: the repo has been pushed (9am Feb. 16th) |
Vurbossity revisions:
One more tweak on top of the lab3 version: we'll add keywords "true" and "false" as the boolean literals.
// parse the token sequence and rewrite as C, // writing the results to standard output, // with any error messages directed to standard error void parse(token tokens[], int size); |
Original vurbossity | Resulting C++ |
gdef x integer COM some global? pdef printStuff left real r right begin write "I was given" write r end main begin vdef y real set x 33 set y left add x 1.2 right call printStuff left y right end | #include <iostream> #include <string> using namespace std; long x; void printStuff(double r) { cout << "I was given" << endl; cout << r << endl; } int main() { double y; x = 33; y = (x + 1.2); printStuff(y); } |
#include <iostream> #include <string> using namespace std;Translation of the if loop The 'if' portion of the if loop can be directly replaced by a while loop to give the desired functionality. Note the 'else' portion in vurbossity is always executed once following the completion of the loop portion, but does need to be in a block of its own to ensure the scoping works out the same in the translation as the original, i.e.
while (condition from the if) { ... the statements from the if body ... } { ... the statements from the else body ... }Function return values Since vurbossity has no return types/statements the return type in the C++ functions will always be "void". Input/output Assume "cin >> SomeVarName;" and "cout << ExpressionOutput << endl;" are the desired I/O equivalents of read and write. Only valid C++ statements should be written to stdout If your program is generating any error messages, debugging messages, or informational messages they should all be going to stderr (cerr) not stdout (cout). This allows the user to separate any valid generated code from all other output if they so desire.