Refactored to make grammar more compact and parser more readable.