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

Bài tập lớn Chương trình dịch – Đề số 13

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 (238.82 KB, 54 trang )

1.Nguyễn Thị Hồng Trang
2.Nguyễn Thị Thanh Hải
3.Dương Thị Thanh Thúy
4.Trịnh Thị Thúy Ngân
Đề số 13
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 Gán,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, 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.
Yêu cầu:
 Viết chương trình bằng tay.
 Quá trình phân tích cú pháp được thực hiện theo phương pháp từ dưới lên
 Giai đoạn xử lý ngữ nghĩa sinh viên phải thực hiện bằng cách đặt các hành
vi ngữ nghĩa vào bản đặc tả cú pháp.
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ép Gán
- Gán giá trị trực tiếp
- Phép gán giá trị + them, - bớt: +=
- Phép gán giá trị nhân, chia, chia có dư: *=, /=, %=
- Phép gán bit shift: >>=
- Phép gán bít and, or, xor: &=, |=, ^=
2. Phát biểu ghép
{
Lệnh 1;
Lệnh 2;


}
3 Phát biểu if
* Dạng 1:
If (điều kiện) lệnh S;
- VD:
if (a>0)
Printf (“a là số lớn hơn 0”);
- 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 .
- VD:
If (phaydiem<8)
{
If (phaydiem<7)
Printf (“Bạn chỉ đạt điểm Trung bình!”);
Else
Printf(“Bạn đạt loại Khá”);
}
Else
Printf(“Bạn đạt loại Giỏi”);
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
leftpar ( (
rightpar ) )
not ! Phép phủ định
and && Phép và
or || Phép hoặc
semicolon ; ;
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 open → [
else → else close → ]
void → void aws → ?
main → main
asg → =
begin → {
end → }
leftpar → (
rightpar → )
semicolon → ;
coma → ,
colon → :
2. Sơ đồ dịch
* Sơ đồ dịch nhận dạng token relop:
* Sơ đồ dịch nhận dạng token relop:
* id
* id
other
*
5
=
4
=
!
=
76

>
8
9
=
1
0
other
*
Start
0
2
1
3
=
3
Start
1
letter | digit | ‘_’
<
2
letter | ‘_’
*
other
* num

* real
* real

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
3
digit
digit
Start
1
7
8
5
6
4
3
2
+
]
)
(
/
*
-
[
9
2
other
*
4
1
0
‘.’

other
digit
digit

+‘+’|
’-‘
8 9
digit
5 7
digit
digit
other
6
*
sta
rt
digit
2
digit
1
3
other
‘E’|‘e’
‘E’|‘e’ ‘+’|‘-’
*
*
10
{
C. Phân tích cú pháp
I. Định nghĩa văn phạm tổng quát

S → void main leftpar rightpar block
block → begin assign_list end
assign_list → assign assign_list |
ε
assign → dec_var | begin assign_list end | pbif
dec_var → type id id1 semicolon 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 semicolon
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
!
1
8
19
&
&
2
0
15
| |
13
14
12
17
21

11
}
;
:
?
,
16
=
term2 → term2 op1 term3| term3
term3 → term3 op2 factor | factor
factor → not factor1
factor1 → leftpar exp rightpar| id | num | real
* Văn phạm tăng cường
S’ → S
(1) S → dec_var void main leftpar rightpar block
(2) dec_var → type id id1 semicolon 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 semicolon
(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 → leftpar expr rightpar
(31) factor1 → id
(32) factor1 → num
(33) factor1 → real
(34) factor1 → leftpar type rightpar 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. leftpar
4. rightpar
5. type
6. semicolon
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 leftpar rightpar block, $
dec_var → .type id id1 semicolon 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 leftpar rightpar block, $

goto(I
0,
type)
I

3
: dec_var → type. id id1 semicolon dec_var, void

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

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

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

goto(I
5
, id1)

I
7
: dec_var → type id id1. semicolon dec_var, void

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

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

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

goto(I
7
, semicolon)
I
11

: dec_var → type id id1 semicolon. dec_var, void
dec_var → .type id id1 semicolon dec_var, void

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

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

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

goto(I
11

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

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

goto(I
13
, close)
I
17
: id1 → open num close. id1, semicolon

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

goto(I
14
, block)
I
18
: S → dec_var void main leftpar rightpar 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 semicolon 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 semicolon, type | begin | id | if |
ε

goto(I
17
, id)
I
20
: id1 → open num close id1., semicolon
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 semicolon 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 semicolon, 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 semicolon 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 semicolon 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 semicolon, type | begin | id | if |
ε

goto(I
19
, id)
I
27
: assign → id. asg expr semicolon, 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 semicolon dec_var, type | begin | id | if |

ε
id1 → .coma id id1, semicolon
id1 → .open num close id1, semicolon
id1 → ., semicolon

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 semicolon 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 semicolon, 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 → .leftpar expr rightpar,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 → .leftpar type rightpar 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 semicolon, type | begin | id | if |
ε
expr → .exp aws expr colon expr, semicolon
expr → .exp, semicolon
exp → .exp or exp1, semicolon | aws | or
exp → .exp1, semicolon | aws | or
exp1 → .exp1 and term, semicolon | aws | or | and
exp1 → .term, semicolon | aws | or | and
term → .term relop1 term1, semicolon | aws | or | and | relop1
term → .term1, semicolon | aws | or | and | relop1
term1 → .term1 relop2 term2, semicolon | aws | or | and | relop1| relop2
term1 → .term2, semicolon | aws | or | and | relop1| relop2
term2 →.term2 op1 term3, semicolon | aws | or | and | relop1| relop2 | op1
term2 → .term3, semicolon | aws | or | and | relop1| relop2 | op1
term3→.term3 op2 factor, semicolon | aws | or | and | relop1| relop2 |op1|op2
term3 → .factor, semicolon | aws | or | and | relop1| relop2 |op1|op2
factor → .not factor1, semicolon | aws | or | and | relop1| relop2 |op1|op2


goto(I
30
, id1)
I
42
: dec_var → type id id1. semicolon 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 semicolon 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 semicolon 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 semicolon, type | begin | id | if |
ε

goto(I
31

, id)
I
48
: assign → id. asg expr semicolon, 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
, leftpar)
I
57
: factor1 → leftpar. expr rightpar, type | begin | id | if | aws | or | and |
relop1| relop2 |op1 |op2 |
ε
expr → .exp aws expr colon expr, rightpar
expr → .exp, rightpar

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

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

Goto(I
39
, num)
I
59

: factor1 → num., type|begin|id|if|aws|or|and|relop1|relop2|op1|op2|
ε

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

Goto(I
40
, end)
I
61
: assign → begin assign_list end., type | begin | id | if |
ε

Goto(I
41
, expr)
I
62
: assign → id asg expr. semicolon, type | begin | id | if |
ε

Goto(I
41
, exp)

I
63
: expr → exp. aws expr colon expr, semicolon
expr → exp., semicolon
exp → exp. or exp1, semicolon | aws | or

Goto(I
41
, exp1)
I
64
: exp → exp1., semicolon | aws | or
exp1 → exp1. and term, semicolon | aws | or | and

Goto(I
41
, term)
I
65
: exp1 → term., semicolon | aws | or | and
term → term. relop1 term1, semicolon | aws | or | and | relop1

Goto(I
41
, term1)
I
66
: term → term1., semicolon | aws | or | and | relop1
term1 → term1. relop2 term2, semicolon | aws | or | and | relop1| relop2


Goto(I
41
, term2)
I
67
: term1 → term2., semicolon | aws | or | and | relop1| relop2
term2 →term2. op1 term3, semicolon | aws | or | and | relop1| relop2 | op1

Goto(I
41
, term3)
I
68
: term2 → term3., semicolon | aws | or | and | relop1| relop2 | op1
term3→term3. op2 factor, semicolon | aws | or | and | relop1| relop2 |op1|op2

Goto(I
41
, factor)
I
69
: term3 → factor., semicolon | aws | or | and | relop1| relop2 |op1|op2

Goto(I
41
, not)

×