資源簡介
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<<‘?‘<
評論
共有 條評論