Introduction to Compiler Construction
ASU Textbook Chapter 1 Tsan-sheng Hsu
tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu
1
Introduction to Compiler Construction ASU Textbook Chapter 1 - - PowerPoint PPT Presentation
Introduction to Compiler Construction ASU Textbook Chapter 1 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is a compiler? A recognizer . Definitions: A translator . source program compiler target
tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu
1
Compiler notes #1, Tsan-sheng Hsu, IIS 2
3 + 5 - 6 * 6 ====> 3 5 + 6 6 * -
≡ the set of languages that can be recognized by this machine
Compiler notes #1, Tsan-sheng Hsu, IIS 3
Compiler notes #1, Tsan-sheng Hsu, IIS 4
following a given pattern
maybe some additional information) to the parser
Compiler notes #1, Tsan-sheng Hsu, IIS 5
Compiler notes #1, Tsan-sheng Hsu, IIS 6
the source
(Lexeme) index = * 12 ; (Token) ID ASSIGN TIMES INT SEMI-COL Every token is legal, but the sequence is erroneous.
Compiler notes #1, Tsan-sheng Hsu, IIS 7
than +, this operation must be performed as a unit, not ‘‘initial + rate’’.
Compiler notes #1, Tsan-sheng Hsu, IIS 8
= position + initial * rate 60 = position + initial * rate 60 (float) (float) (float) int−to−float()
Compiler notes #1, Tsan-sheng Hsu, IIS 9
= position + initial * rate 60 (float) (float) (float) int−to−float()
temp1 := int-to-float(60) temp2 := rate * temp1 temp3 := initial + temp2 position := temp3
Compiler notes #1, Tsan-sheng Hsu, IIS 10
temp1 := int-to-float(60) temp2 := rate * temp1 temp3 := initial + temp2 position := temp3
temp2 := rate * 60.0 position := initial + temp2
Compiler notes #1, Tsan-sheng Hsu, IIS 11
machine codes (machine dependent assembly language) directly, which is rare now .
compiler → P-code → interpreter → execution
1/3 for P-code
⊲ P-machine is an ideal general machine whose interpreter can be written
easily
⊲ divide and conquer ⊲ recent example: JAVA
Compiler notes #1, Tsan-sheng Hsu, IIS 12
temp2 := rate * 60.0 position := initial + temp2
Compiler notes #1, Tsan-sheng Hsu, IIS 13
⊲ #define MAXC 10
⊲ BASIC ⊲ C
⊲ #include <stdio.h>
Compiler notes #1, Tsan-sheng Hsu, IIS 14
forward addressed
i.e., anything that is used before its declaration.
goto error handling; · · · error handling: · · ·
Compiler notes #1, Tsan-sheng Hsu, IIS 15
Compiler notes #1, Tsan-sheng Hsu, IIS 16