3. Compilers and Interpreters |
Overview
|
Note: Study Chapter 1 Sections 1.4 to 1.6 of the textbook. |
Pure Compilation and Linking
|
Compilation, Assembly, and Linking
|
Mixed Compilation and Interpretation
|
Preprocessing
|
Integrated Programming Environments (IDEs)
|
Overview of Compilation
|
Lexical Analysis
program gcd (input, output); var i, j : integer; begin read (i, j); while i <> j do if i > j then i := i - j else j := j - i; writeln (i) end.into a stream of tokens program gcd ( input , output ) ; var i , j : integer ; begin read ( i , j ) ; while i <> j do if i > j then i := i - j else j := j - i ; writeln ( i ) end . |
Note: Download a scanner application in Java |
Context-Free Grammars
<statement> -> <loop-statement> <statement> -> <if-statement> <loop-statement> -> for (<expression>; <expression>; <expression>) <statement> <expression> -> <logical-expression> ... |
Syntax Analysis
<Program> -> program <id> ( <id> <More_ids> ) ; <Block> . <Block> -> <Variables> begin <Stmt> <More_Stmts> end <More_ids> -> , <id> <More_ids> | e <Variables> -> var <id> <More_ids> : <Type> ; <More_Variables> | e <More_Variables> -> <id> <More_ids> : <Type> ; <More_Variables> | e <Stmt> -> <id> := <Exp> | read ( <id> <More_ids> ) | writeln ( <Exp> <More_Exps> ) | if <Exp> then <Stmt> else <Stmt> | while <Exp> do <Stmt> | begin <Stmt> <More_Stmts> end |
Note: An interactive parser demo demonstrates the parsing of the gcd Pascal example program into a parse tree (see also textbook pp. 20-21). |
Semantic Analysis
|
Strong Typing
|
Intermediate Code Generation
|
Target Code Generation and Optimization
|
Exercise 1: Name two languages in which a program can rewrite new pieces of itself. Hint: which languages are said to be suitable for symbolic and logic processing? |