CSC362.01, Class 4: Sample Source and Target Languages Admin: * What subject to use for your email * When is homework due? At the start of class! * Prospective visiting faculty coming in the next few weeks. Please attend their talks. * Summer research talk next Wednesday. * Putnam talk today. * Cool convo Thursday. Extra credit for attending. * Watch Sam suffer on a panel Thursday evening. * Lots of this stuff is online in the Examples directory. Overview: * PAL, A pseduo-assembly language (intermediate rep) * STUPID, A simple high-level language * Lexing STUPID * Parsing STUPID Normal computer operation: * Read next instruction from memory * Decode the instruction * Fetch some operands from memory * Executes the operation * Stores the results somewhere Suppose we need to represent intermediate code for programs (not high level, not too low level), what should we do? * A data structure in the language of your choice, rather than a textual intermediate representation * Close to assembly language, so translation to "real assembly" language is "easy" * Removes many of the complexities of real assembly language: * No restrictions on the number of registers * No restrictions on types of operands * Tree-like rather than linear (perhaps less parsing, matches translation; may be easier to find things) * Reasonable but limited set of operations PAL is a set of Java classes * Computer * Instruction (interface) + .execute() * Variable: Sources and destinations of values * Standard registers (Registers.pc, Registers.fp, Registers.bp) * Temporaries: "Infinite" user-defined registers Variable x = new Temporary(); * Memory locations (indexed by variables) * Offsets from memory locations * "Constants" The instructions * MOVE source -> destination Instruction foo = new Move(x,y); * Arithmetic: [IF]Add, [IF]Sub, [IF]Mult, [IF]Div * Jumps * Instruction Sequence * Random other stuff: Labels, NoOp, Halt, [IF]Read, [IFS]Write, Conversion Sample code