\contentsline {chapter}{\numberline {1}Introduction}{4} \contentsline {section}{\numberline {1.1}Guide to the Source Code}{4} \contentsline {paragraph}{Abstract Syntax}{4} \contentsline {paragraph}{Analysis}{4} \contentsline {paragraph}{Translation}{6} \contentsline {paragraph}{Code Generation}{6} \contentsline {paragraph}{Tiger Runtime System}{6} \contentsline {paragraph}{Other Modules}{6} \contentsline {chapter}{\numberline {2}Abstract Syntax of Tiger}{7} \contentsline {section}{\numberline {2.1}Symbols}{7} \contentsline {subsection}{\numberline {2.1.1}Basic Symbols}{7} \contentsline {subsection}{\numberline {2.1.2}Symbol Tables}{8} \contentsline {section}{\numberline {2.2}Abstract Syntax}{10} \contentsline {subsection}{\numberline {2.2.1}Ast Types}{10} \contentsline {subsection}{\numberline {2.2.2}Abstract Syntax Tree Printer}{11} \contentsline {chapter}{\numberline {3}Analysis}{16} \contentsline {section}{\numberline {3.1}Environments}{16} \contentsline {subsection}{\numberline {3.1.1}Interface to the Environment}{17} \contentsline {subsection}{\numberline {3.1.2}Implementation of Environments}{18} \contentsline {section}{\numberline {3.2}Semantic Analysis}{20} \contentsline {subsection}{\numberline {3.2.1}Type System}{21} \contentsline {subsection}{\numberline {3.2.2}The {\normalfont \tt {}translate\relax } Entry Point}{23} \contentsline {subsection}{\numberline {3.2.3}Declarations}{24} \contentsline {paragraph}{Function Declarations}{24} \contentsline {paragraph}{Variable Declarations}{25} \contentsline {paragraph}{Type Declarations}{25} \contentsline {paragraph}{Exception Declarations}{26} \contentsline {subsection}{\numberline {3.2.4}Variables}{26} \contentsline {paragraph}{Simple Variables}{26} \contentsline {paragraph}{Field Variables}{27} \contentsline {paragraph}{Subscript Variables}{27} \contentsline {subsection}{\numberline {3.2.5}Expressions}{27} \contentsline {paragraph}{Simple Expressions}{28} \contentsline {paragraph}{Records}{28} \contentsline {paragraph}{Arrays}{29} \contentsline {paragraph}{Assignment}{29} \contentsline {paragraph}{Operator Expressions}{29} \contentsline {paragraph}{Function Calls}{30} \contentsline {paragraph}{Conditionals}{30} \contentsline {paragraph}{Loops}{31} \contentsline {paragraph}{Sequences}{32} \contentsline {paragraph}{Let Expressions}{32} \contentsline {paragraph}{Exceptions}{32} \contentsline {chapter}{\numberline {4}Translation}{34} \contentsline {section}{\numberline {4.1}Intermediate Representation}{34} \contentsline {subsection}{\numberline {4.1.1}Interface to the IR}{35} \contentsline {subsection}{\numberline {4.1.2}Implementation of IR Utilities}{36} \contentsline {section}{\numberline {4.2}Translation to Intermediate Representation}{39} \contentsline {subsection}{\numberline {4.2.1}Translation Implementation}{39} \contentsline {paragraph}{Utilities}{40} \contentsline {paragraph}{Literals}{41} \contentsline {paragraph}{Function Calls}{41} \contentsline {paragraph}{Variables}{42} \contentsline {paragraph}{Operator Expressions}{43} \contentsline {paragraph}{Conditionals}{43} \contentsline {paragraph}{Loops}{44} \contentsline {paragraph}{Records and Arrays}{44} \contentsline {paragraph}{Sequences}{45} \contentsline {paragraph}{Functions}{46} \contentsline {paragraph}{Exceptions}{46} \contentsline {chapter}{\numberline {5}Code Generation}{48} \contentsline {section}{\numberline {5.1}Stack Frames}{48} \contentsline {subsection}{\numberline {5.1.1}Stack Frame Implementation}{49} \contentsline {section}{\numberline {5.2}Code Generation}{52} \contentsline {chapter}{\numberline {6}Tiger Runtime System}{55} \contentsline {section}{\numberline {6.1}Allocation and Garbage Collection}{55} \contentsline {subsection}{\numberline {6.1.1}Memory Allocator}{55} \contentsline {subsection}{\numberline {6.1.2}Garbage Collector Implementation}{56} \contentsline {subsection}{\numberline {6.1.3}Garbage Collector Main Loop}{58} \contentsline {section}{\numberline {6.2}Tiger Standard Library}{59} \contentsline {subsection}{\numberline {6.2.1}Standard Library Implementation}{60} \contentsline {paragraph}{Library Functions}{61} \contentsline {paragraph}{Exceptions}{64} \contentsline {section}{\numberline {6.3}Runtime Startup Code}{65} \contentsline {subsection}{\numberline {6.3.1}Interpreter Startup}{65} \contentsline {chapter}{\numberline {A}Driver and Utilities}{70} \contentsline {section}{\numberline {A.1}Compiler Driver}{70} \contentsline {paragraph}{Standard Basis}{70} \contentsline {paragraph}{Compiler Driver}{71} \contentsline {section}{\numberline {A.2}Error Handling}{72} \contentsline {subsection}{\numberline {A.2.1}Error Implementation}{73} \contentsline {section}{\numberline {A.3}Command Line Options}{74} \contentsline {subsection}{\numberline {A.3.1}Options}{74} \contentsline {subsection}{\numberline {A.3.2}Option Implementation}{75} \contentsline {chapter}{\numberline {B}Scanner and Parser}{76} \contentsline {section}{\numberline {B.1}Scanner}{76} \contentsline {section}{\numberline {B.2}Parser}{79} \contentsline {chapter}{\numberline {C}Linearize Algorithm}{85} \contentsline {section}{\numberline {C.1}Canonical Trees}{85}