CS212 Spring 2002 3/27/2002 Lecture 9: Wrap Up on FBR; Translation ------------------------------------------------------------------------------- [0] Announcements: + did anyone start Part 3? + reading: Brookshear 5.1, 5.4 ------------------------------------------------------------------------------- [1] Summary from last time: + completed example in [7] (Lecture 7) + didn't formally get to live examples ------------------------------------------------------------------------------- [2] Overview for today: + reminder of complete sam-code for functions + explanation of examples + more details on compilers and intro to syntax trees ------------------------------------------------------------------------------- [3] Generic sam-code: // PROGRAM EXECUTION: PUSHIMM 0 PUSHFBR PUSHIMM 1 POPFBR JSR main POPFBR STOP // FUNCTION EXECUTION: label: ADDSP n STOREOFF -1 ADDSP -n JUMPIND |=================================| Page 1 |=================================| // FUNCTION INVOCATION (calling function f): PUSHIMM 0 // or ADDSP 1 PUSHFBR PUSHSP PUSHIMM n+1 SUB POPFBR JSR f ADDSP -n POPFBR ------------------------------------------------------------------------------- [4] Examples + see a.sam, b.sam, c.sam from Lecture 8 ------------------------------------------------------------------------------- [5] Language Implementation + see section 5.4 in optional textbook + showing a bit more detail on what's going on + TRANSLATOR vs COMPILER? see pg 228 ------------------------------------------------------------------------------- [6] Translation + TRANSLATION: converting a program from one language to another SOURCE PROGRAM gets translated into OBJECT PROGRAM + process of translation: source lexical parser code object program analyzer generator program + note: steps are usually intertwined |=================================| Page 2 |=================================| [7] Lexical Analysis + LEXICAL ANALYSIS: recognizing which strings of symbols from the source program represent a single entity + TOKEN: lexical unit, or one of the entities recognized by the lex analyzer ------------------------------------------------------------------------------- [8] Parsing + PARSING: process of identifying the grammatical structure of the program and recognizing the role of each component + formatting: FIXED-FORMAT LANGUAGE: appearance and position matters for parser FREE-FORMAT LANGUAGE: positioning of statements is irrelevant + SYNTAX DIAGRAMS: - see pp 257-258 - graphical ways of representing the syntax rules - TERMINALS ("finished" nodes) and NONTERMINALS (need further expansion) + PARSE TREE: - see pp 259-260 - graphical ways of representing how code conforms to syntax - represents parser's understanding of program's grammar ex) x + y Expr /|\ Term + Term | | x y + SYMBOL TABLE: - storing variable info - see book for details ------------------------------------------------------------------------------- [9] Code Generation + CODE GENERATION: process of constructing the machine-language instructions to simulate the statements recognized by the parser ------------------------------------------------------------------------------- [10] Linking and Loading + terms pop up quite a bit with C/C++ programming + see pp 262-264 + LINKING: connections to needed operating system utilities + LOADING: put complete executable program into memory |=================================| Page 3 |=================================|