Пример #1
0
void GDLNode::createOrNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		std::vector<PropositionNode*> propositions;
		for (size_t i = 1; i < tokenLines.size(); ++i) {
			try {
				if (tokenLines[i].getType() != TOKEN_LINE_RELATION && tokenLines[i].getType() != TOKEN_LINE_DISTINCT) {
					throw Exception("Syntax error: Or must have proposition as arguments. In line: " + tokenLine.toString());
				}
				
				PropositionNode *proposition;
				createPropositionNode(tokenLines[i], (GDLNode**)&proposition);
				propositions.push_back(proposition);
			} catch (Exception &e) {
				for (size_t i = 0; i < propositions.size(); ++i) {
					delete propositions[i];
				}
				throw e;
			}
		}
		*nodeOut = new OrNode(propositions);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Or node. In line: " + tokenLine.toString());
	}
}
Пример #2
0
void GDLNode::createDistinctNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	std::vector<Token> arguments;
	
	breakDownTokenLine(tokenLine, tokenLines);
	for (size_t i = 1; i < tokenLines.size(); ++i) {
		int type = tokenLines[i].getTokens()[0].getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Invalid arguments in Distinct. In line: " + tokenLine.toString());
		}
		arguments.push_back(tokenLines[i].getTokens()[0]);
	}
	*nodeOut = new DistinctNode(arguments);
}
Пример #3
0
void GDLNode::createInitNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	PropositionNode *proposition;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		if (tokenLines.at(1).getType() != TOKEN_LINE_RELATION) {
			throw Exception("Syntax error: Init must have proposition as argument. In line: " + tokenLine.toString());
		}
		
		createPropositionNode(tokenLines.at(1), (GDLNode**)&proposition);
		*nodeOut = new InitNode(proposition);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating init node. In line: " + tokenLine.toString());
	}
}
Пример #4
0
void GDLNode::createIfNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		GDLNode *head = createGDLNodes(tokenLines.at(1));
		std::vector<GDLNode*> body;
		for (size_t i = 2; i < tokenLines.size(); ++i) {
			GDLNode *b = createGDLNodes(tokenLines[i]);
			body.push_back(b);
		}
		*nodeOut = new IfNode(head, body);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating If node. In line: " + tokenLine.toString());
	}
}
Пример #5
0
void GDLNode::createGoalNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		int type = tokenLines.at(1).getTokens().at(0).getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Goal must have role as first argument. In line: " + tokenLine.toString());
		}
		if (tokenLines.at(2).getTokens().at(0).getType() != TOKENIZER_TOKEN_TYPE_TERM) {
			throw Exception("Syntax error: Goal must have value as second argument. In line: " + tokenLine.toString());
		}
		
		Token role = tokenLines[1].getTokens()[0];
		int value = stoi(tokenLines[2].getTokens()[0].getTokenStr());
		*nodeOut = new GoalNode(role, value);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Goal node. In line: " + tokenLine.toString());
	}
}
Пример #6
0
void GDLNode::createDoesNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		int type = tokenLines.at(1).getTokens().at(0).getType();
		if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
			throw Exception("Syntax error: Does must have role as first argument. In line: " + tokenLine.toString());
		}
		if (tokenLines.at(2).getType() != TOKEN_LINE_RELATION) {
			throw Exception("Syntax error: Does must have action as second argument. In line: " + tokenLine.toString());
		}
		
		Token role = tokenLines[1].getTokens()[0];
		PropositionNode *proposition;
		createPropositionNode(tokenLines[2], (GDLNode**)&proposition);
		*nodeOut = new DoesNode(role, proposition);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Does node. In line: " + tokenLine.toString());
	}
}
Пример #7
0
void GDLNode::createPropositionNode(const TokenLine &tokenLine, GDLNode **nodeOut) {
	std::vector<TokenLine> tokenLines;
	
	breakDownTokenLine(tokenLine, tokenLines);
	try {
		std::string name;
		std::vector<Token> arguments;
		
		name = tokenLines.at(0).getTokens().at(0).getTokenStr();
		for (size_t i = 1; i < tokenLines.size(); ++i) {
			int type = tokenLines.at(i).getTokens().at(0).getType();
			if (type != TOKENIZER_TOKEN_TYPE_TERM && type != TOKENIZER_TOKEN_TYPE_VAR) {
				throw Exception("Syntax error: Proposition '" + name + "' has incorrect arguments. In line: " + tokenLine.toString());
			}
			arguments.push_back(tokenLines.at(i).getTokens().at(0));
		}
		*nodeOut = new PropositionNode(name, arguments);
	} catch (std::out_of_range) {
		throw Exception("Syntax error while creating Proposition node. In line: " + tokenLine.toString());
	}
}