修复一些小bug

This commit is contained in:
不点 小 2022-04-14 19:17:24 +08:00
parent 29006acb6b
commit 3288bc111a
9 changed files with 357 additions and 90 deletions

View File

@ -30,7 +30,7 @@ unordered_map<int, string> ha =
{4, "TYPE"}, {5, "VAR"}, {6, "IF"}, {7, "THEN"},
{8, "ELSE"}, {9, "FI"}, {10, "WHILE"}, {11, "DO"},
{12, "ENDWH"}, {13, "BEGIN"}, {14, "END"}, {15, "READ"},
{16, "WRITE"}, {11, "ARRAY"}, {12, "OF"}, {13, "RECORD"},
{16, "WRITE"}, {17, "ARRAY"}, {18, "OF"}, {19, "RECORD"},
{20, "RETURN"}, {21, "INTEGER"}, {22, "CHAR1"}, {23, "ID"},
{24, "INTC"}, {25, "CHARC"}, {26, "ASSIGN"}, {27, "EQ"},
{28, "LT"}, {29, "PLUS"}, {30, "MINUS"}, {31, "TIMES"},

View File

@ -427,7 +427,7 @@ TypeIR* SemanticAnalysis::arrayType(TreeNode* t)
TypeIR* present = NULL;
if (t->attr.ArrayAttr.low > t->attr.ArrayAttr.up)
{
semanticError(t->lineno, "数组越界");
semanticError(t->lineno, "数组上下界定义错误");
hasError = true;
}
else
@ -837,13 +837,26 @@ TypeIR* SemanticAnalysis::arrayVar(TreeNode* t)
//数组下标类型
TypeIR* temp1 = NULL;
TypeIR* temp2 = NULL;
AccessKind tempA;
temp1 = entry->attrIR.idtype->More.ArrayAttr.indexTy;
temp2 = Expr(t->child[0], NULL);
temp2 = Expr(t->child[0], &tempA);
if (temp1 == NULL || temp2 == NULL)
return NULL;
//判断类型后,判断数组是否越界
if (temp1 == temp2)
{
Eptr = entry->attrIR.idtype->More.ArrayAttr.elemTy;
if (temp1->kind == intTy)
{
if (t->child[0]->attr.ExpAttr.val != -842150451)
if (t->child[0]->attr.ExpAttr.val < entry->attrIR.idtype->More.ArrayAttr.low ||
t->child[0]->attr.ExpAttr.val > entry->attrIR.idtype->More.ArrayAttr.up)
semanticError(t->lineno, "数组值参下标越界");
}
}
else
{
string temp = t->name[0].c_str();

View File

@ -1,3 +1,109 @@
ProK
line: 4 PheadK
PheadK bubble
VarK
line: 2 Deck Integer i j num
line: 3 Deck ArrayK 20 1 Integer a
line: 5 ProcDecK q
line: 5 Deck value param: Integer num
VarK
line: 7 Deck Integer i j k
line: 8 Deck Integer t
StmLk
line: 10 Stmtk Assign
line: 10 ExpK Vari Id i
line: 10 ExpK Const Id 1
line: 11 Stmtk While
line: 11 ExpK Op <
line: 11 ExpK Vari Id i
line: 11 ExpK Vari Id num
line: 12 Stmtk Assign
line: 12 ExpK Vari Id j
line: 12 ExpK Op +
line: 12 ExpK Op -
line: 12 ExpK Vari Id num
line: 12 ExpK Vari Id i
line: 12 ExpK Const Id 1
line: 13 Stmtk Assign
line: 13 ExpK Vari Id k
line: 13 ExpK Const Id 1
line: 14 Stmtk While
line: 14 ExpK Op <
line: 14 ExpK Vari Id k
line: 14 ExpK Vari Id j
line: 15 Stmtk If
line: 15 ExpK Op <
line: 15 ExpK Vari ArrayMember a
line: 15 ExpK Op +
line: 15 ExpK Vari Id k
line: 15 ExpK Const Id 1
line: 15 ExpK Vari ArrayMember a
line: 15 ExpK Vari Id k
line: 17 Stmtk Assign
line: 17 ExpK Vari Id t
line: 17 ExpK Vari ArrayMember a
line: 17 ExpK Vari Id k
line: 18 Stmtk Assign
line: 18 ExpK Vari ArrayMember a
line: 18 ExpK Vari Id k
line: 18 ExpK Vari ArrayMember a
line: 18 ExpK Op +
line: 18 ExpK Vari Id k
line: 18 ExpK Const Id 1
line: 19 Stmtk Assign
line: 19 ExpK Vari ArrayMember a
line: 19 ExpK Op +
line: 19 ExpK Vari Id k
line: 19 ExpK Const Id 1
line: 19 ExpK Vari Id t
line: 20 Stmtk Assign
line: 20 ExpK Vari Id t
line: 20 ExpK Const Id 0
line: 22 Stmtk Assign
line: 22 ExpK Vari Id k
line: 22 ExpK Op +
line: 22 ExpK Vari Id k
line: 22 ExpK Const Id 1
line: 24 Stmtk Assign
line: 24 ExpK Vari Id i
line: 24 ExpK Op +
line: 24 ExpK Vari Id i
line: 24 ExpK Const Id 1
StmLk
line: 29 Stmtk Read num
line: 30 Stmtk Assign
line: 30 ExpK Vari Id i
line: 30 ExpK Const Id 1
line: 31 Stmtk While
line: 31 ExpK Op <
line: 31 ExpK Vari Id i
line: 31 ExpK Vari Id num
line: 32 Stmtk Read j
line: 33 Stmtk Assign
line: 33 ExpK Vari ArrayMember a
line: 33 ExpK Vari Id i
line: 33 ExpK Vari Id j
line: 34 Stmtk Assign
line: 34 ExpK Vari Id i
line: 34 ExpK Op +
line: 34 ExpK Vari Id i
line: 34 ExpK Const Id 1
line: 36 Stmtk Call
line: 36 ExpK Vari Id i
line: 36 ExpK Vari Id num
line: 37 Stmtk Assign
line: 37 ExpK Vari Id i
line: 37 ExpK Const Id 1
line: 38 Stmtk While
line: 38 ExpK Op <
line: 38 ExpK Vari Id i
line: 38 ExpK Op +
line: 38 ExpK Vari Id num
line: 38 ExpK Const Id 1
line: 39 Stmtk Write
line: 39 ExpK Vari ArrayMember a
line: 39 ExpK Vari Id i
line: 40 Stmtk Assign
line: 40 ExpK Vari Id i
line: 40 ExpK Op +
line: 40 ExpK Vari Id i
line: 40 ExpK Const Id 1

View File

@ -1,9 +0,0 @@
语法错误, line 4 : 符号"ools\MSVC\14.29.30133\include\xlocale"错误,也许缺失符号"ID"
语法错误, line 4 : 意外符号"ools\MSVC\14.29.30133\include\xlocale"或许缺少符号“TYPE” / “VAR” / “PROCEDURE” / “BEGIN”
语法错误, line 4 : 意外符号"ools\MSVC\14.29.30133\include\xlocale"或许缺少符号“PROCEDURE” / “BEGIN” / “VAR”
语法错误, line 4 : 意外符号"ools\MSVC\14.29.30133\include\xlocale"或许缺少符号“PROCEDURE” / “BEGIN”
语法错误, line 4 : 符号"ools\MSVC\14.29.30133\include\xlocale"错误,也许缺失符号"BEGIN"
语法错误, line 4 : 意外符号"ools\MSVC\14.29.30133\include\xlocale"
语法错误, line 4 : 意外符号"ools\MSVC\14.29.30133\include\xlocale",或许缺少符号“;”/ “END” / “ENDWH”
语法错误, line 4 : 符号"ools\MSVC\14.29.30133\include\xlocale"错误,也许缺失符号"END"
语法错误, line 4 : 符号"ools\MSVC\14.29.30133\include\xlocale"错误,也许缺失符号"DOT"

View File

@ -0,0 +1 @@
语义错误, line 36 : 不是函数名

View File

@ -0,0 +1,12 @@
==========µÚ0²ã·ûºÅ±í==========
i: intTy varKind Level: 0 Offset: 7 indir
j: intTy varKind Level: 0 Offset: 8 indir
num: intTy varKind Level: 0 Offset: 9 indir
a: arrayTy varKind Level: 0 Offset: 10 indir
q: funcKind Level: 1 nOff: -842150656
==========µÚ1²ã·ûºÅ±í==========
num: intTy varKind Level: 1 Offset: 7 dir
i: intTy varKind Level: 1 Offset: 8 indir
j: intTy varKind Level: 1 Offset: 9 indir
k: intTy varKind Level: 1 Offset: 10 indir
t: intTy varKind Level: 1 Offset: 11 indir

View File

@ -1,21 +1,42 @@
{给出一个错误的程序,测试是否能够检查出来,
并给出错误 提示信息}
program bubble
var integer i,j,num;
array [1..20] of integer a;
program _error
var integer s;
integer t;
procedure factor(intaeger n;var integer m);
var integer w;
procedure q(integer num);
var integer i,j ,k;
integer t;
begin
if n=0
then m:=1
else
factor(n-1,w);
m:=n*w
fi
i:=1;
while i < num do
j := num-i+ 1;
k:=1;
while k<j do
if a[k+ 1] < a[k]
then
t:=a[k ];
a[k] :=a[k+ 1 ];
a[k+ 1 ]:=t
else t:=0
fi;
k:=k+ 1
endwh;
i:=i+1
endwh
end
begin
read(s);
factor(s,t);
write(t)
read(num);
i:=1;
while i < num do
read(j);
a[i]:=j;
i:=i+1
endwh;
i(num);
i:=1;
while i <(num+ 1) do
write(a[i]);
i:=i+1
endwh
end.

View File

@ -1,71 +1,194 @@
4 2 program
4 1 ools\MSVC\14.29.30133\include\xlocale
4 23 error
5 5 var
1 2 program
1 23 bubble
2 5 var
2 21 integer
2 23 i
2 38 ,
2 23 j
2 38 ,
2 23 num
2 37 ;
3 17 array
3 39 [
3 24 1
3 41 ..
3 24 20
3 40 ]
3 18 of
3 21 integer
3 23 a
3 37 ;
5 3 procedure
5 23 q
5 33 (
5 21 integer
5 23 s
5 23 num
5 34 )
5 37 ;
6 21 integer
6 23 t
6 37 ;
7 3 procedure
7 23 factor
7 33 (
7 23 intaeger
7 23 n
7 37 ;
7 5 var
7 21 integer
7 23 m
7 34 )
7 23 i
7 38 ,
7 23 j
7 38 ,
7 23 k
7 37 ;
8 5 var
8 21 integer
8 23 w
8 23 t
8 37 ;
9 13 begin
10 6 if
10 23 n
10 27 =
10 24 0
11 7 then
11 23 m
11 26 :=
11 24 1
12 8 else
13 23 factor
13 33 (
13 23 n
13 30 -
10 23 i
10 26 :=
10 24 1
10 37 ;
11 10 while
11 23 i
11 28 <
11 23 num
11 11 do
12 23 j
12 26 :=
12 23 num
12 30 -
12 23 i
12 29 +
12 24 1
12 37 ;
13 23 k
13 26 :=
13 24 1
13 38 ,
13 23 w
13 34 )
13 37 ;
14 23 m
14 26 :=
14 23 n
14 31 *
14 23 w
15 9 fi
16 14 end
17 13 begin
18 15 read
18 33 (
18 23 s
18 34 )
14 10 while
14 23 k
14 28 <
14 23 j
14 11 do
15 6 if
15 23 a
15 39 [
15 23 k
15 29 +
15 24 1
15 40 ]
15 28 <
15 23 a
15 39 [
15 23 k
15 40 ]
16 7 then
17 23 t
17 26 :=
17 23 a
17 39 [
17 23 k
17 40 ]
17 37 ;
18 23 a
18 39 [
18 23 k
18 40 ]
18 26 :=
18 23 a
18 39 [
18 23 k
18 29 +
18 24 1
18 40 ]
18 37 ;
19 23 factor
19 33 (
19 23 s
19 38 ,
19 23 a
19 39 [
19 23 k
19 29 +
19 24 1
19 40 ]
19 26 :=
19 23 t
19 34 )
19 37 ;
20 16 write
20 33 (
20 8 else
20 23 t
20 34 )
21 14 end
21 35 .
21 0 ÿ
20 26 :=
20 24 0
21 9 fi
21 37 ;
22 23 k
22 26 :=
22 23 k
22 29 +
22 24 1
23 12 endwh
23 37 ;
24 23 i
24 26 :=
24 23 i
24 29 +
24 24 1
25 12 endwh
26 14 end
28 13 begin
29 15 read
29 33 (
29 23 num
29 34 )
29 37 ;
30 23 i
30 26 :=
30 24 1
30 37 ;
31 10 while
31 23 i
31 28 <
31 23 num
31 11 do
32 15 read
32 33 (
32 23 j
32 34 )
32 37 ;
33 23 a
33 39 [
33 23 i
33 40 ]
33 26 :=
33 23 j
33 37 ;
34 23 i
34 26 :=
34 23 i
34 29 +
34 24 1
35 12 endwh
35 37 ;
36 23 i
36 33 (
36 23 num
36 34 )
36 37 ;
37 23 i
37 26 :=
37 24 1
37 37 ;
38 10 while
38 23 i
38 28 <
38 33 (
38 23 num
38 29 +
38 24 1
38 34 )
38 11 do
39 16 write
39 33 (
39 23 a
39 39 [
39 23 i
39 40 ]
39 34 )
39 37 ;
40 23 i
40 26 :=
40 23 i
40 29 +
40 24 1
41 12 endwh
42 14 end
42 35 .
42 0 ÿ

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 MiB

After

Width:  |  Height:  |  Size: 3.2 MiB