Papers
Topics
Authors
Recent
Search
2000 character limit reached

Mimid: Dynamic Control-Flow Grammar Inference

Updated 7 July 2026
  • Mimid is a prototype algorithm that infers readable context-free grammars by analyzing dynamic control-flow traces rather than data flow.
  • It instruments recursive descent parsers to log control structures and reconstructs parse trees that mirror the parser's code structure.
  • Evaluations demonstrate that Mimid produces grammars that are more accurate, readable, and extendable compared to traditional data-flow-based methods.

Searching arXiv for papers on Mimid and related grammar mining work. Mimid is a prototype and a general algorithm for inferring a readable context-free grammar for a program’s input language from dynamic control flow. It takes a program and a small set of sample inputs, observes how input characters are accessed during execution, reconstructs syntactic structure from those traces, and extracts productions that are structurally close to the parser implementation rather than to incidental data-flow artifacts. The approach was introduced for programs whose input models are unavailable or out of date, in settings where such models are useful for vulnerability analysis, reverse engineering, fuzzing and software testing, clone detection, and refactoring (Gopinath et al., 2019).

1. Problem setting and design rationale

Mimid was proposed against a background in which input grammar recovery was already recognized as valuable, but existing methods exhibited two recurring limitations. First, some grammar miners produced unwieldy and incomprehensible grammars. Second, others relied on heuristics that targeted specific parsing patterns. In particular, prior state-of-the-art work such as Autogram depended on data flow from the input, which limited applicability when parsers did not preserve substrings in variables or when parsing logic was implemented as recognizer-style traversal over a shared input buffer (Gopinath et al., 2019).

The defining design decision in Mimid is to infer syntactic structure from dynamic control flow rather than from data flow. Instead of asking where input fragments are stored, the method asks where input characters are accessed, and under which control-stack context. This makes the approach applicable to parsers with or without meaningful data flow, including pure recognizers.

The scope of the method is explicitly centered on all stack-based recursive descent parsers, including PEG parsers and parser combinators. The description also states that these parser styles account for approximately 80% of top language parsers. Within that scope, Mimid aims not merely to recover an accepting model, but to infer a grammar that remains readable, structurally faithful, and suitable for direct human inspection and extension.

2. Dynamic control-flow tracing

The first stage of Mimid is source-level instrumentation. The parser is instrumented to log entry and exit of every function or method, together with entry and exit of control-flow structures such as loops and conditionals. These control-flow structures are treated as pseudo-methods, so that the execution trace records not only call hierarchy but also intra-procedural branching structure (Gopinath et al., 2019).

Each execution frame, whether it corresponds to a function or a control-flow structure, is assigned a unique ID according to call stack order. The input string is wrapped in a proxy object that intercepts character accesses and logs, for each access, the current control-flow stack. This logging discipline is central: the trace couples input positions to parsing context at the moment of use.

A further convention resolves responsibility for consumption. Only the last method to access a character “consumes” it, meaning that ownership of a character is ultimately attributed to the most specific parser component that actually parses it. This yields traces from which a hierarchical parse structure can be reconstructed even when intermediate functions perform lookahead or pass indices through multiple layers of parser logic.

This tracing model is deliberately lightweight in the sense used by the paper: it depends on the control stack and on accesses to the input buffer, not on dynamic taint propagation or parser-specific semantic annotations. A plausible implication is that the inferred structure is closely tied to procedural decomposition in the parser implementation itself.

3. Parse-tree reconstruction and grammar extraction

For each sample input, the recorded execution trace is post-processed into a parse tree. Internal nodes correspond to method calls or control-structure instances and retain their unique IDs; leaves correspond to the concrete input characters that were consumed (Gopinath et al., 2019).

The construction must resolve overlapping accesses. Mimid assigns child nodes exclusive, contiguous index ranges within the input, thereby forcing a well-formed hierarchy out of the dynamic trace. Control-flow nodes are labeled not only by type but also by their static program ID and the branch taken during execution, which allows alternation and repetition patterns to be recovered later as grammar structure rather than discarded as implementation detail.

Generalization proceeds by grouping parse-tree nodes by name and then testing compatibility between node instances. The core question is whether one instance can replace another without changing acceptance of the input. The method uses active learning and mutation for these tests. For efficiency, transitive compatibility is assumed, with empirical justification reported in the paper. Repetition is handled by identifying interchangeable loop iterations and summarizing them using regular-expression structure in EBNF form. Nullability is inferred by “zeroing out” loops or skipping branches and confirming acceptance.

Grammar extraction is then straightforwardly tree-driven. Each unique node label becomes a nonterminal. For any node, the ordered sequence of terminal and nonterminal children becomes a production. Productions collected across parse trees are merged, after which a compaction phase applies reductions such as inlining nonterminals with a single expansion, merging duplicates, and removing unused or trivial rules.

The calculator example in the paper illustrates the resulting style:

1
2
3
4
5
<START> ::= (<parse_expr>"[*+-/]")*<parse_expr>
<parse_expr>  ::= <parse_num> | <parse_paren>
<parse_paren> ::= `(' <parse_expr> `)'
<parse_num>   ::= <digit>+
<digit> ::= `0' | ... | `9'

The reported intent of this pipeline is not merely acceptance-equivalent inference, but extraction of grammars that are readable, structurally faithful, and immediately suitable for use.

4. Supported parser styles and methodological position

Mimid is presented as applicable to ad hoc recursive-descent parsers, textbook-style recursive descent, parser combinators, PEG-based parsers, and even recognizer implementations. The description also notes that parsers using lexing or tokenization can be handled with minor extensions (Gopinath et al., 2019).

Its comparison with Autogram is central to its methodological identity. Autogram derives nonterminals from dynamic data flow and therefore encounters difficulty when the program keeps only an index or pointer into the input buffer and reuses the whole buffer across calls. Mimid’s control-flow-based approach avoids that dependence. As presented, its main advantages are:

  • Data-flow independence: it works even if no variables ever store substrings.
  • No parser-style heuristics: it does not need ad hoc rules for lookahead or programming idioms.
  • Automatic regular-expression generalization: repetition and alternation are summarized from dynamic structure.
  • Broader applicability: it covers advanced recursive-descent forms, including PEG and combinator-based implementations.
  • Higher readability: inferred grammars are described as closer to textbook structure.

The paper also positions Mimid against black-box grammar-inference systems such as GLADE, REINAM, and GRIMOIRE. Those systems are described as primarily producing grammar-like artifacts for fuzzing rather than human-readable grammars for inspection or maintenance. Mimid, by contrast, is intended to produce grammars that can be read, extended, and reused directly by researchers and practitioners.

5. Evaluation and observed behavior

The prototype was implemented in Python and evaluated on subjects including recursive-descent expression parsers, URL parsing, MicroJSON, CGIDecode, Netrc, PEG-based parsers, and parser combinators (Gopinath et al., 2019).

The evaluation asked four questions: how often inputs generated from inferred grammars are accepted by the original program, how often valid inputs from a golden set are accepted by the inferred grammar, whether the method works on programs without meaningful data flow and on advanced parser styles, and how it compares with Autogram. The reported results favor Mimid strongly on most subjects.

For inputs generated by the inferred grammars and tested against the original programs, Mimid achieved 100.0% on calc.py, cgidecode.py, urlparse.py, and netrc.py, 98.7% on microjson.py, and 87.5% on mathexpr.py. The corresponding Autogram figures were 36.5%, 47.8%, 100.0%, 0.0%, 53.8%, and 30.3%.

For the valid golden input set accepted by the inferred grammar, Mimid achieved 100.0% on calc.py and cgidecode.py, 96.4% on urlparse.py, 93.0% on microjson.py, 92.7% on mathexpr.py, and 41.3% on netrc.py. Autogram recorded 0.0% on calc.py, mathexpr.py, and microjson.py, 35.1% on cgidecode.py, 100.0% on urlparse.py, and 34.6% on netrc.py.

The qualitative conclusion reported for these experiments is that, in the complex and realistic cases, Mimid produced grammars that were much more accurate, structurally close to the original, easy to read, and suitable for extension. This suggests that the gain from control-flow observation is not only numerical but representational: the inferred grammar more closely follows the parser’s decomposition of the language.

6. Input dependence, limitations, and later extensions

A central limitation of Mimid is that it remains an inductive method. If certain syntactic structures are absent from the supplied sample inputs, the mining process will likely overlook them. The original work states this dependency directly: unseen input features will not be present in inferred grammars. Additional limitations include the fact that grammars can only approximate the true language, that parser combinators and PEGs may require minor adaptation to recover appropriate nonterminal names, that lexical analyzers need supplemental token-stream tracking, and that reparsing already-parsed parts can require heuristic refinement (Gopinath et al., 2019).

This input-coverage dependency became the starting point for a later extension that integrates automated input generation with Mimid. The 2025 work on “Generating Inputs for Grammar Mining using Dynamic Symbolic Execution presents a fully automated approach that feeds generated inputs directly into the Mimid mining pipeline, thereby eliminating the need for handwritten seed corpora (Pointner et al., 5 Aug 2025).

That extension argues that pure Dynamic Symbolic Execution (DSE) is insufficient for structured-input parsers because of path explosion. To address this, it introduces two mechanisms. The first is iterative expansion, inspired by PFUZZER: generation starts with a single-character placeholder input and incrementally appends characters while solving failure-inducing comparisons with an SMT solver. The second is a three-phase approach: Phase 1 collects function prefixes and initial stems, Phase 2 grows longer stems while reusing collected stems for sub-parsers, and Phase 3 completes those stems into globally valid full inputs.

The reported evaluation covers eleven benchmark applications and compares handwritten inputs, KLEE, One-Phase, and the Three-Phase Approach. On average, the resulting grammar F1-score was 66.4 for KLEE, 63.2 for One-Phase, 89.6 for Three-Phase, and 92.2 for Handwritten inputs. The difficult cases are particularly revealing: on Calc, KLEE achieved 14.8, One-Phase 8.0, and Three-Phase 100.0; on MailParser, KLEE and One-Phase both achieved 0.0, while Three-Phase reached 100.0; on CgiDecode, the figures were 50.0, 96.9, and 97.5, respectively. The paper further reports recovery of subtle features and edge cases, including multiple commas in JSON dictionaries and special behaviors in escape sequences.

Taken together, these results establish two complementary facts about Mimid. First, its core control-flow-based grammar inference remains a general and readable alternative to data-flow-based mining. Second, its principal weakness—dependence on input coverage—can be substantially mitigated by automated DSE-based input generation. This suggests a broader role for Mimid in reconstructing specifications from existing or legacy parsers, particularly when manual input curation is unavailable or prohibitively expensive.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Mimid.