ACL 2025finding0 citations

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

Qingyuan Liang, Zhao Zhang, Zeyu Sun, Zheng Lin, Qi Luo, Xiao Yueyi, Yizhou Chen, Yuqun Zhang

Abstract

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.

BibTeX
@inproceedings{liang-etal-2025-grammar,
    title = "Grammar-Based Code Representation: Is It a Worthy Pursuit for {LLM}s?",
    author = "Liang, Qingyuan  and
      Zhang, Zhao  and
      Sun, Zeyu  and
      Lin, Zheng  and
      Luo, Qi  and
      Yueyi, Xiao  and
      Chen, Yizhou  and
      Zhang, Yuqun  and
      Zhang, Haotian  and
      Zhang, Lu  and
      Chenbin, Chenbin  and
      Xiong, Yingfei",
    editor = "Che, Wanxiang  and
      Nabende, Joyce  and
      Shutova, Ekaterina  and
      Pilehvar, Mohammad Taher",
    booktitle = "Findings of the Association for Computational Linguistics: ACL 2025",
    month = jul,
    year = "2025",
    address = "Vienna, Austria",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2025.findings-acl.807/",
    doi = "10.18653/v1/2025.findings-acl.807",
    pages = "15640--15653",
    ISBN = "979-8-89176-256-5"
}