GramTrans: A Better Code Representation Approach in Code Generation

Zhao Zhang, Qingyuan Liang, Zeyu Sun, Yizhou Chen, Guoqing Wang, Yican Sun, Lu Zhang, Ge Li, Yingfei XiongarXiv 2025 · DOI

Abstract

Recent advancements in code generation have highlighted the importance of code representation. This paper introduces GramTrans, a framework designed to optimize code representations by reducing their parsing difficulty. By transforming complex code grammars into simpler LL(1) structures, GramTrans enables Large Language Models (LLMs) to allocate more cognitive capacity to logic and problem-solving rather than syntactic decoding. Our results demonstrate significant performance improvements across major benchmarks, including HumanEval and MBPP, using models like StarCoder and Qwen2.5.

Introduction

In AI-assisted coding, Large Language Models (LLMs) typically process code as plain text or sequences derived from abstract syntax trees. However, the impact of the representation's syntactic complexity on model performance has remained largely unexplored. This paper addresses the "parsing difficulty" gap, proposing that if a model must expend significant internal resources to parse a representation, its capacity for semantic reasoning is diminished. The authors identify a fundamental need for code representations that are mathematically "easy" for a model to interpret without sacrificing token efficiency.

The GramTrans Framework

The core hypothesis of this work is that easier-to-parse representations lead to better neural model performance. To test this, the authors categorize grammars by their complexity, ranging from simple LL(1) to complex non-context-free grammars.

Hierarchy of Grammar Classes

GramTrans automates the conversion of standard Context-Free Grammars (CFG) into LL(1) grammars. LL(1) grammars are considered the "gold standard" for simplicity because they can be parsed deterministically with a single-token lookahead. The transformation process involves:

  1. Hierarchical Conflict Elimination: Resolving ambiguities by iteratively expanding rules and introducing new terminal symbols to clear up parsing conflicts.
  2. Flexible Trade-offs: A "1-layer" variant is introduced to balance syntactic simplicity with token efficiency, avoiding the excessive sequence lengths sometimes caused by full LL(1) conversion.
  3. Bidirectional Translation: A robust translator maps original code to the simplified representation for training and back to standard code for execution.
Examples of Code Representations across different Grammar Classes

Experimental Setup and Results

We validated GramTrans using several benchmarks, including MathQA for controlled experiments, and industry standards like HumanEval and MBPP for Python, as well as HumanEval-X for Java. The models tested included StarCoder 1B, DeepSeek-Coder 1.3B, and Qwen2.5 1.5B.

Our experiments revealed a near-perfect correlation: as parsing difficulty increases, model performance (measured by pass@1) decreases. By "pre-digesting" the code structure, GramTrans allows models to focus on semantic reasoning. Key performance gains include:

  • StarCoder 1B: Python pass@1 improved from 62.2% (plain text) to 66.4%.
  • Qwen2.5 1.5B: Achieved 67.3% with the 1-layer variant, compared to 63.4% for plain text.
  • Java Generalization: DeepSeek and Qwen2.5 saw improvements of 3.1% and 4.3% respectively on Java benchmarks, proving the method is language-agnostic.

The "1-layer" variant emerged as a "sweet spot," providing most of the benefits of LL(1) with only a 4-5% increase in token count, proving more effective than previous aggressive compression methods.

Conclusion

GramTrans demonstrates that clarifying syntactic structure is more beneficial for code generation than simple text compression. While full LL(1) transformation can introduce token overhead, the 1-layer approach offers a highly efficient alternative that maintains sequence lengths nearly identical to plain text. Future work will explore scaling these findings to larger models (70B+) and more complex, dynamic programming languages.

Summary updated

BibTeX
@misc{zhang2025gramtrans,
  author = {Zhao Zhang and Qingyuan Liang and Zeyu Sun and Yizhou Chen and Guoqing Wang and Yican Sun and Lu Zhang and Ge Li and Yingfei Xiong},
  title = {{GramTrans: A Better Code Representation Approach in Code Generation}},
  year = {2025},
  eprint = {2510.02887},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.02887},
}
Figure