def parse_grammar(file_path):
	"""
	Generate a grammar from a file describing the production rules.
	Note that the symbols are inferred from the production rules.

	For more information on the format of the file, please reffer to
	the README.md or the the sample grammars provided in this repository.

	:param file_path: Path to the file containing the description of the grammar.
	:returns: the grammar object and the starting symbol.
	"""
	with open(file_path) as f:
		content = f.read().splitlines()

	if len(content) <= 1:
		raise Exception('Grammar should have at least one production rule and a starting symbol')

	# First line should be the starting symbol
	start_symbol = content[0]

	grammar = {}
	for line in content[1:]:
		# Each line should be in the format:
		# X -> A B ... C
		symbols = line.split()
		if len(symbols) <= 2 or symbols[1] != '->':
			raise Exception('Each production line should be in the format: X -> A B ... C')

		if symbols[0] not in grammar:
			grammar[symbols[0]] = []

		grammar[symbols[0]].append(symbols[2:])

	if start_symbol not in grammar:
		raise Exception('Grammar should have at leats one production rule with the start_symbol.')

	return grammar, start_symbol