Research indexPreprint
Syntax and Type-Guided Code Generation: Enhancing LLM-Based Java Program Synthesis through Formal Language Constraints
Enea
Zenodo (CERN European Organization for Nuclear Research)15 Oct 2024Open access
NobleIDark:/48914/w1/20260515/F8642EDEDOI10.5281/zenodo.17372496
Syntax and Type-Guided Code Generation: Enhancing LLM-Based Java Program Synthesis through Formal Language Constraints
Enea · Zenodo (CERN European Organization for Nuclear Research) · 2024
NobleIDark:/48914/w1/20260515/F8642EDEDOI10.5281/zenodo.17372496
Free to read at the publisher
You can read the abstract here, or the full text at the publisher.
Abstract
This paper presents a framework to improve the reliability of Large Language Models (LLMs) in code generation by integrating formal programming language properties into the decoding process. The proposed methods—Syntax-Guided Generation (SGG) and Type-Aware Generation (TAG)—use grammars and static type checking to ensure syntactic and semantic correctness in Java code. Experiments on HumanEval, MBPP, CodexGLUE, and a custom Java dataset show that syntax guidance reduces invalid code by up to 24%, type-aware constraints improve semantic accuracy by up to 22%, and combined methods boost functional correctness by up to 15%. This work bridges statistical language modeling and formal language theory, demonstrating that constraint-based generation enhances LLM code reliability.