GramTrans: A Better Code Representation Approach in Code Generation

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Zhang, Zhao, Liang, Qingyuan, Sun, Zeyu, Chen, Yizhou, Wang, Guoqing, Sun, Yican, Zhang, Lu, Li, Ge, Xiong, Yingfei
Format: Preprint
Publié: 2025
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866918153720692736
author Zhang, Zhao
Liang, Qingyuan
Sun, Zeyu
Chen, Yizhou
Wang, Guoqing
Sun, Yican
Zhang, Lu
Li, Ge
Xiong, Yingfei
author_facet Zhang, Zhao
Liang, Qingyuan
Sun, Zeyu
Chen, Yizhou
Wang, Guoqing
Sun, Yican
Zhang, Lu
Li, Ge
Xiong, Yingfei
contents Code generation has shown great promise in assisting software development. A fundamental yet underexplored question is how the choice of code representation affects model performance. While existing studies employ various representations, such as treating code as plain text, grammar rule sequences, or syntax tree sequences, they lack a principled understanding of the relationship between parsing difficulty and model effectiveness. This paper proposes a conjecture: the easier a representation is to parse, the better performance the model achieves. We formalize this idea using grammar classes, where representations in simpler classes (e.g., LL(1)) are easier to parse. Through a controlled experiment on a Python-based DSL, we show that parsing difficulty strongly correlates with model performance. Motivated by this finding, we present GramTrans, a general approach that automatically transforms a context-free language into a representation within the LL(1) class. GramTrans introduces a novel hierarchical conflict elimination algorithm, enabling a flexible trade-off between syntactic simplicity and token efficiency. We evaluate GramTrans on both Python and Java using three code generation models: StarCoder 1B, DeepSeek-Coder 1.3B, and Qwen2.5 1.5B. Across multiple benchmarks, GramTrans consistently delivers significant improvements over baseline representations. Furthermore, our analysis of existing representations reconfirms the strong alignment between parsing difficulty and model performance, providing additional support for the conjecture.
format Preprint
id arxiv_https___arxiv_org_abs_2510_02887
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle GramTrans: A Better Code Representation Approach in Code Generation
Zhang, Zhao
Liang, Qingyuan
Sun, Zeyu
Chen, Yizhou
Wang, Guoqing
Sun, Yican
Zhang, Lu
Li, Ge
Xiong, Yingfei
Software Engineering
Code generation has shown great promise in assisting software development. A fundamental yet underexplored question is how the choice of code representation affects model performance. While existing studies employ various representations, such as treating code as plain text, grammar rule sequences, or syntax tree sequences, they lack a principled understanding of the relationship between parsing difficulty and model effectiveness. This paper proposes a conjecture: the easier a representation is to parse, the better performance the model achieves. We formalize this idea using grammar classes, where representations in simpler classes (e.g., LL(1)) are easier to parse. Through a controlled experiment on a Python-based DSL, we show that parsing difficulty strongly correlates with model performance. Motivated by this finding, we present GramTrans, a general approach that automatically transforms a context-free language into a representation within the LL(1) class. GramTrans introduces a novel hierarchical conflict elimination algorithm, enabling a flexible trade-off between syntactic simplicity and token efficiency. We evaluate GramTrans on both Python and Java using three code generation models: StarCoder 1B, DeepSeek-Coder 1.3B, and Qwen2.5 1.5B. Across multiple benchmarks, GramTrans consistently delivers significant improvements over baseline representations. Furthermore, our analysis of existing representations reconfirms the strong alignment between parsing difficulty and model performance, providing additional support for the conjecture.
title GramTrans: A Better Code Representation Approach in Code Generation
topic Software Engineering
url https://arxiv.org/abs/2510.02887