Abstract
Natural language processing for programming aims to use NLP techniques to assist programming. It is increasingly prevalent for its effectiveness in improving productivity. Distinct from natural language, a programming language is highly structured and functional. Constructing a structure-based representation and a functionality-oriented algorithm is at the heart of program understanding and generation. In this paper, we conduct a systematic review covering tasks, datasets, evaluation methods, techniques, and models from the perspective of the structure-based and functionality-oriented property, aiming to understand the role of the two properties in each component. Based on the analysis, we illustrate unexplored areas and suggest potential directions for future work.
Introduction
The rise of Large Language Models (LLMs) has revolutionized how we approach software development. However, programming languages (PL) possess unique characteristics that distinguish them from natural languages (NL). Code is inherently structure-based, following strict hierarchical and nested rules, and functionality-oriented, meaning its primary purpose is execution to produce specific outputs. A single syntax error or a logical flaw can render a program useless, regardless of how "natural" it looks.
This survey provides a comprehensive roadmap of Natural Language Processing for Programming (NLP4P), framing the field through these two intrinsic properties. By categorizing tasks, datasets, and models under this dual-lens, we highlight the shift from treating code as simple text to treating it as a logical, executable entity.
Taxonomy of NLP4P Tasks
The core of this survey is a taxonomy that divides NLP4P tasks based on whether they prioritize structural understanding or functional correctness.
As shown in the taxonomy, tasks like Code Search and Summarization are primarily structure-based, focusing on understanding the "what" and "how" of the code. Conversely, tasks like Program Synthesis and Code Refinement are functionality-oriented, where the ultimate goal is achieving a specific computational result.
Methods for Program Understanding and Generation
To address these two properties, researchers have developed specialized techniques:
- Structure-based Understanding: Models are often enhanced with intermediate representations like Abstract Syntax Trees (AST), Control Flow Graphs (CFG), and Program Dependence Graphs (PDG). These allow the model to capture the underlying logic—such as loops and recursions—rather than just processing a flat sequence of tokens.
- Functionality-oriented Generation: To ensure generated code is executable and correct, techniques such as Self-Instruct (LLM-generated training data), Interactive Programming (feedback from interpreters), and Test-case-based Filtering are employed. The latter involves sampling multiple solutions and validating them against unit tests.
Datasets and Evaluation Metrics
Datasets in NLP4P range from massive, general-purpose crawls like The Stack to dedicated benchmarks like CodeSearchNet (for retrieval) and HumanEval (for execution-based generation).
A critical insight is the "Execution Gap": a model might achieve a high BLEU score (textual similarity) while producing code that fails to run. This has necessitated a shift toward execution-based metrics like Pass@k, which measures success based on passing unit tests rather than string matching.
Key Results and Performance Analysis
The effectiveness of incorporating structural and functional awareness is evident in benchmark results.
Models that explicitly incorporate structural information, such as CodeT5, UniXcoder, and GraphCodeBERT, significantly outperform vanilla Transformers on structure-based tasks like code search and clone detection. In functionality-oriented tasks, while structure-aware models perform well, pure scale (parameter count) and domain-specific fine-tuning (e.g., CodeLlama-Python) are dominant factors for achieving high functional correctness.
Future Directions
Despite significant progress, several challenges remain:
- Multilingual NLP4P: Expanding support for low-resource programming languages and non-English documentation.
- Multi-modal Specifications: Integrating visual inputs like diagrams and UI mockups into the code generation pipeline.
- Long-Context Processing: Moving beyond single functions to understand and maintain entire repositories with complex interdependencies.
By bridging the gap between structural representation and functional execution, the field of NLP4P continues to push the boundaries of automated software engineering.
Summary updated