Tải bản đầy đủ (.doc) (55 trang)

Môn chương trình dịch Viết trình biên dịch để dịch 1 đoạn chương trình

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (239.63 KB, 55 trang )

LỜI NÓI ĐẦU
Chương trình dịch là một môn học của ngành khoa học máy tính. Cùng với
sự phát triển của các chuyên ngành : Lý thuyết ngôn ngữ hình thức & Ôtômat và
các chuyên ngành khác, lý thuyết thiết kế trình biên dịch ngày một hoàn thiện hơn.
Ngày nay lý thuyết trình biên dịch đã được ứng dụng không những trong
việc thiết kế trình biên dịch cho ngôn ngữ lập trình mà còn trong lĩnh vực trí tuệ
nhân tạo - hiểu ngôn ngữ tự nhiên, dịch máy ….
Đồ án môn học : CHƯƠNG TRÌNH DỊCH là dịp tốt để cho việc học tập
của sinh viên chuyên ngành tin học nắm vững lý thuyết và cách thiết kế trình biên
dịch được tốt.
Vì thế chúng em thực hiện đồ án, với đề tài 14:
Viết trình biên dịch để dịch 1 đoạn chương trình gồm các phát biểu sau:
- Phát biểu ghép, if trong C
- Các phát biểu kết thúc bằng dấu ;
- Các biểu thức trong các phát biểu là các biểu thức số học và logic, gồm các
phép toán +, -, *, /, (?:), !, &&, || và các phép toán so sánh. Toán hạng gồm các
danh hiệu, hằng số thực và nguyên (kể cả biểu thức) và kiểu array. Độ ưu tiên
các phép toán tương tự C.
- Thực hiện chuyển đổi kiểu từ nguyên sang thực khi cần thiết.
Em xin chân thành cảm ơn sự hướng dẫn tận tình của cô Phan Thị Thu
Hồng và sự đóng góp ý kiến của các bạn, nhằm giúp đỡ cho đồ án hoàn thành đúng
yêu cầu. Mặc dù đã cố gắng tham khảo nhiều tài liệu nhưng quá trình thực hiện
khó tránh khỏi những thiếu sót và hạn chế. Rất mong nhận được những ý kiến nhận
xét, đóng góp của thầy cô và các bạn.
Nhóm sinh viên thực hiện
Nguyễn Thị Diệp
Phạm Thị Định
Nguyễn Thị Gấm
Nguyễn Thị Nụ
Lớp : THC 52
MỤC LỤC


L I NÓI UỜ ĐẦ 1
A. Những nội dung liên quan tới yêu cầu của đề bài
I. Phát biểu ghép và if trong C
1. Phát biểu ghép
{
Lệnh 1;
Lệnh 2;

}
2. Phát biểu if
* Dạng 1:
If (điều kiện)
lệnh S;
- Lệnh S có thể gồm nhiều lệnh (khối lệnh).
* Dạng 2:
If (điều kiện)
lệnh S1;
else
lệnh S2;
- Lệnh S1, S2 có thể là một khối lệnh .
II. Các phát biểu kết thúc bằng dấu ;
Đa số các câu lệnh kết thúc bằng dấu ; dùng để ngăn cách các câu lệnh. Ví
dụ như: Phát biểu gán (a=0, gán 0 cho biến a), khai báo biến, hằng (float a, khai
báo biến a có kiểu số thực)…
III. Các phép toán
1. Các phép toán số học
- Phép cộng: +
- Phép trừ: -
- Phép nhân: *
- Phép chia: /

2. Các phép toán logic
- Phép và: && (AND)
- Phép hoặc: || (OR)
- Phép phủ định: ! (NOT)
3. Các phép toán so sánh
- Phép nhỏ hơn: <
- Phép nhỏ hơn hoặc bằng: <=
- Phép lớn hơn: >
- Phép lớn hơn hoặc bằng: >=
- Phép bằng: ==
- Phép khác (không bằng): !=
4. Toán tử chọn theo điều kiện
(Điều kiện) ? biểu thức 1 : biểu thức 2
- Điều kiện đúng thì biểu thức nhận giá trị biểu thức 1, các trường hợp còn lại bằng
biểu thức 2.
5. Các toán hạng
- Danh hiệu: là tên được dùng để đặt cho các biến, hằng, hàm, kiểu… Tên được đặt
theo quy định: gồm các chữ cái, chữ viết, dấu gạch chân, không bắt đầu bằng chữ
số, không trùng với khóa.
- Các hằng số thực và nguyên:
+ Hằng số nguyên: 9, -7
+ Hằng số thực: 1.523, -0.33E5
- Kiểu array:
Kiểu tên_mảng [kích_thước_chiều1][kích_thước_chiều2]…[kích_thước_chiều_n]
6. Độ ưu tiên của phép toán
- Có 15 mức ưu tiên, thường thì các toán tử 1 ngôi có độ ưu tiên cao hơn 2 ngôi.
Thứ tự ưu tiên được chỉ rõ hơn trong dấu ().
7. Chuyển đổi kiểu nguyên sang kiểu số thực
int i;
- Chuyển kiểu: (float) i;

B. Phân tích từ vựng
I. Bảng token
Token Lexeme Pattern
if If if
else Else else
void Void Void
main Main main
type int, float int, float
asg = =
id Ab, a123, a_bc Các danh hiệu được đặt: bắt đầu chữ cái
hoặc dấu gạch chân theo sau là số hoặc
chữ, dấu gạch chân và không trùng với
khóa
num 12, -2 Các số nguyên
real 0.35, -3E2 Các số thực
begin { {
end } }
relop1 ==, != Phép so sánh: EQ, NE
relop2 <, <=, >, >= Các phép toán so sánh: GT, GE, LT, LE
left ( (
right ) )
not ! Phép phủ định
and && Phép và
or || Phép hoặc
semi ; ;
coma , ,
colon : :
open [ [
close ] ]
aws ? ?

op1 +, - Các phép toán số học
op2 *, /
II. Sơ đồ dịch
1. Định nghĩa các token
a. id
letter → A | B | … | Z | a | b | … | z
digit → 0 | 1 | 2 | … | 9
id → (letter | ‘_’) (letter | digit | ‘_’)
*
b. num
digit → 0 | 1 | 2 | … | 9
num → digit (digit)*
c. real
real → digit(digit)* (.digit(digit)* |
ε
) ((( E | e )( + | - |
ε
) digit(digit)*)) |
ε
)
d. Các phép toán so sánh
relop1 → == | !=
relop2 → < | <= | > | >=
e. Các phép toán logic
not → !
and → &&
or → ||
f. Các phép toán số học
op1 → + | -
op2 → * | /

g. type
type → int | float
h. Các token khác
if → if
else → else
void → void
main → main
asg → =
begin → {
end → }
left → (
right → )
semi → ;
coma → ,
colon → :
open → [
close → ]
aws → ?
2. Sơ đồ dịch
* Sơ đồ dịch nhận dạng token relop:
* Sơ đồ dịch nhận dạng token relop:
Start
0
2
1
3
=
<
* id
* id

* num

* real
* real

other
*
5
=
4
=
!
=
76
>
8
9
=
1
0
other
*
3
Start
1
letter | digit | ‘_’
Start
1
3
digit

digit
2
letter | ‘_’
*
other
2
other
*
4
10
‘.’
other
digit
digit

+‘+’|’-

8 9
digit
5 7
digit
digit
other
6
*
start
digit
2
digit
1

3
other
‘E’|‘e’
‘E’|‘e’
*
Chú ý: Một số trạng thái có thêm một dấu * để chỉ ra đồ thị chuyển đã xử lý quá
một ký tự của phần khác. Ký hiệu này được lưu và trả lại khi đoán nhận phần khác.
Start
1
5
4
3
2
+
/
*
-
*
C. Phân tích cú pháp
I. Định nghĩa văn phạm tổng quát
S → void main left right block
block → begin assign_list end
assign_list → assign assign_list |
ε
assign → dec_var | begin assign_list end | pbif
7
8
6
]
)

(
[
9
10
!
1
8
19
&
&
2
0
15
|
|
13
14
12
17
21
11
{
}
;
:
?
,
16
=
dec_var → type id id1 semi dec_var

id1 → coma id1 | open num close id1 |
ε
pbif → if expr pbif | if expr pbif else pbif | begin assign_list end |
id asg expr semi
expr → exp aws expr colon expr
exp → exp or exp1 | exp1
exp1 → exp1 and term | term
term → term relop1 term1 | term1
term1 → term1 relop2 term2 | term2
term2 → term2 op1 term3| term3
term3 → term3 op2 factor | factor
factor → not factor1
factor1 → left exp right| id | num | real
* Văn phạm tăng cường
S’ → S
(1) S → dec_var void main left right block
(2) dec_var → type id id1 semi dec_var
(4) id1 → coma id id1
(5) id1 → open num close id1
(6) id1 →
ε
(7) block → begin assign_list end
(8) assign_list → assign assign_list
(9) assign_list →
ε
(10) assign → dec_var
(11) assign → if expr assign
(12) assign → if expr assign else assign
(13) assign → begin assign_list end
(14) assign → id asg expr semi

(15) expr → exp aws expr colon expr
(16) expr → exp
(17) exp → exp or exp1
(18) exp → exp1
(19) exp1 → exp1 and term
(20) exp1 → term
(21) term → term relop1 term1
(22) term → term1
(23) term1 → term1 relop2 term2
(24) term1 → term2
(25) term2 → term2 op1 term3
(26) term2 → term3
(27) term3 → term3 op2 factor
(28) term3 → factor
(29) factor → not factor1
(30) factor1 → left expr right
(31) factor1 → id
(32) factor1 → num
(33) factor1 → real
(34) factor1 → left type right id
II. Các ký hiệu kết thúc và chưa kết thúc
1. Các ký hiệu kết thúc
1. void
2. main
3. left
4. right
5. type
6. semi
7. id
8. coma

9. open
10. close
11. num
12. begin
13. end
14. asg
15. aws
16. colon
17. not
18. and
19. or
20. relop1
21. relop2
22. op1
23. op2
24. if
25. else
26. real
2. Các ký hiệu không kết thúc
1. S
2. dec_var
3. block
4. id1
5. assign_list
6. assign
7. expr
8. exp
9. exp1
10. term
11. term1

12. term2
13. term3
14. factor
15. factor1
III. Xây dựng bảng phân tích LR
Closure({S’→ .S, $})
I
0
: S’→ .S, $
S → .dec_var void main left right block, $
dec_var → .type id id1 semi dec_var, void
dec_var → ., void

goto(I
0
, S)
I
1
: S’→S., $

goto(I
0
, dec_var)
I
2
: S → dec_var. void main left right block, $

goto(I
0,
type)

I
3
: dec_var → type. id id1 semi dec_var, void

goto(I
2
, void)
I
4
: S → dec_var void. main left right block, $

goto(I
3
, id)
I
5
: dec_var → type id. id1 semi dec_var, void
id1 → .coma id id1, semi
id1 → .open num close id1, semi
id1 → ., semi

goto(I
4
, main)
I
6
: S → dec_var void main. left right block, $

goto(I
5

, id1)
I
7
: dec_var → type id id1. semi dec_var, void

goto(I
5,
coma)
I
8
: id1 → coma. id id1, semi

goto(I
5
, open)
I
9
: id1 → open. num close id1, semi

goto(I
6
, left)
I
10
: S → dec_var void main left. right block, $

goto(I
7
, semi)
I

11
: dec_var → type id id1 semi. dec_var, void
dec_var → .type id id1 semi dec_var, void

goto(I
8
, id)
I
12
: id1 → coma id. id1, semi
id1 → .coma id id1, semi
id1 → .open num close id1, semi
id1 → ., semi

goto(I
9
, num)
I
13
: id1 → open num. close id1, semi

goto(I
10
, right)
I
14
: S → dec_var void main left right. block, $
block → .begin assign_list end, $

goto(I

11
, dec_var)
I
15
: dec_var → type id id1 semi dec_var., void
goto(I
11
, type) ≡ I
3

goto(I
12
, id1)
I
16
: id1 → coma id id1., semi
goto(I
12
, coma) ≡ I
8
, goto(I
12
, open) ≡ I
9

goto(I
13
, close)
I
17

: id1 → open num close. id1, semi
id1 → .coma id id1, semi
id1 → .open num close id1, semi
id1 → ., semi

goto(I
14
, block)
I
18
: S → dec_var void main left right block., $

goto(I
14
, begin)
I
19
: block → begin. assign_list end, $
assign_list → .assign assign_list, end
assign_list → ., end
assign → .dec_var, type | begin | id | if |
ε

dec_var → .type id id1 semi dec_var, type | begin | id | if |
ε
assign → .if expr assign, type | begin | id | if |
ε
assign → .if expr assign else assign, type | begin | id | if |
ε
assign → .begin assign_list end, type | begin | id | if |

ε
assign → .id asg expr semi, type | begin | id | if |
ε

goto(I
17
, id)
I
20
: id1 → open num close id1., semi
goto(I
17
, coma) ≡ I
8
, goto(I
17
, open) ≡ I
9

goto(I
19
, assign_list)
I
21
: block → begin assign_list. end, $

goto(I
19
, assign)
I

22
: assign_list → assign. assign_list, end
assign_list → .assign assign_list, end
assign_list → ., end
assign → .dec_var, type | begin | id | if |
ε

dec_var → .type id id1 semi dec_var, type | begin | id | if |
ε
assign → .if expr assign, type | begin | id | if |
ε
assign → .if expr assign else assign, type | begin | id | if |
ε
assign → .begin assign_list end, type | begin | id | if |
ε
assign → .id asg expr semi, type | begin | id | if |
ε

goto(I
19
, dec_var)
I
23
: assign → dec_var., type | begin | id | if |
ε

goto(I
19
, type)
I

24
: dec_var → type. id id1 semi dec_var, type | begin | id | if |
ε

goto(I
19
, if)
I
25
: assign → if. expr assign, type | begin | id | if |
ε
assign → if. expr assign else assign, type | begin | id | if |
ε
expr → .exp aws expr colon expr, type | begin | id | if |
ε
expr → .exp, type | begin | id | if |
ε
exp → .exp or exp1, type | begin | id | if | aws | or |
ε
exp → .exp1, type | begin | id | if | aws | or |
ε
exp1 → .exp1 and term, type | begin | id | if | aws | or | and |
ε
exp1 → .term, type | begin | id | if | aws | or | and |
ε
term → .term relop1 term1, type | begin | id | if | aws | or | and | relop1 |
ε

term → .term1, type | begin | id | if | aws | or | and | relop1 |
ε

term1 → .term1 relop2 term2, type| begin| id| if| aws| or| and| relop1|relop2|
ε
term1 → .term2, type| begin| id| if| aws| or| and| relop1|relop2|
ε
term2 →.term2 op1 term3, type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε
term2 → .term3, type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε
term3→.term3 op2 factor,type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
term3 → .factor, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor → .not factor1, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε

goto(I
19
, begin)
I
26
: assign → begin. assign_list end, type | begin | id | if |
ε
assign_list → .assign assign_list, end
assign_list → ., end
assign → .dec_var, type | begin | id | if |
ε

dec_var → .type id id1 semi dec_var, type | begin | id | if |
ε
assign → .if expr assign, type | begin | id | if |

ε
assign → .if expr assign else assign, type | begin | id | if |
ε
assign → .begin assign_list end, type | begin | id | if |
ε
assign → .id asg expr semi, type | begin | id | if |
ε

goto(I
19
, id)
I
27
: assign → id. asg expr semi, type | begin | id | if |
ε

goto(I
21
, end)
I
28
: block → begin assign_list end., $

goto(I
22
, assign_list)
I
29
: assign_list → assign assign_list., end
goto(I

22
, assign) ≡ I
22
, goto(I
22
, dec_var) ≡ I
23
, goto(I
22
, type) ≡ I
24
goto(I
22
, if) ≡ I
25
, goto(I
22
, begin) ≡ I
26
, goto(I
22
, id) ≡ I
27
goto(I
24
, id)
I
30
: dec_var → type id. id1 semi dec_var, type | begin | id | if |
ε

id1 → .coma id id1, semi
id1 → .open num close id1, semi
id1 → ., semi

goto(I
25
, expr)
I
31
: assign → if expr. assign, type | begin | id | if |
ε
assign → if expr. assign else assign, type | begin | id | if |
ε
assign → .dec_var, type | begin | id | if |
ε
| else
dec_var → .type id id1 semi dec_var, type | begin | id | if |
ε
| else
assign → .if expr assign, type | begin | id | if |
ε
| else
assign → .if expr assign else assign, type | begin | id | if |
ε
| else
assign → .begin assign_list end, type | begin | id | if |
ε
| esle
assign → .id asg expr semi, type | begin | id | if |
ε

| else

goto(I
25
, exp)
I
32
: expr → exp. aws expr colon expr, type | begin | id | if |
ε
expr → exp., type | begin | id | if |
ε
exp → exp. or exp1, type | begin | id | if | aws | or |
ε

goto(I
25
, exp1)
I
33
: exp → exp1., type | begin | id | if | aws | or |
ε
exp1 → exp1. and term, type | begin | id | if | aws | or | and |
ε

goto(I
25
, term)
I
34
: exp1 → term., type | begin | id | if | aws | or | and |

ε
term → term. relop1 term1, type | begin | id | if | aws | or | and | relop1 |
ε


goto(I
25
, term1)
I
35
: term → term1., type | begin | id | if | aws | or | and | relop1 |
ε
term1 → term1. relop2 term2, type| begin| id| if| aws| or| and| relop1|relop2|
ε

goto(I
25
, term2)
I
36
: term1 → term2., type| begin| id| if| aws| or| and| relop1|relop2|
ε
term2 →term2. op1 term3, type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε

goto(I
25
, term3)
I
37

: term2 → term3., type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε
term3→term3. op2 factor,type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε

goto(I
25
, factor)
I
38
: term3 → factor., type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε

goto(I
25
, not)
I
39
: factor → not. factor1, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor1 → .left expr right,type|begin|id|if|aws|or|and|
relop1|relop2|op1|op2|
ε
factor1 → .id, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor1 → .num, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor1 → .real, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor1 → .left type right id, type|begin|id|if|aws|or|and|

relop1|relop2|op1|op2|
ε

goto(I
26
, assign_list)
I
40
: assign → begin assign_list. end, type | begin | id | if |
ε
goto(I
26
, assign) ≡ I
22
, goto(I
26
, dec_var) ≡ I
23
, goto(I
26
, type) ≡ I
24
goto(I
26
, if) ≡ I
25
, goto(I
26
, begin) ≡ I
26

, goto(I
26
, id) ≡ I
27

goto(I
27
, asg)
I
41
: assign → id asg. expr semi, type | begin | id | if |
ε
expr → .exp aws expr colon expr, semi
expr → .exp, semi
exp → .exp or exp1, semi | aws | or
exp → .exp1, semi | aws | or
exp1 → .exp1 and term, semi | aws | or | and
exp1 → .term, semi | aws | or | and
term → .term relop1 term1, semi | aws | or | and | relop1
term → .term1, semi | aws | or | and | relop1
term1 → .term1 relop2 term2, semi | aws | or | and | relop1| relop2
term1 → .term2, semi | aws | or | and | relop1| relop2
term2 →.term2 op1 term3, semi | aws | or | and | relop1| relop2 | op1
term2 → .term3, semi | aws | or | and | relop1| relop2 | op1
term3→.term3 op2 factor, semi | aws | or | and | relop1| relop2 |op1|op2
term3 → .factor, semi | aws | or | and | relop1| relop2 |op1|op2
factor → .not factor1, semi | aws | or | and | relop1| relop2 |op1|op2

goto(I
30

, id1)
I
42
: dec_var → type id id1. semi dec_var, type | begin | id | if |
ε
Goto(I
30
, coma) ≡ I
8
, goto(I
30
, open) ≡ I
9
Goto(I
31
, assign)
I
43
: assign → if expr assign., type | begin | id | if |
ε
assign → if expr assign. else assign, type | begin | id | if |
ε

Goto(I
31
, dec_var)
I
44
: assign → dec_var., type | begin | id | if |
ε

| else

Goto(I
31
, type)
I
45
: dec_var → type. id id1 semi dec_var, type | begin | id | if |
ε
| else

goto(I
31
, if)
I
46
: assign → if. expr assign, type | begin | id | if |
ε
| else
assign → if. expr assign else assign, type | begin | id | if |
ε
| else
expr → .exp aws expr colon expr, type | begin | id | if |
ε

expr → .exp, type | begin | id | if |
ε

exp → .exp or exp1, type | begin | id | if | aws | or |
ε

exp → .exp1, type | begin | id | if | aws | or |
ε
exp1 → .exp1 and term, type | begin | id | if | aws | or | and |
ε

exp1 → .term, type | begin | id | if | aws | or | and |
ε

term → .term relop1 term1, type | begin | id | if | aws | or | and | relop1 |
ε

term → .term1, type | begin | id | if | aws | or | and | relop1 |
ε
term1 → .term1 relop2 term2, type| begin| id| if| aws| or| and|
relop1|relop2|
ε

term1 → .term2, type| begin| id| if| aws| or| and| relop1|relop2|
ε
term2 →.term2 op1 term3, type|begin|id|if|aws|or|and|
relop1|relop2|op1|
ε
term2 → .term3, type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε
term3→.term3 op2 factor,type|begin|id|if|aws|or|and|
relop1|relop2|op1|op2|
ε
term3 → .factor, type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor → .not factor1,type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|

ε
goto(I
31
, begin)
I
47
: assign → begin. assign_list end, type | begin | id | if |
ε
| else
assign_list → .assign assign_list, end
assign_list → ., end
assign → .dec_var, type | begin | id | if |
ε

dec_var → .type id id1 semi dec_var, type | begin | id | if |
ε
assign → .if expr assign, type | begin | id | if |
ε
assign → .if expr assign else assign, type | begin | id | if |
ε
assign → .begin assign_list end, type | begin | id | if |
ε
assign → .id asg expr semi, type | begin | id | if |
ε

goto(I
31
, id)
I
48

: assign → id. asg expr semi, type | begin | id | if |
ε
| else

Goto(I
32
, aws)
I
49
: expr → exp aws. expr colon expr, type | begin | id | if |
ε
expr → .exp aws expr colon expr, colon
expr → .exp, colon
exp → .exp or exp1, colon | aws | or
exp → .exp1, colon | aws | or
exp1 → .exp1 and term, colon | aws | and | or
exp1 → .term, colon | aws | and | or
term → .term relop1 term1, colon | aws | and | relop1 | or
term → .term1, colon | aws | and | relop1 | or
term1 → .term1 relop2 term2, colon | aws | and | relop1 | relop2 | or
term1 → .term2, colon | aws | and | relop1 | relop2 | or
term2 →.term2 op1 term3, colon|aws|or|and|relop1|relop2|op1
term2 → .term3, colon |aws|or|and|relop1|relop2|op1
term3→.term3 op2 factor,colon|aws|or|and|relop1|relop2|op1|op2
term3 → .factor, colon|aws|or|and|relop1|relop2|op1|op2
factor → .not factor1, colon|aws|or|and|relop1|relop2|op1|op2
Goto(I
32
, or)
I

50
: exp → exp or. exp1, type | begin | id | if | aws | or |
ε
exp1 → .exp1 and term, type | begin | id | if | aws | or |
ε
| and
exp1 → .term, type | begin | id | if | aws | or |
ε
| and
term → .term relop1 term1, type | begin | id | if | aws | or |
ε
| and | relop1
term → .term1, type | begin | id | if | aws | or |
ε
| and | relop1
term1 →.term1 relop2 term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term1 → .term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term2 →.term2 op1 term3, type|begin|id|if| aws| or|
ε
| and| relop1| relop2|op1
term2 → .term3, type| begin| id| if| aws| or|
ε
| and| relop1| relop2| op1
term3 → .term3 op2 factor, type|begin|id|if|aws|or|
ε
|and|

relop1|relop2|op1|op2
term3 → .factor, type| begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
33
, and)
I
51
: exp1 → exp1 and. term, type | begin | id | if | aws | or | and |
ε
term → .term relop1 term1, type | begin | id | if | aws | or |
ε
| and | relop1
term → .term1, type | begin | id | if | aws | or |
ε
| and | relop1
term1 →.term1 relop2 term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term1 → .term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term2 →.term2 op1 term3, type|begin|id|if| aws| or|
ε
| and| relop1| relop2|op1

term2 → .term3, type| begin| id| if| aws| or|
ε
| and| relop1| relop2| op1
term3 → .term3 op2 factor, type|begin|id|if|aws|or|
ε
|and|
relop1|relop2|op1|op2
term3 → .factor, type| begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
34
, relop1)
I
52
: term → term relop1. term1, type | begin | id | if | aws | or | and | relop1 |
ε
term1 →.term1 relop2 term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term1 → .term2, type| begin| id| if| aws| or|
ε
| and| relop1| relop2
term2 →.term2 op1 term3, type|begin|id|if| aws| or|
ε
| and| relop1| relop2|op1

term2 → .term3, type| begin| id| if| aws| or|
ε
| and| relop1| relop2| op1
term3 → .term3 op2 factor, type|begin|id|if|aws|or|
ε
|and|
relop1|relop2|op1|op2
term3 → .factor, type| begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
35
, relop2)
I
53
: term1 → term1 relop2. term2, type| begin| id| if| aws| or| and| relop1|relop2|
ε
term2 →.term2 op1 term3, type|begin|id|if| aws| or|
ε
| and| relop1| relop2|op1
term2 → .term3, type| begin| id| if| aws| or|
ε
| and| relop1| relop2| op1
term3 → .term3 op2 factor, type|begin|id|if|aws|or|
ε
|and|

relop1|relop2|op1|op2
term3 → .factor, type| begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
36
, op1)
I
54
: term2 →term2 op1. term3, type|begin|id|if|aws|or|and|relop1|relop2|op1|
ε
term3 → .term3 op2 factor, type|begin|id|if|aws|or|
ε
|and|
relop1|relop2|op1|op2
term3 → .factor, type| begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
37
, op2)
I

55
: term3→term3 op2. factor,type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε
factor →.not factor1, type|begin| id| if| aws| or|
ε
| and| relop1| relop2|op1|op2

Goto(I
39
, factor1)
I
56
: factor → not factor1., type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε

Goto(I
39
, left)
I
57
: factor1 → left. expr right, type | begin | id | if | aws | or | and |
relop1| relop2 |op1 |op2 |
ε
expr → .exp aws expr colon expr, right
expr → .exp, right
exp → .exp or exp1, right | aws | or
exp → .exp1, right | aws | or
exp1 → .exp1 and term, right | aws | or | and
exp1 → .term, right | aws | or | and
term → .term relop1 term1, right | aws | or | and | relop1

term → .term1, right | aws | or | and | relop1
term1 → .term1 relop2 term2, right | aws | or | and | relop1 | relop2
term1 → .term2, right | aws | or | and | relop1 | relop2
term2 →.term2 op1 term3, right | aws | or | and | relop1 | relop2 | op1
term2 → .term3, right | aws | or | and | relop1 | relop2 | op1
term3→.term3 op2 factor, right | aws | or | and | relop1 | relop2 | op1| op2
term3 → .factor, right | aws | or | and | relop1 | relop2 | op1| op2
factor → .not factor1, right | aws | or | and | relop1 | relop2 | op1| op2
factor1 → left. type right id, type|begin|id|if|aws|or|and|

×