trying to add logic to grammar