This project finishes the front-end of your simplified compiler by translating the source code (LOLcode) into intermediate code (LMAOcode). Your compiler must have a function named "generate_LMAOcode_from_LOLcode" that takes a single argument, a multiline string of LOLcode. The multiline string returned by this function must be a legal LMAOcode, as described below.
We recommend that you implement this project in three stages:
Note that logical operators ('BOTH', 'ALL', 'EITHER', 'ANY') normally short-circuit such that if their result is fixed based on the first term of the operator, the second term does not execute (e.g. "a = (b=3) || (b=4)" would result in a=b=3.) While proper short-circuiting is not required (nor tested) in Project 3, it will be part of Project 4.
Not all of the LOLcode that was parsed in Project 2 will be in Project 3. For instance, none of the parts of LOLcode that deal with types other than NUMBR will be in Project 3. Also absent are the mathematical operators BIGGR and SMALLR.
Your compiler must still detect errors from previous projects. And in the event of an error, your compiler should raise the an exception.
The VISIBLE command (in LOLcode) should output all values on a single line consecutively, and then place a newline at the end of the line (unless there is a exclamation point). For example, this code:
HAI 1.450 I HAS A a AN ITZ A NUMBR AN ITZ 2 VISIBLE 1 a VISIBLE 13 AN PRODUKT OF a AN 5 KTHXBYE
should produce LMAOcode that that looks something like:
VAL_COPY 2 s6 VAL_COPY s6 s0 VAL_COPY 1 s7 OUT_NUM s7 OUT_NUM s0 OUT_CHAR '\n' VAL_COPY 13 s8 OUT_NUM s8 VAL_COPY 5 s9 MULT s0 s9 s10 OUT_NUM s10 OUT_CHAR '\n'
The specific intermediate code will not be graded as long as it produces the correct output when executed with "interpreter.py". In the case of the code above, the output should be:
LMAOcode syntax is detailed in the Target Language Specification, but at this point you don't need to pay attention to any of the instructions after NOP.
The LMAOcode Interpreter (made available as "interpreter.py" in the starter code) will allow you to directly run LMAOcode so that you can test them. "interpreter.py" can be used via the command line and reads from stdin and writes the executed output to stdout. We recommend that you first create an input file with a .lmao extension. For example, if you wanted to compile and test the source program "mytest.lol" in your Project3/ directory, you would first output the resulting LMAOcode your compiler generates to a file, "mytest.lmao", then run:
$ python3 interpreter.py <mytest.lmao >mytest.out
Note: Your generated intermediate code does not have to match the sample code provided (though any large differences are probably a sign of a problem), but your final output when you run the intermediate code MUST match the expected output.
When you hand in your program, you must include in a folder called Project3: