acceptodds
Published as a conference paper at NeurIPS 2026

Synsema: Syntax-Guided Learning of Semantically Valid Programs

Levin Winter, Cong Li, Hao Sun, Zhendong Su

Abstract

Generating inputs for systems that process highly structured data, such as compilers, is difficult due to the dual of syntactic and semantic constraints. Traditional approaches rely on manually crafted rules that require deep domain expertise and are difficult to maintain, while modern machine learning methods have to learn syntax and semantics simultaneously which is challenging. We present Synsema, a novel approach that combines insights from both worlds by reformulating the generation of semantically valid programs as a syntax-guided reinforcement learning task. By guaranteeing syntactic validity through the grammar, the agent needs to only learn the language's semantic rules, sampling from a drastically reduced space. We implement our approach in the context of Java and Rust which both exhibit strict semantic requirements, and train an agent to generate interesting and well-formed programs using fine-grained semantic feedback. Applied to compiler testing, we systematically compare different syntax-guided generation procedures with an unconstrained baseline and show that by restricting the sampling space, Synsema learns semantic rules efficiently. While an average of only 0.03% of programs generated by the baseline are semantically valid, Synsema produces a diverse set of programs with a 7.29% success rate that trigger 2.6x more compiler behaviors. In addition, Synsema discovered 5 previously unknown bugs in production compilers, validating the practical impact of our approach.

Keywords:
Sydney, Main Track

Reviews

Among:
Shape:
123456this paper, Bottom 4%
Figure 1. Mean review rating of the reviewed papers at NeurIPS 2026. This paper averages 3.67 over 3 reviews, above 4% of the others.
Reviewer_4xXLOpenReview ↗
Rating
3
Clarity
3
Confidence
4
Originality
3
Quality
2
Significance
2
Read review
Summary

The authors argue that existing learning-based approaches must simultaneously learn both syntax and semantics, which is highly inefficient because syntactically valid programs occupy only a tiny fraction of the overall token space. To address this issue, the paper proposes SYNSEMA, a syntax-guided reinforcement learning framework that explicitly separates syntactic correctness from semantic learning. The key idea is to leverage a context-free grammar (CFG) to constrain the action space of an RL agent such that all generated programs are syntactically valid by construction. Under this formulation, the agent only needs to learn semantic constraints through compiler feedback. This paper presents an interesting integration of grammar-based generation and reinforcement learning for program synthesis and compiler fuzzing. The paper explores three grammar-guided generation mechanisms based on top-down (LL), bottom-up (LR), and chart-based (Earley) parsing algorithms, resulting in different action representations and constrained action spaces. Semantic learning is driven by compiler-derived rewards, including penalties based on compilation diagnostics and positive rewards derived from compiler coverage novelty. In experiments, the authors verify that constraining the generation process with syntax substantially reduces the search space and enables more effective learning of semantic validity compared to unconstrained token-level generation.

Strengths and weaknesses

Strengths

  1. The paper presents a clean and intuitive formulation that separates syntactic validity from semantic learning by incorporating grammar constraints into the reinforcement learning process. The overall framework is easy to understand and well motivated for compiler testing.

  2. The paper evaluates multiple grammar-guided generation strategies based on different parsing algorithms and demonstrates the practical utility of the approach on real-world compilers.

Weaknesses

  1. A central claim of the paper is that the proposed framework learns program semantics. However, the evidence provided mainly demonstrates improved compilation success rates. The reward signal is entirely derived from compiler acceptance, diagnostics, and coverage information, making it unclear whether the model learns semantic concepts or simply learns to generate patterns that satisfy compiler-specific validity checks. More broadly, compilation success is a relatively weak proxy for semantic understanding.

  2. It is unclear whether syntax-guided constraints need to be incorporated during training at all. Many modern constrained generation approaches enforce syntactic validity during decoding by masking invalid tokens according to a grammar while leaving the underlying model training unchanged. The paper does not provide evidence that integrating grammar constraints into the RL training process yields benefits beyond what could be achieved through inference-time constrained decoding alone. As a result, the necessity of the proposed training formulation remains insufficiently justified.

  3. The experimental setting focuses exclusively on unconditional program generation. Without any specification, prompt, or downstream task, it is difficult to assess whether the model has learned meaningful semantic relationships beyond compiler acceptance patterns. Furthermore, unconditional generation substantially limits the practical applicability of the framework compared to more realistic program-generation settings where generation is conditioned on user intent, requirements, or existing code context.

  4. The empirical evaluation is conducted using a randomly initialized GPT-2 model with only 124M parameters. Given that contemporary code generation systems are typically built upon substantially larger pretrained models, it remains unclear whether the observed findings would transfer to modern foundation models. Consequently, the practical relevance of the proposed approach in today's code-generation landscape is somewhat limited.

Questions
  1. The proposed approach relies on context-free grammars and parser-specific structures (e.g., LL/LR productions and parsing tables). How were these grammars and parsing tables obtained for Rust and Java in practice? Were they directly derived from existing compiler specifications, automatically generated from publicly available grammar definitions, or manually adapted? Additionally, how much engineering effort is required when extending the framework to a new programming language?

  2. A central claim of the paper is that the agent learns semantic constraints. Could the authors provide additional evidence that the learned behavior goes beyond merely generating compiler-accepted patterns? For example, are there analyses showing that the model learns specific semantic concepts (e.g., typing rules, scope resolution, ownership constraints) rather than simply exploiting frequent compilable structures?

  3. What advantages are gained by incorporating grammar constraints during RL training rather than applying grammar-constrained decoding only at inference time? Have the authors considered or evaluated a baseline where the model is trained normally and syntax validity is enforced solely through decoding-time masking?

  4. The experiments are conducted using a randomly initialized GPT-2 model with 124M parameters. Do the authors expect the proposed framework to remain beneficial when applied to modern pretrained code models or large language models that already possess substantial syntactic and semantic knowledge? If so, what modifications would be necessary to integrate SYNSEMA with such models?

Limitations

yes

Paper formatting concerns

N/a

Reviewer_dRJbOpenReview ↗
Rating
4
Clarity
3
Confidence
4
Originality
2
Quality
3
Significance
2
Read review
Summary

This paper presents an approach for generating test cases, or inputs, for testing compilers. The challenge here is generating "good" inputs, that is, well-formed programs that exercise all code paths of the compiler.

The main idea is to force the generators to only produce well-formed programs. For most programming languages, getting accepted by a context-free grammar (CFG) is the most basic constraint. The CFG is used to constrain the next token -- thus, the action space is constrained so that only syntactically well-formed programs are ever generated. Generating syntactically well-formed programs is not enough, one needs to generate programs that also pass some semantic checks enforced by the compiler, and furthermore, generate programs that activate new code paths in the compiler. The compiler is used to generate a reward that is used in an RL loop to update the policy.

The paper evaluates this idea to test Rust and Java compilers. They report finding 5 new bugs in these compilers.

Strengths and weaknesses

The paper presents a potent technique for bug finding in compilers. The overall approach sounds reasonable and each constituent is reasonably justified. The evaluation results are good; in particular, the fact that the authors found 14 crashes out of which 5 are new crashes is indeed impressive and shows the value of the approach.

The approach for generating syntactically correct programs reminds me of the ICLR 2022 paper titled Synchromesh. The authors can consider discussing it - especially since it also "enforced" syntactic (and some semantic) correctness by constraining next token using CFG parsing technology.

One interesting aspect of this work is the "bi-modal" reward - when the compiler detects an error, the problematic tokens identified by the compiler are used to penalize the corresponding actions. On the other hand, when the compiler does not detect and error, the novelty score is assigned as a reward to the final action. This is intriguing since it is not clear how this will generalize to testing programs that are not compilers.

One aspect that was confusing when one starts reading the paper is the "circular" reasoning of "testing compilers" using the compiler itself. Suppose the compiler has a bug and did not implement the language specification correctly. Say, a program that was supposed to be type incorrect is incorrectly judged as type correct by the compiler. These kinds of bugs will not be revealed by Synsema, isn't it, because of circular reasoning -- the compiler is used as a specification while it is simultaneously being tested against some larger implicit specification. This point is a source of confusion initially.

Questions
  1. How much work was it to gather "coverage" score from a compiler? Did you have to annotate the compiler to generate coverage information?

  2. There is plenty of work on testing compilers (such as C compilers). Some of these works have been cited too. It is mentioned they rely on "complex generation logic" -- it will be good to know if they would have discovered these bugs, and if not, any particular reason why not?

  3. The main argument against existing work is that they require "huge manual effort" -- it will be good to get some validation for that claim. Maybe by lines-of-code or developer effort reported, and compare that with the same metric here. This also brings us back to Question 1.

  4. It is not clear what is the starting point here in terms of the model. Line 224 says "We employ GPT-2", and then Line 226 says "randomly initialized weights" and Line 344 says "we did not adopt any pretrained model". Isn't GPT-2 a pretrained model? Or did you only use that architecture as seems to be suggested by theat starting with random weight comment.

Other comments:

Figure 1: y * z . Shouldn't y also be inside a red box?

Limitations

Yes

Paper formatting concerns

No

Final justification

I thank the authors for their response. Overall, there is some merit in this work - it shows that one can learn a policy using RL based on compiler feedback to generate diverse programs that can expose compiler bugs. However, I am slightly less enthusiastic about the paper than before. The main reason is that the rebuttal breaks my mental model of the work. The RL approach here is rewarding syntactic correctness and code coverage. And this was shown to expose compiler crashes. But the experiments reported during the rebuttal show that a fuzzer powered by pretrained models can do better on the code coverage metric, but yet it fails to detect crashes. Given this new evidence, I am not sure why the proposed approach works. I think there is deeper analysis needed here into the detected crashes/bugs (as was also suggested by another reviewer) to get full clarity on the proposed approach.

Reviewer_ECUSOpenReview ↗
Rating
4
Clarity
3
Confidence
4
Originality
2
Quality
2
Significance
2
Read review
Summary

This paper presents SYNSEMA, a syntax-guided reinforcement learning framework for generating semantically valid programs, with compiler testing as the main target application. The key idea is to separate syntax from semantics: context-free grammars and parser-derived action spaces ensure syntactic validity by construction, while an RL agent learns from compiler diagnostics and coverage feedback to generate programs that are more likely to compile and exercise diverse compiler behavior. The paper instantiates this idea with three syntax-guided agents based on top-down/LL, bottom-up/LR, and chart/Earley parsing, and evaluates them on Java and Rust compilers. The results show that SYNSEMA produces substantially more compilable programs than an unconstrained token-level RL baseline, improves compiler edge coverage, and discovers several previously unknown compiler bugs.

Strengths and weaknesses

Strengths

The paper studies an important and practical problem: generating valid and interesting programs for testing compilers and other systems that process highly structured inputs. The separation between syntactic validity and semantic validity is well motivated. Using grammars to reduce the action space is a natural way to avoid many early syntax failures, and using compiler diagnostics and coverage as feedback provides a useful learning signal for program generation.

The paper is also relatively clear in its presentation. The three action-space designs based on top-down, bottom-up, and chart parsing are explained well, and the comparison among these choices is a useful part of the paper. The implementation appears nontrivial, and the evaluation on both Rust and Java makes the empirical study more convincing than a single-language setup. The fact that the system finds previously unknown compiler bugs is a positive sign for its practical potential.

Weaknesses

1. The novelty over existing grammar-based generation and fuzzing methods is not sufficiently established.

Grammar-constrained program generation is a well-established idea in grammar-based fuzzing, semantic-aware program generation, and neural code generation. Recent work such as [1] further shows that grammar/AST-based code representations have been explored in billion-scale LLMs, not only for syntactic validity but also for improving semantic differentiation. In this context, SYNSEMA’s novelty appears to lie less in grammar-guided generation itself, and more in combining grammar-constrained action spaces with compiler diagnostic feedback, coverage-based rewards, and an RL loop for Java/Rust compiler testing. The paper would be stronger if it more explicitly clarified which component is the main technical contribution: the LL/LR/Earley action-space comparison, the mapping from compiler diagnostics to RL actions, the semantic-learning formulation, or the compiler-testing application.

2. The main baseline is too weak to support the stronger empirical claims.

The primary baseline is an unconstrained token-level RL agent trained from scratch. This baseline needs to learn both syntax and semantics only from compiler feedback. For languages such as Java and Rust, it is expected that such a model will generate mostly syntactically invalid programs. Therefore, the large improvement in compilable-program rate mainly shows that grammar guidance is useful compared with no grammar guidance for a from-scratch RL generator.

This is a valid and useful result, but it supports a narrower conclusion than the paper seems to suggest. It does not show that SYNSEMA is better than practical grammar-guided generators, grammar-aware coverage fuzzers, semantic-aware fuzzers, or existing compiler-testing tools. To better isolate the contribution of the RL policy, the paper should include stronger baselines such as grammar-guided random generation, grammar-guided coverage-based fuzzing without RL, and existing grammar/semantic-aware fuzzers where applicable. Without these comparisons, it is difficult to tell whether the main gains come from learning semantics, or simply from enforcing syntactic validity.

3. The paper does not compare against modern SOTA LLMs on program generation.

The paper motivates itself partly against language-model-based program generation, but the underlying model used in SYNSEMA is a randomly initialized GPT-2 124M model rather than a pretrained code LLM. Modern code LLMs already encode substantial syntax and semantic knowledge about Java and Rust. Although LLM sampling may have lower throughput, each generated sample may be more semantically meaningful or structurally complex.

Therefore, it remains unclear whether SYNSEMA would outperform SOTA LLM-based methods under a comparable practical budget. Useful baselines could include SOTA LLM sampling with compilation filtering, LLM-based compiler-error repair, LLM generation followed by coverage-guided selection, or LLM-based mutation of existing valid programs. The comparison should ideally be under matched wall-clock time or monetary budget. Without such baselines, the paper does not fully establish the practical advantage of SYNSEMA over modern LLM-based compiler testing.

4. The evidence for learning complex semantics is limited.

The paper often frames the task as learning semantic validity, especially for languages such as Rust with strict ownership, borrowing, lifetime, trait, and generic constraints. However, the main semantic metric is whether the generated program successfully compiles. Compilability is useful, but it is a coarse measure. A program can compile while avoiding most difficult semantic features, especially if the generator tends to produce short or simple programs.

The paper does not provide a feature-level analysis showing whether the generated valid programs actually exercise nontrivial semantic constraints. For Rust, it would be important to know how often valid generated programs contain ownership/borrowing interactions, lifetime annotations, trait bounds, generic constraints, macros, const generics, unsafe code, or other difficult language features. Without such analysis, the claim that the model learns semantics should be stated more conservatively. The current evidence mainly shows that the model learns to increase compiler acceptance under a grammar-constrained and bounded generation setup.

5. The compiler coverage results are promising but hard to interpret.

The paper reports relative improvements in edge coverage, which is useful. However, it does not report the total number of instrumented compiler edges or the corresponding coverage percentage. For large compilers such as rustc and javac, absolute edge counts are difficult to interpret without knowing the denominator. It is therefore unclear how deep the exploration is in absolute terms.

The evaluation would be more informative if it reported coverage percentage, coverage per wall-clock time, coverage per GPU-hour, and perhaps unique edges per unique valid program. These efficiency metrics are important because the baseline generates many more programs but most are invalid, while SYNSEMA generates fewer programs but with a much higher valid rate. The current results show improvement, but they do not fully clarify the practical testing efficiency of the method.

Overall, the implementation and empirical study is interesting, and the results do show that syntax guidance is highly beneficial for from-scratch RL-based program generation. However, the current evaluation does not yet fully establish novelty or practical superiority over existing grammar-guided, semantic-aware, or LLM-based compiler testing methods. The strongest supported conclusion is that grammar-guided action spaces substantially improve a from-scratch RL generator; broader claims about semantic learning and compiler-testing advantage need stronger baselines and deeper analysis.

[1] Liang, Q., Zhang, Z., Sun, Z., Lin, Z., Luo, Q., Yueyi, X., ... & Xiong, Y. (2025, July). Grammar-based code representation: Is it a worthy pursuit for llms?. In Findings of the Association for Computational Linguistics: ACL 2025 (pp. 15640-15653).

Questions
  1. What is the precise technical novelty of SYNSEMA compared with existing grammar-based and grammar-aware fuzzing/program-generation methods?

  2. Could the authors compare against modern LLM-based program generation under matched wall-clock time or monetary budget? Relevant baselines include LLM sampling with compilation filtering, LLM-based compiler-error repair, and LLM generation combined with coverage-guided selection or mutation.

  3. Could the authors provide a feature-level analysis of generated valid programs? For Rust, it would be useful to report how often programs involve ownership/borrowing, lifetimes, trait bounds, generics, macros, const generics, unsafe code, and other nontrivial language features.

Limitations

The paper includes a limitations section, which is appreciated. However, I think several limitations should be discussed more explicitly:

  • The current evaluation mainly establishes the benefit of syntax guidance over an unconstrained from-scratch RL baseline, not necessarily over practical compiler fuzzing methods.
  • The lack of comparison with modern LLM-based generation limits the conclusions about practical advantage.
  • The generated programs are bounded in length and vocabulary, which may limit semantic and structural complexity.
  • The paper does not sufficiently analyze whether generated programs exercise difficult semantic features such as Rust ownership, borrowing, lifetimes, traits, or generics.
Paper formatting concerns

No

Final justification

Thank you for the detailed response and additional experiments. I find the combination of grammar-guided generation, reinforcement learning, and compiler feedback well motivated, and the new results support that this combination provides benefits beyond syntax enforcement alone.

One remaining question is whether the increased use of features such as lifetimes, generics, and ownership translates into better exploration of compiler behaviors that are more likely to expose bugs. A more detailed analysis of the bug-triggering test cases, including the feature combinations or unusual program structures they require, would help clarify this point. The fact that DeepSeek achieves higher coverage but finds fewer reported bugs also suggests that coverage alone may not capture this distinction.

I also consider the cost-matched comparison with LLMs reasonably fair, since API pricing already amortizes the cost of pretraining.

Overall, the response has improved my view of the paper. I increased my score from 3 to 4.

Comments on the paper

1 comment
Meta-review

The reviewers appear to accept the basic premise of the paper, specifically that learning programming language semantics can help generate compiler test cases. However, there are some substantial concerns:

The entire setup seems somewhat archaic. Would a modern LLM have made the problem irrelevant through its knowledge of Rust and Java? A success rate of 7.29% generated programs compilable seems low with modern technology.
The experiments measure compilability, not conformance to semantics. What evidence is there for learning semantics? Or, is this just not a goal and the only goal is to find programs that crash the compiler?
A stronger comparison with existing test generation techniques would help - does the technique discover bugs these previous techniques would not have discovered, and is there a quantitative measure somewhere that would make this argument more precise?
Better compiler coverage results would help as suggested by the reviewers.

The response period was very productive and reviewers were unanimous that this paper can be accepted. I strongly urge the authors to pay attention to the reviews and the responses as they prepare a revision as I anticipate that we can expect to see the paper significantly improved during the revision along the lines suggested in the reviews.

From OpenReview, CC BY 4.0. Authors as signed there; shown unedited.

Related papers

Loading the map…

Discussion (0)

Sign in to comment.