SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.17988 · 2024

Constrained Decoding for Fill-in-the-Middle Code Language Models via Efficient Left and Right Quotienting of Context-Sensitive Grammars

arXiv · PDF · Open in the Atlas

Code that ran

4 of 6 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 2 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2402.17988.json · badge: /api/ran/2402.17988.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
amazon-science/incremental-parsing canonical (classifier label)
classifier basis: census
4 ran · 2 no recorded run
FunctionStatusWhere it lives
cut_text_random Ran
ran; our contract draft was wrong, not the code
amazon-science/incremental-parsing/incremental_parsing/evaluation/text_cuts.py
code served (permissive licence) · get_code("a69071e9274fe02e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import random

# Set seed for reproducibility
random.seed(42)

ARGS = {
    "text": "The quick brown fox jumps over the lazy dog. This is a sample text to demonstrate the cut_text_random function. It contains enough characters to be split into meaningful parts.",
    "min_cut_percentage": 0.2,
    "max_cut_percentage": 0.6,
    "cut_amount": 0.15,
    "cut_no_more_than": None
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_absolute_positions Ran
ran, honoured the contract we drafted
amazon-science/incremental-parsing/incremental_parsing/evaluation/text_cuts.py
code served (permissive licence) · get_code("a67dc4188029ee5d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 2, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import io
import tokenize
from tokenize import TokenInfo
from typing import Tuple, List

# Create a simple Python code string to tokenize
code_text = """def hello():
    x = 42
    return x
"""

# Tokenize the code string
tokens_list = list(tokenize.generate_tokens(io.StringIO(code_text).readline))

# Filter to only meaningful tokens (skip ENCODING, ENDMARKER, NEWLINE, NL, INDENT, DEDENT)
filtered_tokens = [
    tok for tok in tokens_list 
    if tok.type not in (tokenize.ENCODING, tokenize.ENDMARKER, tokenize.NEWLINE, 
                        tokenize.NL, tokenize.INDENT, tokenize.DEDENT)
]

ARGS = {
    "text": code_text,
    "tokens": filtered_tokens,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, dtype family int — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_runs_of_same_indentation Ran
ran; our contract draft was wrong, not the code
amazon-science/incremental-parsing/incremental_parsing/evaluation/text_cuts.py
code served (permissive licence) · get_code("aa0e7bf322585b9e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tokenize
from tokenize import TokenInfo

# Create valid TokenInfo objects for testing
# TokenInfo has fields: type, string, start, end, line

tokens = [
    TokenInfo(type=tokenize.NAME, string='pass', start=(1, 0), end=(1, 4), line='pass\n'),
    TokenInfo(type=tokenize.INDENT, string='    ', start=(2, 0), end=(2, 4), line='    pass\n'),
    TokenInfo(type=tokenize.NAME, string='pass', start=(2, 4), end=(2, 8), line='    pass\n'),
    TokenInfo(type=tokenize.INDENT, string='        ', start=(3, 0), end=(3, 8), line='        pass\n'),
    TokenInfo(type=tokenize.NAME, string='pass', start=(3, 8), end=(3, 12), line='        pass\n'),
    TokenInfo(type=tokenize.DEDENT, string='', start=(4, 0), end=(4, 4), line='    pass\n'),
    TokenInfo(type=tokenize.NAME, string='pass', start=(4, 4), end=(4, 8), line='    pass\n'),
    TokenInfo(type=tokenize.DEDENT, string='', start=(5, 0), end=(5, 0), line='pass\n'),
    TokenInfo(type=tokenize.NAME, string='pass', start=(5, 0), end=(5, 4), line='pass\n'),
    TokenInfo(type=tokenize.INDENT, string='    ', start=(6, 0), end=(6, 4), line='    pass\n'),
    TokenInfo(type=tokenize.NAME, string='pass', start=(6, 4), end=(6, 8), line='    pass\n'),
    TokenInfo(type=tokenize.DEDENT, string='', start=(7, 0), end=(7, 0), line='pass\n'),
]

ARGS = {
    'tokens': tokens
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
parse_top_level_file Ran
ran; our contract draft was wrong, not the code
amazon-science/incremental-parsing/incremental_parsing/evaluation/evaluate_stack.py
code served (permissive licence) · get_code("8cf06c6d34b7983f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

from pathlib import Path
import tempfile
import os

# Create a temporary directory structure that mimics the expected file layout
temp_dir = tempfile.mkdtemp()

# Create a test directory structure for a data index
data_idx = 42
data_dir = Path(temp_dir) / str(data_idx)
data_dir.mkdir(parents=True, exist_ok=True)

# Create subdirectories for cut and seed
cut_idx = 0
seed_idx = 0
cut_dir = data_dir / str(cut_idx)
seed_dir = cut_dir / str(seed_idx)
seed_dir.mkdir(parents=True, exist_ok=True)

# Create the required files
(seed_dir / 'prefix').write_text('def foo():\n    ')
(seed_dir / 'suffix').write_text('\n    return 42')

# Create constrained generation file
constrained_dir = seed_dir / 'constrained'
constrained_dir.write_text('x = 1')

# Create unconstrained generation file
unconstrained_dir = seed_dir / 'unconstrained'
unconstrained_dir.write_text('x = 1')

# Create unconstrained_checked marker
unconstrained_checked_dir = seed_dir / 'unconstrained_checked'
unconstrained_checked_dir.write_text('')

# Create stats.json
stats_json = seed_dir / 'stats.json'
stats_json.write_text('{"generation_time": 0.5}')

# Create full_constrained marker
(seed_dir / 'full_constrained').write_text('')

# Construct the argument for the function
top_level_file = data_dir

ARGS = {
    'top_level_file': top_level_file
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
create_balanced_context Not yet run
unverified (harvested, no recorded run)
amazon-science/incremental-parsing/incremental_parsing/generation/utils.py
code served (permissive licence) · get_code("01edc77d3bb7b944")
How it ran

no invocation recorded.

tokenizer_int64 Not yet run
unverified (harvested, no recorded run)
amazon-science/incremental-parsing/incremental_parsing/generation/utils.py
code served (permissive licence) · get_code("4971c3e59cfa2506")
How it ran

no invocation recorded.

Also present in other papers' code

Of 6 samples lifted from this paper's linked repositories, 6 carry a function identity and 0 do not. Of the 6 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large Language Models are powerful tools for program synthesis and advanced auto-completion, but come with no guarantee that their output code is syntactically correct. This paper contributes an incremental parser that allows early rejection of syntactically incorrect code, as well as efficient detection of complete programs for fill-in-the-middle (FIM) tasks. We extend the Earley parsing algorithm to allow for left and right quotients of context-free grammars, and develop methods to handle quotienting of several context-sensitive features present in the grammars of many common programming languages. The result of these contributions is an efficient, general, and well-grounded method for left and right quotient parsing. To validate our theoretical contributions -- and the effectiveness of certain design decisions -- we evaluate our method on the particularly difficult case of FIM completion for Python 3, with syntax-correctness constraints. Our results demonstrate that constrained generation can significantly reduce the incidence of syntax errors in recommended code.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2402.17988")
get_code_for_paper("2402.17988")
have("2402.17988")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2402.17988.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2402.17988.svg)](https://syntology.ai/paper/2402.17988)

Connect an agent — have() is free.