📄 for.cpp
字号:
//分析for循环语句
#include "Parser.h"
int Sen_For()
{
int RTN_ADDR = lineOfEqu + 1;
GetNextSymble();
int initValue = Sen_Assign();
int targetValue = 0;
int rtn1 = 0;
if(curr_code == 22) //是否为to
{
GetNextSymble();
if(curr_code == 27 || curr_code == 28) //为整数或标志符
{
targetValue = curr_addr;
GetNextSymble();
if(curr_code == 8) //是否为do
{
GetNextSymble();
int TRUE_ADDR = EquPush(10, initValue, targetValue, 0);
int FALSE_ADDR = EquPush(6, 0, 0, 0);
switch(curr_code)
{
case 27: //标志符,说明是赋值语句
Sen_Assign();
rtn1 = expr_rtn_addr;
break;
case 12:
rtn1 = Sen_For(); //for语句
break;
case 13: //if语句
rtn1 = Sen_If();
break;
case 20: //repeat循环语句
rtn1 = Sen_Repeat();
break;
case 26: //while循环语句
rtn1 = Sen_While();
break;
case 2: //begin
rtn1 = Begin();
break;
default: //其他语句为错误
Error(COMMON_ERROR);
break;
}
BackPatch(TRUE_ADDR, rtn1);
int tt = New_Temp();
EquPush(2, initValue, ONE, tt);
EquPush(1, tt, 0, initValue);
EquPush(6, 0, 0, RTN_ADDR);
BackPatch(FALSE_ADDR, lineOfEqu + 1);
}
else
{
Error(FOR_ERROR);
}
}
else
{
Error(FOR_ERROR);
}
}
else
{
Error(FOR_ERROR);
}
return RTN_ADDR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -