# spoc_searchbased_pseudocode_to_code__34ffb89b.pdf SPo C: Search-based Pseudocode to Code Sumith Kulal , Panupong Pasupat , Kartik Chandra, Mina Lee, Oded Padon, Alex Aiken, Percy Liang Department of Computer Science Stanford University {sumith,ppasupat,kach,minalee,padon,aaiken,pliang}@cs.stanford.edu We consider the task of mapping pseudocode to executable code, assuming a oneto-one correspondence between lines of pseudocode and lines of code. Given test cases as a mechanism to validate programs, we search over the space of possible translations of the pseudocode to find a program that compiles and passes the test cases. While performing a best-first search, compilation errors constitute 88.7% of program failures. To better guide this search, we learn to predict the line of the program responsible for the failure and focus search over alternative translations of the pseudocode for that line. For evaluation, we collected the SPo C dataset (Search-based Pseudocode to Code) containing 18,356 C++ programs with humanauthored pseudocode and test cases. Under a budget of 100 program compilations, performing search improves the synthesis success rate over using the top-one translation of the pseudocode from 25.6% to 44.7%. 1 Introduction We consider the task of mapping natural language pseudocode to functionally correct computer programs that are long enough to have significant intermediate state (e.g., 10 20 lines) and perform non-trivial computations. Previous work on executable semantic parsing mainly focuses on translating short text descriptions to one-line programs [57, 47, 58, 59, 29, 11], and while recent work explored generating longer programs from text descriptions [30, 54, 39, 18, 19, 17], these programs are mostly evaluated on syntactic metrics (e.g., exact match and BLEU score) rather than functional correctness. In contrast, the program synthesis community emphasizes functional correctness, typically captured by a set of input-output test cases that the program must compute correctly [14, 13]. However, input-output pairs give no information about the intermediate states of the program, making it difficult to synthesize long programs. Synthesizing a general class of programs of significant length and internal complexity is too challenging without some description of the steps of computation. To that end, we propose synthesizing programs from natural language pseudocode and test cases. The test cases provide the functional specification, while the pseudocode provides guidance for the intermediate computations the program should perform. To synthesize a functionally correct program, instead of relying on the top-one translation of the pseudocode, we search over the space of possible translations to find one that passes the test cases. In this work, we view the desired program as a composition of segments of code, each aligned to a segment of natural language in the pseudocode. Figure 1 instantiates our setup: each pseudocode line translates to a line of code with approximately one or two atomic statements. Unlike treating the whole program as a single big chunk (too coarse) or decomposing into individual tokens (too fine-grained), semantically coherent segments of code (rendered as single lines here) form a natural Equal contribution. 33rd Conference on Neural Information Processing Systems (Neur IPS 2019), Vancouver, Canada. 1 in function main int main() { 2 let n be integer int n; 3 read n cin >> n; 4 let A be vector of integers vector A; 5 set size of A = n A.resize(n); 6 read n elements into A for(int i = 0; i < A.size(); i++) cin >> A[i]; 7 for all elements in A for(int i = 0; i < A.size(); i++) { 8 set min_i to i int min_i = i; 9 for j = i + 1 to size of A exclusive for(int j = i+1; j < A.size(); j++) { 10 set min_i to j if A[min_i] > A[j] if(A[min_i] > A[j]) { min_i = j; } 11 swap A[i], A[min_i] swap(A[i], A[min_i]); 12 print all elements of A for(int i=0; i