Skip to content

Commit fed8302

Browse files
committed
修改开头的产生式规则,使其正确匹配
1 parent 10cd389 commit fed8302

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

semantic_syntactic_analyzer/3.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
program example5;
2+
begin
3+
var A,B,C,D,W:integer;
4+
begin
5+
A:= 1; B:= 5; C:= 3; D:= 4; W:=1;
6+
if W>=1 then A:=B*C+B/D
7+
else repeat A:=A+1 until A<0
8+
end.

semantic_syntactic_analyzer/parser.y

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,26 @@ extern int iserror = 0;
3939

4040
// ---------------------------1 程序定义--------------------------------------
4141
// 1.1 <程序> → program <标识符> ; | program
42-
program : PROGRAM program_name SEMI program
43-
44-
| VAR var_definition program
45-
{
46-
// printf("\033[36m[info]\033[0m Variable Declaration: of type integer.\n"); // 只作提示,以后要删除
47-
}
48-
| BEG statement
42+
43+
program : PROGRAM program_name SEMI VAR var_definition BEG statement
4944
{
50-
// printf("\033[36m[info]\033[0m BEGIN\n"); // 只作提示,以后要删除
45+
// printf("\033[36m[info]\033[0m Start analyzing.\n"); // 只作提示,以后要删除
5146
}
5247
;
5348

49+
// 以下是另一种实现方法,两种都可以顺利完成识别
50+
// program : PROGRAM program_name SEMI next_a
51+
52+
// next_a : VAR var_definition next_b
53+
// {
54+
// // printf("\033[36m[info]\033[0m Variable Declaration: type integer.\n"); // 只作提示,以后要删除
55+
// }
56+
// next_b : BEG statement
57+
// {
58+
// // printf("\033[36m[info]\033[0m BEGIN\n"); // 只作提示,以后要删除
59+
// }
60+
// ;
61+
5462
program_name : id {
5563
prog_name = $1.lexeme;
5664
// printf("(%d) (program,%s,-,-)\n", quad_ruple_count, $1.lexeme); // 弃用的输出

0 commit comments

Comments
 (0)