Compiler Construction 2016 Computer Laboratory University of Cambridge Timothy G. Griffin (tgg22@cam.ac.uk) There are many possible extensions or modifications possible for the Slang interpreters. Here are just a few ideas. They are listed from easiest to hardest. ) Write some interesting slang examples. Run the interpreters on them and try to understand the verbose output. ) Add division to the arithmetic operations. How will you handle division by zero? ) The CONTEST: improve the concrete syntax of Slang by changing the parser. Also see if you can make some of the type annotations optional. ) We have blurred the distinction between the defining language (OCaml) and the defined language (Slang) in several ways. For example, Slang integers are the ints supplied by OCaml on your machine. Now suppose that Slang only allows 16-bit integers, where overflow or underflow should raise a run-time error. Can you modify the implementation to match this? Are there additional build-in functions that you might want to add to such a language? ) Add mutual recursion to Slang1. Such as let g(x : int) : int = ... f(e) ... and f(z :int) : int = .... g(e') ... in ... end This requires careful treatment of environments! ) Implement simple optimisations : --- peephole --- inline expansion --- constant folding ) Implement simple "tuple pattern matching" in the compiler. For example, instead of writing let rev (p : int * int) : int * int = (snd p, fst p) in rev (21, 17) end allow users to write let rev (x : int, y : int) : int * int = (y, x) in rev (21, 17) end Question: Will your compiler generate identical code for these two programs? ) Implement a garbage collector for the Jargon VM. ) Implement elimination of tail-recursion in the compiler. ) Implement Objects in Slang. ) Implement exception in Slang. ) Translate Jargon.listing into Java VM code (that works).