Professional Documents
Culture Documents
l2 Scanner
l2 Scanner
Compiler Construction
Phn tch t vng
Nguyen Ngoc Duong
Nguyen Huu Duc
Faculty of information technology
Hanoi university of technology
Experiment in compiler
construction - Scanner design
Scanner l g?
Experiment in compiler
construction - Scanner design
Scanner l g?
Experiment in compiler
construction - Scanner design
Nhim v ca mt scanner
nh danh (identifier)
t kha (keyword)
s (number)
Hng k t/xu k t
special character
...
Experiment in compiler
construction - Scanner design
Nhim v ca mt scanner
Experiment in compiler
construction - Scanner design
Bng ch ci ca KPL
Experiment in compiler
construction - Scanner design
T kha
PROGRAM, CONST, TYPE, VAR, PROCEDURE,
FUNCTION, BEGIN, END, ARRAY, OF, INTEGER,
CHAR, CALL, IF, ELSE, WHILE, DO, FOR, TO
Ton t
:= (assign), + (addition), - (subtraction), * (multiplication), /
(division), = (comparison of equality), != (comparison of
difference), > (comparison of greaterness), < (comparison
of lessness), >= (comparison of greaterness or equality),
<= (comparison of lessness or equality)
Experiment in compiler
construction - Scanner design
KPLs tokens
K hiu c bit
; (semicolon), . (period), : (colon), , (comma), (
(left parenthesis), ) (right parenthesis),
(singlequote)
V
(. v .) nh du ch mc ca mng
(* v *) nh du im bt u v kt thc
ca ch thch
Ngoi ra
nh danh, s, hng k t
Experiment in compiler
construction - Scanner design
Experiment in compiler
construction - Scanner design
S0
S1
S1
S1
S0
>
S0
S4
S5
S0
S0
S2
S2
10
Ni dung
Makefile
Project
scanner.c
Tp chnh
reader.h, reader.c
c m ngun
charcode.h,
charcode.c
Phn loi k t
token.h, token.c
error.h, error.c
Thng bo li
Experiment in compiler
construction - Scanner design
11
Experiment in compiler
construction - Scanner design
12
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
Khong trng
Ch ci
Ch s
+
-
*
/
<
<
!
=
,
.
:
;
\
(
)
K t ngoi bng ch ci
Experiment in compiler
construction - Scanner design
13
Experiment in compiler
construction - Scanner design
14
Experiment in compiler
construction - Scanner design
15
Experiment in compiler
construction - Scanner design
16
Experiment in compiler
construction - Scanner design
17
}
}
Experiment in compiler
construction - Scanner design
18
Nhim v
void skipBlank();
void skipComment();
Token* readIdentKeyword(void);
Token* readNumber(void);
Token* readConstChar(void);
Token* getToken(void);
Experiment in compiler
construction - Scanner design
19