end
end
begin
end
如何检查出是否配对正确,错误情形很多,
1、缺少end与之配对
begin
//end
2、缺少begin与之配对
//begin
end
3、多end或者多begin
begin
begin
end
end
end
类似这些错误,如何检查出这些错误呢 ------解决方案-------------------- 最基本的,一个栈,遇到Begin压栈,遇到end弹栈. ------解决方案-------------------- ------解决方案--------------------
差不多吧,当栈里面没有东西还要popup就报错,更简单的可以用一个变量
i:=0;
while file is not EOF do
begin
read next word;
if next word is 'begin' then
i:=i+1;
if next word is 'end' then
i:= i-1;
if i<0 then
raise error
end;
麻烦的倒是要先清注释,再清掉字符串常量 ------解决方案--------------------
差不多吧,当栈里面没有东西还要popup就报错,更简单的可以用一个变量
i:=0;
while file is not EOF do
begin
read next word;
if next word is 'begin' then
i:=i+1;
if next word is 'end' then
i:= i-1;
if i<0 then
raise error
end;
麻烦的倒是要先清注释,再清掉字符串常量