📄 main.cpp
字号:
infile>>buff;cout<<buff<<endl;
argument();
if(Code==SEM)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else
error(16);
}
else error(15);
}
}
/////////////////////////////////////
void argument()
{
if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code==ID)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code==COL)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
typeil();
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else
error(19);
}
else
error(18);
}
else
error(17);
}
}
////////////////////////////////////////////////////////
void procsuff()
{
if(Code==PROCEDURE)
{
procedh();
block();
if(Code==SEM)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
procsuff();
}
else
error(20);
}
}
////////////////////////////////////////////////////////
void assipro()
{
if(Code>=BEGIN_OF_V+1&&Code<=BEGIN_OF_V+MAX_NUM_OF_V)
//此范围为变量名(标识符)的内码范围
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
suffix();
}
else
error(21);
}
/////////////////////////////////////////////////////////
void sentence()
{
if(Code>=BEGIN_OF_V+1&&Code<=BEGIN_OF_V+MAX_NUM_OF_V)
//此范围为变量名(标识符)的内码范围
assipro();
else if(Code==IF)
ifsent();
else if(Code==WHILE)
whilsent();
else if(Code==READ)
read();
else if(Code==WRITE)
write();
else if(Code==BEGIN)
compsent();
}
/////////////////////////////////////////////////////
void suffix()
{
if(Code==ASS)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
}
else if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(22);
}
}
////////////////////////////////////////////////////////
void ifsent()
{
if(Code==IF)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
conditio();
if (Code==THEN)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
sentence();
}
else error(24);
}
else error(23);
}
/////////////////////////////////////////////////////////
void whilsent()
{
if(Code==WHILE)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
conditio();
if(Code==DO)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
sentence();
}
else error(26);
}
else error(25);
}
////////////////////////////////////////////////////////////
void read()
{
if(Code==READ)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code>=BEGIN_OF_V+1&&Code<=BEGIN_OF_V+MAX_NUM_OF_V)
//此范围为变量名(标识符)的内码范围
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
idsuff();
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(27);
}
else error(30);
}
else error(29);
}
else error(28);
}
/////////////////////////////////////////////////////////////
void idsuff()
{
if(Code==COM)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code>=BEGIN_OF_V+1&&Code<=BEGIN_OF_V+MAX_NUM_OF_V)
//此范围为变量名(标识符)的内码范围
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
idsuff();
}
else error(31);
}
}
///////////////////////////////////////////////////////////////
void write()
{
if(Code==WRITE)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
exprsuff();
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(34);
}
else error(33);
}
else error(32);
}
////////////////////////////////////////////////////////////////
void compsent()
{
if(Code==BEGIN)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
sentence();
sentsuff();
if(Code==END)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(36);
}
else error(35);
}
/////////////////////////////////////////////////////////////////
void exprsuff()
{
if(Code==COM)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
exprsuff();
}
}
//////////////////////////////////////////////////////////////////
void sentsuff()
{
if(Code==SEM)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
sentence();
sentsuff();
}
}
///////////////////////////////////////////////////////////////////
void conditio()
{
if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
//////
if(Code==ODD)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
}
else
{
express();
respoper();
express();
}
//////
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(42);
}
else error(43);
}
///////////////////////////////////////////////////////////////////
void express()
{
if(Code==ADD||Code==SUB)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
//可以有正负号,也可以没有
term();
termsuff();
}
////////////////////////////////////////////////////////////////////
void term()
{
factor();
factsuff();
}
////////////////////////////////////////////////////////////////////
void termsuff()
{
if(Code==ADD||Code==SUB)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
factor();
factsuff();
}
}
////////////////////////////////////////////////////////////////////
void factsuff()
{
if(Code==MUL||Code==DIV)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
factor();
factsuff();
}
}
//////////////////////////////////////////////////////////////////////
void factor()
{
if(Code>=BEGIN_OF_V+1&&Code<=BEGIN_OF_V+MAX_NUM_OF_V)
//此范围为变量名(标识符)的内码范围
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
factsuff();
}
else
if(Code>=BEGIN_OF_C+1&&Code<=BEGIN_OF_C+MAX_NUM_OF_C)
//此范围为常量的内码范围
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
factsuff();
}
else
if(Code==LBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
express();
if(Code==RBR)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(38);
}
else error(37);
}
///////////////////////////////////////////////////////////////
void addoper()
{
if(Code==ADD||Code==SUB)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(39);
}
///////////////////////////////////////////////////////////////
void muloper()
{
if(Code==MUL||Code==DIV)
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(40);
}
///////////////////////////////////////////////////////////////
void respoper()
{
if(Code>=EQU&&Code<=GEQ)//6种比较运算符的内码连在一起的
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(41);
}
///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -