Casting types restriction using grammar