资源简介
ege小游戏,用于借鉴和参考游戏开发,游戏内容是黑塔,一个以前很火的游戏
代码片段和文件信息
#include
#define TK_NUM 500
#define TK_ID 600
using namespace std;
class Parser{
public:
Parser(){
cin>>s;
lookahead=getToken();
expr();
}
int tokenval=0;
string id_buffer=““;
int lookahead=0;
int current=0;
string s;
void match(int t){
if(t==lookahead)lookahead=getToken();
else cout<<“error“;
}
void expr(){
factor();rest();
}
void rest(){
if(lookahead==‘+‘){
match(‘+‘);term();cout<<‘+‘;rest();
}else if(lookahead==‘-‘){
match(‘-‘);term();cout<<‘-‘;rest();
}else if(lookahead==‘*‘||lookahead==‘/‘){
last();rest();
}else if(lookahead==‘ ‘)cout<<‘\n‘;
}
void term(){
factor();last();
}
void last(){
if(lookahead==‘*‘){
match(‘*‘);factor();cout<<‘*‘;last();
}else if(lookahead==‘/‘){
match(‘/‘);factor();cout<<‘/‘;last();
}else if(lookahead==‘ ‘)cout<<‘\n‘;
}
void factor(){
if(lookahead==TK_ID){
cout<<‘ ‘< match(lookahead);
}else if(lookahead==TK_NUM){
cout<<‘ ‘<
评论
共有 条评论