Compiler Construction 2013   
Computer Laboratory 
University of Cambridge 
Timothy G. Griffin
December 2012 

Slang.1 Compiler (Slang = Simple LANGuage) 

This (very minimal) compiler targets one of two virtual machines: 
   VRM.0 : Virtual Register Machine, version 0. 
   VSM.0 : Virtual Stack Machine, version 0. 
                                     
Files : 

Library.sml	      : A few auxiliary definintions 		

AST_expr.sml	      : AST expr, a tiny subset of the "L-language" from Semantics of Programming Languages. 
AST_normal_expr.sml   : AST normal_expr, forces all sub-expression to be "named" 

AST_vrm_assembler.sml : AST for VRM.0 assembly code  
AST_vrm_bytecode.sml  : AST for VRM.0 byte code  	

AST_vsm_assembler.sml : AST for VSM.0 assembly code  	
AST_vsm_bytecode.sm   : AST for VSM.0 byte code  	

Lexer.sml	      : hand-written lexer 	
parser.sml	      : slang.1 -> expr, hand-written recursive-descent parser 
                      : (see file for a slang.1 grammar description)
type_check.sml        : expr -> expr annotation with types 

normalise.sml         : expr -> normal_expr, giving "names" to each sub-expression 		
vrm_code_gen.sml      : normal_exppr -> vrm_assembler, code generation  
vrm_assemble.sml      : vrm_assembler -> vrm_bytecode, assembly 
vrm_emit.sml          : vrm_bytecode -> output binary file

vsm_code_gen.sml      : exppr -> vsm_assembler, code generation  
vsm_assemble.sml      : vsm_assembler -> vsm_bytecode, assembly 
vsm_emit.sml          : vsm_bytecode -> output binary file

slang_compile.sml     : functions to put it all together 		
main.sml	      : command-line processing 	

Doing a "make" should produce slang1. Here are examples of using slang1:

slang1 -vrm examples/squares.slang    : compile squares.slang to VRM.0 to binary object file examples/squares.vrmo
slang1 examples/squares.slang         : same as above (VRM.0 is the default) 
slang1 -v examples/squares.slang      : same as above, but with verbose output at each stage of compilation

slang1 -vsm examples/squares.slang    : compile squares.slang to VSM.0 to binary object file examples/squares.vsmo
slang1 -v -vsm examples/squares.slang : same as above, but with verbose output at each stage of compilation

Please report bugs to tgg22@cam.ac.uk.  All bug reports must contain a 
proposed fix! 
