?? 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)
//此范圍為變量名(標識符)的內(nèi)碼范圍
{
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)
//此范圍為變量名(標識符)的內(nèi)碼范圍
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)
//此范圍為變量名(標識符)的內(nèi)碼范圍
{
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)
//此范圍為變量名(標識符)的內(nèi)碼范圍
{
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)
//此范圍為變量名(標識符)的內(nèi)碼范圍
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
factsuff();
}
else
if(Code>=BEGIN_OF_C+1&&Code<=BEGIN_OF_C+MAX_NUM_OF_C)
//此范圍為常量的內(nèi)碼范圍
{
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種比較運算符的內(nèi)碼連在一起的
{
infile>>Code;
infile>>buff;cout<<buff<<endl;
}
else error(41);
}
///////////////////////////////////////////////////////////////
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -