CS 15-212: Fundamental Structures of Computer Science II |
Lexical analysis converts ("transduces") the input character stream into a stream of tokens. The syntactic parser then converts the token stream into a stream of expressions, or "abstract syntax" trees. The next job of the interpreter is to carry out type checking to make sure that each expression is well-typed. A precise specification of the typing rules can be given in terms of a deductive system, expressed in terms of a set of inference rules. The type checker traverses the syntactic parse tree (typically in postorder), building up type environments and applying the inference rules to assign a type to each node in the tree. We illustrate the basic idea on our fragment of ML consisting of arithmetic expressions together with Booleans and conditional statements.