Abstract:Automatically generating testcase is one of approaches to test compilers. Nowadays Purdom strategy is normally used to do it. In this paper, we define a graph called DG graph to describe a context-free grammar, and based on the graph, we propose a new strategy to generate automatically sentences to test compilers. And also we describe the principles of the implementation of the new strategy.