In the event that there are no lexical, syntactic, or semantic errors in the inputted MINI-L program, your code generator should output the generated MIL program on stdout. Refer to the specification of the MIL intermediate code representation for more details about MIL code.
There are nine types of semantic errors that should be captured by your code generator if they are present in an inputted MINI-L program.
Note that some of the above semantic errors may actually cause syntax errors during parsing. For example, if you try to declare a variable with a keyword name, then that will most likely cause a syntax error during parsing. That is fine. What is important is that some type of error message is emitted if any of the above errors are present.
If there are multiple occurrences of the above errors, your code generator should output an error message for each encountered error. You are free to choose the particular format of each error message. At a minimum, each error message should include the source code line number at which the error is encountered. If at least one error is encountered, then no intermediate code should be generated.
As an example, consider the following MINI-L program.
1. function main; 2. beginparams 3. endparams 4. beginlocals 5. n : integer; 6. r : array [10] of integer; 7. n : array [10] of integer; 8. endlocals 9. beginbody 10. read n; 11. n := z + 1; 12. n := n + r; 13. write n; 14. break; 15. endbody
In the above program, there are four semantic errors occurring at lines 7, 11, 12 and 14. The corresponding error messages that might be emitted by your code generator are shown below.
Error line 7: symbol "n" is multiply-defined. Error line 11: used variable "z" was not previously declared. Error line 12: used array variable "r" is missing a specified index. Error line 14: break statement not within a loop.
Error file custom.min can be used for testing.