arXiv:2610.39224cs.SEOct 2026

Manuscript Offprint

arXiv:2610.39224

PyReprism: A Shared Lexical Foundation for Polyglot Code Analysis

Daniel Ogenrwot, Jorge Gonzalo Delgado Cervantes, Richard Sserunjogi, John Businge

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Daniel Ogenrwot Ⓤ, Jorge Gonzalo Delgado Cervantes Ⓤ, Richard Sserunjogi Ⓤ, John Businge Ⓤ

University of Nevada Las Vegas

Las Vegas, USA

{ogenrwot, delgaj10, sserunjo}@unlv.nevada.edu, john.businge@unlv.edu

Abstract—Empirical studies of polyglot repositories apply the same analyses to every language of a corpus, such as separating code from comments, computing metrics, normalizing identifiers, and screening for duplicated code. Assembling them from specialized tools introduces differences in language coverage, measurement conventions, and workflows. We present PYREPRISM, an open-source Python library and command-line tool that separates language-specific lexical processing from reusable analyses: each language declares its lexical surface, which yields a lossless stream of typed tokens, and every analysis is implemented once on that stream. Across 187 built-in languages, language-specific declarations have a median length of 16 lines, and no language overrides a shared analysis. Against a reference parser, comment and string classification reach F1 scores of 0.994 and 0.958 on 1,412 files in 12 languages that were never used to develop the tokenizer. In a study of a polyglot repository, one tool replaces three; with matched inputs and analysis operations, it takes 2.9s instead of 8.7s on one core. We also characterize where lexical analysis falls short, in complexity estimation and clone screening.

Tool: https://github.com/unlv-evol/PyReprism Video: https://youtu.be/IXc-NP5t4GU

Index Terms—mining software repositories, multi-language analysis, lexical analysis, software metrics, code clones

I. INTRODUCTION

Software projects frequently combine multiple programming languages [1], so empirical studies of them must apply the same analyses to every language of a corpus, such as measuring code characteristics, separating comments from code, normalizing identifiers, and detecting duplicated code [2]. Since no single tool supports all of these analyses for all languages, researchers typically combine tools that differ in language coverage, supported operations, and measurement conventions. Such differences can change a study's outcome: tools implementing the same metrics produce different values for the same systems [3].

To put this challenge into perspective, consider OpenPAI [4], which we use as a running example throughout this paper. OpenPAI combines Bash, Python, Java, JavaScript, and TypeScript, so analyzing its documentation, complexity, and duplication requires tools that differ in both language coverage and measurement conventions. In our evaluation, we analyzed it with CLOC [5], LIZARD [6], and JSCPD [7], and the three tools did not even analyze the same files: of the 718 files in these languages, CLOC analyzed 667, LIZARD 408, JSCPD 735, because it counts JSX and TSX files twice.

Per-language measurements from these tools therefore cover different sets of files, which the researcher must identify, reconcile, and report before any comparison. This motivates the shared lexical foundation of PYREPRISM, in which analyses and their measurement policies are implemented once and reused across languages, so that every analysis sees the same files under the same conventions.

Researchers could instead build analyses on language infrastructure such as Pygments [8] or tree-sitter [9], but it provides tokens or syntax trees rather than metrics. Researchers must still decide how token categories map to code and comment lines, what counts as a decision point, and which tokens to rename, and then implement and validate each analysis. Specialized tools thus offer complete analyses for different sets of languages with their own conventions, while infrastructure offers broad coverage but no analyses. To the best of our knowledge, no existing tool lets researchers implement an analysis and its measurement policy once and apply it to every language of a study. Yet many of these analyses need only lexical information, including line accounting, Halstead [10] and approximate McCabe [11] metrics, identifier normalization, n-gram naturalness [12], and fingerprint-based clone screening [13]. This raises a practical question: can a shared lexical representation support reusable analyses across languages with sufficient accuracy for empirical research, and what trade-offs does this introduce in precision, extensibility, and performance?

We present PYREPRISM, whose main contribution is a set of analyses implemented once and reused for every supported language. Each language declares only its lexical surface (file extensions, keywords, and comment and string syntax), from which PYREPRISM produces a lossless stream of typed tokens. All analyses operate on this stream, from line classification and metrics to normalization, n-grams, fingerprints, and clone and diff reports. Measurement policies, such as when a string counts as documentation, are therefore defined once and applied uniformly to all 187 built-in languages. This does not remove methodological choices, but it makes them explicit and consistent.

Our evaluation shows that no language overrides a shared analysis, that comment and string classification reach F1 scores of 0.994 and 0.958 against a reference parser on held-out files, and that in the OpenPAI study one tool replaces three and runs a matched workload about three times faster, although it is slower than CLOC for counting lines alone. It also characterizes where lexical analysis falls short: complexity estimates rank files well but are not interchangeable with syntax-aware values, and lexical clone screening finds copied and lightly edited fragments but few natural clones.

PYREPRISM is an MIT-licensed Python package on PyPI (pip install PyReprism), with source code on GitHub [14] and documentation on Read the Docs [15]. A replication package [16] with all sampled files, scripts, runtimes, and tool versions accompanies this paper.