Compiler Construction 2014 
Computer Laboratory 
University of Cambridge 
Timothy G. Griffin (tgg22@cam.ac.uk) 

These are recommended programing tasks, listed from easiest to 
most difficult. 

0) Write, compile, and run more Slang.1 programs. 
   Try to find bugs in the compiler! 
   Most "subtle bug" report wins a Kit-Kat bar. 

1) Extend Slang.0 with the following boolean operators 
     || 
     && 

   Push this extension all the way through the "front-end" (lexing, 
   parsing, type checking). 

2) Push the extension (1) all the way through to code generation 
   for the VSM. 

   We evaluate "e1 op e2" from left-to-right.  However, 
   these operations are "short-circuited". This 
   means that  and if e1 evalutes to false and 
   op = &&, then we do not evaluate e2, and if e1 evalutes to true and 
   op = ||, then we do not evaluate e2. 

3) Push the extension (1) all the way through to code generation 
   for the VRM.0.  

4) Can you improve the code generated by the compiler by lifting 
   "constant expressions" out of loop bodies?  (For either VRM, VSM
   or both).  Part of this problem is to come up with a good definition 
   of a "constant expression". Write Slang programs to demonstrate this. 

5) Currently the code in vrm_generate_code.sml is profligate in 
   the use of temporary locations. Can you improve the VRM.0 code 
   generated by re-use of some of temporaries? 
   Best code wins a Kit-Kat bar. 

6) Try to write code generation for another platform. 
   (Perhaps JVM or CLI code from VSM assembler, or 
    x86, MIPS, or Dalvik code from VRM assembler...) 
    Best code wins a Kit-Kat bar. 

7) The compiler currently uses multiple passes over the entire 
   input program.  Why might it be a good thing to reduce the
   number of passes? How might this be accomplished? 
   a) Can you write code to translate directly from L1 to IR2? 
      Is your code easy to understand? 
      Best code wins a Kit-Kat bar. 
   b) Can you do type checking and IR2 generation directly in 
      the parser? (That is, can you eliminate the need for AST_L1
      and AST_IR1?) Is your code easy to understand? 
      Best code wins a Kit-Kat bar. 



      
