Skip to main content
LawSphereX

Grammar-Based Code Representation: Is It a Worthy Pursuit for LLMs?

Subject: Language and Linguistics

Author or source: Qingyuan Liang, Zhao Zhang, Zeyu Sun, Zheng Lin, Qi Luo, Yueyi Xiao, Yizhou Chen, Yuqun Zhang, Haotian Zhang, Lu Zhang, Bin Chen, Yingfei Xiong

Updated:

To explore this, we develop a series of billion-scale GrammarCoder models, incorporating grammar rules in the code generation process.

Qingyuan Liang, Zhao Zhang, Zeyu Sun, Zheng Lin, Qi Luo, Yueyi Xiao, Yizhou Chen, Yuqun Zhang, Haotian Zhang, Lu Zhang, Bin Chen, Yingfei Xiong. 2025. Grammar-Based Code Representation: Is It a Worthy Pursuit for LLMs?. Findings of the Association for Computational Linguistics: ACL 2025. Association for Computational Linguistics. DOI 10.18653/v1/2025.findings-acl.807. CC BY 4.0. Original PDF and author abstract are reproduced unchanged apart from whitespace in the abstract. LawSphereX prepared the reading prompt and cover. No endorsement implied.

Publication sources

Authors’ abstract

Source page 1–14

Grammar serves as a cornerstone in programming languages and software engineering, providing frameworks to define the syntactic space and program structure. Existing research demonstrates the effectiveness of grammar-based code representations in small-scale models, showing their ability to reduce syntax errors and enhance performance. However, as language models scale to the billion level or beyond, syntax-level errors become rare, making it unclear whether grammar information still provides performance benefits. To explore this, we develop a series of billion-scale GrammarCoder models, incorporating grammar rules in the code generation process. Experiments on HumanEval (+) and MBPP (+) demonstrate a notable improvement in code generation accuracy. Further analysis shows that grammar-based representations enhance LLMs’ ability to discern subtle code differences, reducing semantic errors caused by minor variations. These findings suggest that grammar-based code representations remain valuable even in billion-scale models, not only by maintaining syntax correctness but also by improving semantic differentiation.

Reading guide for language and linguistics

Source page 1–14

Identify the language phenomenon and how the authors annotate or measure it. Check whether the examples support the conclusions for other settings.