HOME EXAM 2 INF3110/4110 AUTUMN 2003 - ADDENDUM - Questions and answers ---------------------------------------------------------------------- Here are some changes and hints for home exam 2. [Last changed: 20:35 11/11/2003] ------------ CHANGES ------------------------------------------------- A few minor changes have been done to the code which was handed out in the file 'compiler.sml'. The changes *only * concern the functions under ProcBindings and VarBindings together with the surrounding comments. Most of it are details (the comments are now correct and the error messages are a bit more precise), but a new function is added removeVarBindings(n), which removes the n last variable bindings performed. It is therefore recommended to download a new version or change this part of the code, if you should need this. ------------ SCOPE RULES --------------------------------------------- The scope for of a procedure declaration is from the place of declaration until the en of the program. That is, procedures can only call previously declared procedures, but not the other way around. The scope of local variables is from the place of declaration until the first occurrence of end. Declaration of local variables masks declaration of global variables in the usual way. ------------ ABOUT THE SUBMISSION ------------------------------------ In addition to submitting exercise 1 electronically, as an executable(!) SML-file, you should in the paper version add which changes you have done with respect to the code handed out. Do not include all the code that you are left with in the end, but only changes and additions. This is to do the evaluation simpler. Generally, you are free to make changes, also to the code handed out, presupposed that you justify and comment in a good and understandable way. ------------ QUESTION 1 ---------------------------------------------- When I compile the following code, I receive an error message. Why? 1 var a; 2 begin 3 ?a; 4 !a; 5 end ------------ ANSWER 1 ------------------------------------------------ Line 4 contains a semicolon too much! A must end with a , which does not end with a semicolon. Think of a semicolon as something that tells the parser/compiler that there is another or coming. Example: - compile(scan "var a; begin ?a; !a; end") handle x => errorhandler x; ERROR when compiling: STATEMENT val it = [End] : token list This message tells us that the error is in the STATEMENT function and that the argument list was [End]. STATEMENT was called because there was a semicolon after the last , so the program expected a new , but that cannot have 'End' as its first token. ------------ QUESTION 2 ---------------------------------------------- Is it intended that mutual recursion should be possible in L2? ------------ ANSWER 2 ------------------------------------------------ No, that is not the intention. Unfortunately, there was nothing about scope rules in the exam text, so that is now added here. (Se under SCOPE RULES above.) Direct recursion, on the other hand, is allowed.