1.1测试type

正确的表达式为:type —-> TYPE
| ARRAY ‘[‘ period ‘]’ OF TYPE

1.1.1 缺少左中括号

type —-> ARRAY error period ‘]’ OF TYPE

  • 测试用例 ```pascal program test(input,output); var a: array 1..3] of integer; begin

end.


- 预期结果

语法分析程序识别到数组的类型声明缺少左中括号,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected UINUM, expecting '[', location: 2.14  <br />3.  syntax error, missing a left square bracket here, location: 2.13  

- 分析

实际结果与预期结果一致。当语法分析程序在状态92时,读取到变量定义类型识别失败时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。
<a name="YWwWd"></a>
### 1.1.2       缺少OF关键字
type ---> ARRAY '[' period ']' error TYPE

- 测试用例
```pascal
program test(input,output);
var a: array[1..3] integer;
begin

end.
  • 预期结果

语法分析程序识别到数组的类型声明缺少OF关键字,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected TYPE, expecting OF, location: 2.20
    3. syntax error, missing keyword “OF” here, location: 2.19-2.19
  • 分析

实际结果与预期结果一致。当语法分析程序在状态203时,读取到数组的类型声明缺少OF关键字时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。

1.1.3 数组元素识别失败

type —-> ARRAY ‘[‘ period ‘]’ OF error

  • 测试用例 ```pascal program test(input,output); var a: array[1..2] of 123; begin

end.


- 预期结果

语法分析程序识别数组元素类型失败,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected UINUM, expecting TYPE, location: 2.23  <br />3.  syntax error, missing a base **type** keyword here, location: 2.22  <br />4.  syntax error, missing a semicolon here, location: 2.26  <br />5.  fatal error **in** **program** body, location: 5.4  

- 分析

实际结果与预期结果一致。当语法分析程序在状态246时,读取到错误的数组元素类型名时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。
<a name="brLRM"></a>
### 1.1.4       不完整的数组类型
1:type ---> ARRAY error<br />2:type ---> ARRAY '[' error<br />3:type ---> ARRAY '[' period error

- 测试用例1
```pascal
program test(input,output);
var a: array;
begin

end.
  • 预期结果

语法分析程序识别到不完整的数据类型,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected ‘;’, expecting ‘[‘, location: 2.13
    3. syntax error, incomplete array type, location: 2.8-2.13
  • 分析

实际结果与预期结果一致。当语法分析程序在状态92时,读取到不完整的数组类型时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。

  • 测试用例2 ```pascal program test(input,output); var a: array [a; begin

end.


- 预期结果

语法分析程序识别到不完整的数据类型,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected IDENTIFIER, expecting UINUM, location: 2.15  <br />3.  syntax error, incomplete **array** **type**, location: 2.8-2.15  <br />4.  syntax error, missing a semicolon here, location: 2.16  <br />5.  fatal error **in** **program** body, location: 5.4  

- 分析

实际结果与预期结果一致。当语法分析程序在状态122时,读取到不完整的数组类型时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。

- 测试用例3
```pascal
program test(input,output);
var a: array [1..3,4..6,7..9;
begin

end.
  • 预期结果

语法分析程序识别到不完整的数据类型,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected ‘;’, expecting ‘,’ or ‘]’, location: 2.29
    3. syntax error, incomplete array type, location: 2.8-2.29
  • 分析

实际结果与预期结果一致。当语法分析程序在状态158时,读取到不完整的数组类型时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。

1.2测试period

正确的产生式为:period —-> period ‘,’ UINUM RANGEDOT UINUM
| UINUM RANGEDOT UINUM

1.2.1 缺少逗号

period —-> period error UINUM RANGEDOT UINUM

  • 测试用例 ```pascal program test(input,output); var a: array [1..3 4..6 7..9]; begin

end.


- 预期结果

语法分析程序识别到缺少逗号的错误时,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected UINUM, expecting ',' **or** ']', location: 2.20  <br />3.  syntax error, missing a comma here, location: 2.19  <br />4.  syntax error, unexpected UINUM, expecting ',' **or** ']', location: 2.25  <br />5.  syntax error, missing a comma here, location: 2.24  <br />6.  syntax error, unexpected ';', expecting OF, location: 2.30  

- 分析

实际结果与预期结果一致。当语法分析程序在状态158时,未读取到逗号就读取到数字时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。
<a name="M1FF5"></a>
### 1.2.2       缺少双点号
period ---> period ',' UINUM error UINUM

- 测试用例
```pascal
program test(input,output);
var a: array [1..3,4 6,7 9];
begin

end.
  • 预期结果

语法分析程序识别到缺少双点号时,应在不影响其他记号串分析的情况下,报告主程序的错误信息,并报告位置。

  • 测试结果
  1. Here is the syntax error information
    2. syntax error, unexpected UINUM, expecting RANGEDOT, location: 2.22
    3. syntax error, missing range dot .. here, location: 2.21
    4. syntax error, unexpected UINUM, expecting RANGEDOT, location: 2.26
    5. syntax error, missing range dot .. here, location: 2.25
  • 分析

实际结果与预期结果一致。当语法分析程序在状态243时,读取到缺少双点号时,会移进error记号,从而触发相关报错动作,并继续分析后续记号串。

1.3测试subprogram_declarations

正确产生式为:
subprogram_declarations —-> subprogram_declarations subprogram ‘;’ | empty

1.3.1 子程序体尾部缺少分号

subprogram_declarations —-> subprogram_declarations subprogram error

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

end.



- 预期结果

遇到错误应报告“缺少分号”,并报告错误出现的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected _BEGIN, expecting ';', location: 4.1  <br />3.  syntax error, missing a semicolon here, location: 3.14  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。<br /> 
<a name="OcYkt"></a>
## 1.4测试subprogram_head
正确产生式为:<br />subprogram_head ---> PROCEDURE IDENTIFIER formal_parameter | FUNCTION IDENTIFIER formal_parameter ':' TYPE
<a name="90xNX"></a>
### 1.4.1       函数名缺失
subprogram_head ---> FUNCTION error formal_parameter ':' TYPE

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

end.
  • 预期结果

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

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

    1.4.2 缺少冒号

    subprogram_head —-> FUNCTION IDENTIFIER formal_parameter error TYPE
  • 测试用例 ```pascal program test(input,output); var b:real; function fun(a:integer)integer; begin end; begin

end.


- 预期结果

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

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected TYPE, expecting ':', location: 3.24  <br />3.  syntax error, missing a colon here, location: 3.23  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="wL8aI"></a>
### 1.4.3       缺少基本类型关键字
subprogram_head ---> FUNCTION IDENTIFIER formal_parameter ':' error

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

end.
  • 预期结果

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

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

    1.4.4 不完整的函数头

    subprogram_head —-> FUNCTION error
  • 测试用例 ```pascal program test(input,output); var b:real; function; begin end; begin

end.


- 预期结果

遇到错误时报告“函数头不完整”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected ';', expecting IDENTIFIER, location: 3.9  <br />3.  syntax error, incomplete **function** head, location: 3.1-3.9  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="ATXEs"></a>
### 1.4.5       不完整的过程头
subprogram_head ---> PROCEDURE error

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

end.
  • 预期结果

遇到错误时报告“过程头不完整”,并报告错误所在的具体位置,行号和列号。

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

    1.5测试formal_parameter

    正确表达式为:formal_parameter —-> ‘(‘ parameter_list ‘)’ | empty

    1.5.1 不完整的形参列表

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

end.


- 预期结果

遇到错误时报告“形参列表不完整”,并报告错误所在的具体位置,行号和列号。

- 测试结果

1.  Here **is** the syntax error information  <br />2.  syntax error, unexpected ';', expecting VAR **or** IDENTIFIER, location: 3.15  <br />3.  syntax error, incomplete formal parameter list, location: 3.14-3.15  <br />测试结果与预期一致,可以看到错误被成功识别并报告了正确位置,第一行为yacc自带的yyerror函数结果,第二行为自行使用函数重载进行错误处理的结果。
<a name="plk1N"></a>
### 1.5.2       右括号缺失
formal_parameter ---> '(' parameter_list error

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

end.
  • 预期结果

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

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

    1.6测试parameter_list

    正确表达式为:parameter_list —-> parameter_list ‘;’ parameter | parameter

    1.6.1 缺少分号

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

end. ```

  • 预期结果

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

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