コード例 #1
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::while_statement()
{
	PolizFunNOP* tmp = new PolizFunNOP;
	add_poliz_list(tmp);
	PolizItem* p = poliz_list;
	while (p->next!=0)
		p = p->next;
	expression();
	if (strcmp(cur->lex, "do") != 0)
		throw Exeption("do expexted", cur->num_str, cur->lex);
	PolizLabel* tmp1 = new PolizLabel(0, 0);
	add_poliz_list(tmp1);
	PolizItem* p1 = poliz_list;
	while (p1->next!=0)
		p1 = p1->next;
	PolizOpGoFalse* tmp2 = new PolizOpGoFalse;
	add_poliz_list(tmp2);
	next();
	S();
	if (strcmp(cur->lex, ";") != 0)
		throw Exeption("';' expected", cur->num_str, cur->lex);
	next();
	PolizLabel* tmp3 = new PolizLabel(0, p);
	add_poliz_list(tmp3);
	PolizOpGo* tmp4 = new PolizOpGo;
	add_poliz_list(tmp4);
	PolizFunNOP* tmp5 = new PolizFunNOP;
	add_poliz_list(tmp5);
	PolizItem* p2 = poliz_list;
	while (p2->next!=0)
		p2 = p2->next;
	PolizLabel *ptr = dynamic_cast<PolizLabel*>(p1->elem);
	ptr->set_addr(p2);
}
コード例 #2
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::op3()
{
	if (cur->type==number) {
		PolizInt* tmp = new PolizInt(atoi(cur->lex));
		add_poliz_list(tmp);
		next();
	} else
	if (cur->type==variable) {
		PolizString* tmp = new PolizString(cur->lex);
		add_poliz_list(tmp);
		next();
		if (strcmp(cur->lex, "[")==0) {
			next();
			expression();
			if (strcmp(cur->lex, "]")!=0)
				throw Exeption("']' expected", cur->num_str, cur->lex);
			next();
			add_index();
		} else 
			add_nul_index();
		PolizVar* tmp2 = new PolizVar;
		add_poliz_list(tmp2);
	}
	else
	if (cur->type==function_without_param) {
		PolizFunNoParam* tmp = new PolizFunNoParam(cur->lex);
		add_poliz_list(tmp);
		next();
	}
	else
	if (cur->type==function_with_param) {
		PolizFunParam* tmp = new PolizFunParam(cur->lex);
		next();
		if (strcmp(cur->lex, "(")!=0)
			throw Exeption("'(' expected in funct",
				cur->num_str, cur->lex);
		next();
		expression();
		if (strcmp(cur->lex, ")")!=0)
			throw Exeption("')' expected in funct",
				cur->num_str, cur->lex);
		next();
		add_poliz_list(tmp);
	}
	else
	{
		if (strcmp(cur->lex, "(")!=0)
			throw Exeption("'(' expected", cur->num_str, cur->lex);
		next();
		expression();
		if (strcmp(cur->lex, ")")!=0)
			throw Exeption("')' expected", cur->num_str, cur->lex);
		next();
	}
}
コード例 #3
0
void send_message(string message, int sockfd)
{
    string buff;
    buff = message;
    if(buff.size()>MAX_BUFFER_SIZE)
        throw Exeption("Too long message");
    int nwrite = write(sockfd, buff.c_str(), MAX_BUFFER_SIZE);
    if(nwrite<=0){
        throw Exeption("Connection error");
    }
}
コード例 #4
0
void build_server(int socketfd, struct sockaddr_in *server_address, int port_number)
{
	bzero((char *) server_address, sizeof(server_address));
	server_address->sin_family = AF_INET;
	server_address->sin_port = htons(port_number);
	server_address->sin_addr.s_addr = INADDR_ANY;

	if (bind(socketfd, (struct sockaddr *) server_address, sizeof(*server_address)) ==-1){ 
		throw Exeption("binding has problem!\n");
    }
	if(listen(socketfd,7)==-1)
		throw Exeption("problem in listening!");
}
コード例 #5
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::goto_statement()
{
	if (cur->type != label)
		throw Exeption("label expected", cur->num_str, cur->lex);
	PolizItem* item = search_address(cur->lex); // in label list
	PolizLabel* tmp = new PolizLabel(cur->lex, item);
	add_poliz_list(tmp);
	if (item == 0)
		add_label_list(0, cur->lex);
	next();
	if (strcmp(cur->lex, ";") !=0 )
		throw Exeption("';' expected", cur->num_str, cur->lex);
	next();
}
コード例 #6
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::analyze()
{
	next();
	S();
	if (strcmp(cur->lex, ".")!=0)
		throw Exeption("dot expected", cur->num_str, cur->lex);
}
コード例 #7
0
void connect(char* ip, int port, int* socketfd)
{
	int char_number;
	struct sockaddr_in server_address;
	struct hostent *server;

	*socketfd = socket(AF_INET, SOCK_STREAM, 0);
	bzero((char *) &server_address, sizeof(server_address));
	if (*socketfd < 0) 
		throw Exeption("Server not found");
	server = gethostbyname(ip);
	if (server == 0)
		throw Exeption("Perver not found");
	server_address.sin_family = AF_INET;
	bcopy((char *)server->h_addr, (char *)&server_address.sin_addr.s_addr,server->h_length);
	server_address.sin_port = htons(port);
	if (connect(*socketfd,(struct sockaddr *)&server_address,sizeof(server_address)) == -1) 
		throw Exeption("Connection error");
}
コード例 #8
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::print_statement()
{
	if (cur->type == string) {
		PolizString* tmp = new PolizString(cur->lex);
		add_poliz_list(tmp);
		next();
	}
	else
		expression();
	if (strcmp(cur->lex, ";") !=0 )
		throw Exeption("';' expected", cur->num_str, cur->lex);
	next();
}
コード例 #9
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::assignment_statement()
{
	if (cur->type == assignment) {
		add_nul_index();
		next();
	} else
	if (strcmp(cur->lex, "[")==0) {
		next();
		expression();
		if (strcmp(cur->lex, "]")!=0)
			throw Exeption("']' expected", cur->num_str, cur->lex);
		next();
		if (cur->type != assignment)
			throw Exeption("':=' expected", cur->num_str, cur->lex);
		next();
		add_index();
	}
	else
		throw Exeption("':=' or index expected",cur->num_str, cur->lex);
	expression();
	if (strcmp(cur->lex,";")!=0)
		throw Exeption("';' expected", cur->num_str, cur->lex);
	next();
}
コード例 #10
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::game_statement()
{
	if (strcmp(cur->lex, "endturn")==0) {
		PolizEndTurn* tmp = new PolizEndTurn();
		add_poliz_list(tmp);
		next();
	} else
	if ((strcmp(cur->lex,"prod")==0)||(strcmp(cur->lex,"build")==0)) {
		bool is_prod = false;
		if (strcmp(cur->lex, "prod")==0) is_prod = true;
		next();
		expression();
		if (is_prod) {
			PolizProd* tmp = new PolizProd();
			add_poliz_list(tmp);
		} else {
			PolizBuild* tmp = new PolizBuild();
			add_poliz_list(tmp);
		}
	}
	else
	if ((strcmp(cur->lex,"buy")==0)||(strcmp(cur->lex,"sell")==0)) {
		bool is_buy = false;
		if (strcmp(cur->lex, "buy")==0) is_buy = true;
		next();
		expression();
		expression();
		if (is_buy) {
			PolizBuy* tmp = new PolizBuy();
			add_poliz_list(tmp);
		} else {
			PolizSell* tmp = new PolizSell();
			add_poliz_list(tmp);
		}
	}
	if (strcmp(cur->lex,";")!=0)
		throw Exeption("';' expected", cur->num_str, cur->lex);
	next();
}
コード例 #11
0
ファイル: syntax.cpp プロジェクト: yura603/game-manager
void SyntaxAnalyzer::S()
{
	if ((cur->type == keyword)&&
		(strcmp(cur->lex, "end")!=0)) {
		if (strcmp(cur->lex, "if")==0) {
			next();
			if_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "while")==0) {
			next();
			while_statement();
			S();
		}
		else
		if (strcmp(cur->lex, "goto")==0) {
			next();
			goto_statement();
			PolizOpGo* tmp = new PolizOpGo;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "print")==0) {
			next();
			print_statement();
			PolizPrint* tmp = new PolizPrint;
			add_poliz_list(tmp);
			S();
		}
		else
		if (strcmp(cur->lex, "then")!=0) {
			game_statement();
			S();
		}
		else
			throw Exeption("unexpected then", cur->num_str, cur->lex);
	}
	else
	if (cur->type == variable) {
		make_poliz_var();
		next();
		assignment_statement();
		PolizFunAssign* tmp = new PolizFunAssign;
		add_poliz_list(tmp);
		S();
	}
	else
	if (cur->type == label) {
		make_poliz_label();
		next();
		if (strcmp(cur->lex, ">")!=0)
			throw Exeption("'>' expected", cur->num_str, cur->lex);
		next();
		S();
	}
	else {
	if (strcmp(cur->lex, "end")!=0)
		throw Exeption("end expected", cur->num_str, cur->lex);
	else
		next();
	}
}