1.1测试var_parameter

正确表达式为:var_parameter —-> VAR value_parameter

1.1.1 不完整的引用参数列表

var_parameter —-> VAR error

  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro(var ); begin end; begin

end.

  1. - 预期结果
  2. 遇到错误时报告“不完整参数列表”,并报告错误所在的具体位置,行号和列号。
  3. - 测试结果
  4. 1. Here **is** the syntax error information <br />2. syntax error, unexpected ')', expecting IDENTIFIER, location: 3.19 <br />3. syntax error, incomplete refereced parameter list, location: 3.15-3.19 <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
  5. <a name="b3leE"></a>
  6. ## 1.2测试value_parameter
  7. 正确表达式为:value_parameter ---> idlist ':' TYPE
  8. <a name="cFidP"></a>
  9. ### 1.2.1 缺少冒号
  10. value_parameter ---> idlist 'error TYPE
  11. - 测试用例
  12. ```pascal
  13. program test(input,output);
  14. var b:real;
  15. procedure pro(a integer);
  16. begin
  17. end;
  18. begin
  19. end.
  • 预期结果

遇到错误时报告“缺少分号”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected TYPE, expecting ‘,’ or ‘:’, location: 3.17
    3. syntax error, missing a colon here, location: 3.16
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.2.2 缺少基本类型关键字

    value_parameter —-> idlist ‘:’ error
  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro(a:); begin end; begin

end.


- 预期结果

遇到错误时报告“缺少基本类型关键字”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected TYPE, expecting ',' **or** ':', location: 3.17  <br />3.  syntax error, missing a colon here, location: 3.16  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="JhvmM"></a>
## 1.3测试compound_statement
正确表达式为:compound_statement ---> _BEGIN statement_list END
<a name="2dDGS"></a>
### 1.3.1       缺少end关键字
compound_statement ---> _BEGIN statement_list error

- 测试用例
```pascal
program test(input,output);  
var b:real;  
begin  

.
  • 预期结果

遇到错误时报告“缺少END关键字”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected ‘.’, expecting END or ‘;’, location: 5.1
    3. syntax error, missing keyword “end“, location: 3.6
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.4测试statement_list

    正确表达式为:statement_list —-> statement_list ‘;’ statement | statement

    1.4.1 缺少分号

    statement_list —-> statement_list error statement
  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro; var a:integer; begin b:=b; b:=b end; begin

end.


- 预期结果

遇到错误时报告“缺少分号”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected IDENTIFIER, expecting END **or** ';', location: 8.5  <br />3.  syntax error, missing a semicolon here, location: 7.9  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="hkl2H"></a>
## 1.5测试statement
正确表达式为:<br />statement ---> variable ASSIGNOP expression | procedure_call | <br />           compound_statement | IF expression THEN statement else_part | <br />           FOR IDENTIFIER ASSIGNOP expression TO expression DO statement | <br />           WHILE expression DO statement | REPEAT statement UNTIL expression | empty
<a name="9ojec"></a>
### 1.5.1       IF语句缺少then关键字
statement ---> IF expression error statement else_part

- 测试用例
```pascal
program test(input,output);
var b:real;
procedure pro;
var a:integer;
begin
if a>b
b:=1;
end;
begin

end.
  • 预期结果

遇到错误时报告“缺少then关键字”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected IDENTIFIER, expecting THEN, location: 7.9
    3. syntax error, missing keyword “then“, location: 6.11
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.5.2 FOR语句缺少赋值号

    statement —-> FOR IDENTIFIER error expression TO expression DO statement
  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro; var a:integer; begin for a 1 to 2 do b:=1; end; begin

end.


- 预期结果

遇到错误时报告“缺少赋值号”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected UINUM, expecting ASSIGNOP, location: 6.11  <br />3.  syntax error, missing assignop ":=", location: 6.10  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="UKxjm"></a>
### 1.5.3       FOR语句缺少关键字to
statement ---> FOR IDENTIFIER ASSIGNOP expression error expression DO statement

- 测试用例
```pascal
program test(input,output);
var b:real;
procedure pro;
var a:integer;
begin
for a:=1  2 do
b:=1;
end;
begin

end.
  • 预期结果

遇到错误时报告“缺少关键字to”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected UINUM, expecting TO, location: 6.15
    3. syntax error, missing keywrod “to“, location: 6.13
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.5.4 FOR语句缺少关键字do

    statement —-> FOR IDENTIFIER ASSIGNOP expression TO expression error statement
  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro; var a:integer; begin for a:=1 to 2 b:=1; end; begin

end.


- 预期结果

遇到错误时报告“缺少关键字do”,并报告错误所在的具体位置,行号和列号。

- 测试结果

 <br />1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected IDENTIFIER, expecting DO, location: 7.9  <br />3.  syntax error, missing keywrod "**do**", location: 6.13  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="qSKNe"></a>
### 1.5.5       WHILE语句缺少关键字do
statement ---> WHILE expression error statement

- 测试用例
```pascal
program test(input,output);
var b:real;
procedure pro;
var a:integer;
begin
while a=1
b:=1;
end;
begin

end.
  • 预期结果

遇到错误时报告“缺少关键字do”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected IDENTIFIER, expecting DO, location: 7.9
    3. syntax error, missing keywrod “do“, location: 6.14
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.5.6 REPEAT语句缺少关键字until

    statement —-> REPEAT statement error expression
  • 测试用例 ```pascal program test(input,output); var b:real; procedure pro; var a:integer; begin repeat b:=1 a=1; end; begin

end.


- 预期结果

遇到错误时报告“缺少关键字until”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected IDENTIFIER, expecting UNTIL, location: 8.5  <br />3.  syntax error, missing keywrod "**until**", location: 8.5  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="VAJoE"></a>
## 1.6测试id_varpart
正确表达式为:id_varpart ---> '[' expression_list ']' | empty
<a name="OLcyw"></a>
### 1.6.1       缺少右中括号
id_varpart ---> '[' expression_list error

- 测试用例
```pascal
program test(input,output);
var b:real;
c:array[1..5,6..10] of integer;
procedure pro;
var a:integer;
begin
repeat
c[1,6:=100
until a=1;
end;
begin

end.
  • 预期结果

遇到错误时报告“缺少右中括号”,并报告错误所在的具体位置,行号和列号。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected ASSIGNOP, expecting ‘,’ or ‘]’, location: 8.14
    3. syntax error, missing a right square bracket here, location: 8.14
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。

    1.6.2 不完整的数组下标列表

    id_varpart —-> ‘[‘ error
  • 测试用例: ```pascal program test(input,output); var b:real; c:array[1..5,6..10] of integer; procedure pro; var a:integer; begin repeat c[:=100 until a=1; end; begin

end. ```

  • 预期结果

遇到错误时报告“不完整的数组下表列表”,并报告错误所在的具体位置。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected ASSIGNOP, location: 8.11
    3. syntax error, incomplete expression list of array subindex, location: 8.10-8.12
    测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。