In this paper we present a novel algorithm, named GBAP, that jointly uses automatic programming with ant colony optimization for mining classification rules. GBAP is based on a context-free grammar that properly guides the search process of valid rules. Furthermore, its most important characteristics are also discussed, such as the use of two different heuristic measures for every transition rule, as well as the way it evaluates the mined rules. These features enhance the final rule compilation from the output classifier. Finally, the experiments over 17 diverse data sets prove that the accuracy values obtained by GBAP are pretty competitive and even better than those resulting from the top Ant-Miner algorithm.