Abstract
Traditional programming language design mandates strictly unambiguous grammars, often relying on arbitrary precedence rules that may conflict with user intuition or hinder language composition. This paper introduces "resolvable ambiguity," a framework where grammars can remain ambiguous provided users have a guaranteed mechanism—such as parentheses—to specify their intended interpretation. By leveraging Visibly Pushdown Automata (VPDA), the authors demonstrate that determining if an ambiguity is resolvable is decidable, offering a path toward more modular and user-centric language design.
Introduction
For decades, ambiguity in programming languages has been treated as a defect. Because determining the ambiguity of a context-free grammar is undecidable, designers typically restrict themselves to specific grammar classes (like LR or LL) and enforce rigid precedence and associativity rules. However, this approach often leads to arbitrary design choices and creates significant hurdles when attempting to compose independent domain-specific languages (DSLs).
This research challenges this status quo by proposing that ambiguity is acceptable if it is resolvable. In this paradigm, the parser does not need to guess the user's intent; instead, it ensures that the user can always provide clarifying information to uniquely identify the desired parse tree.
The Problem: The Composition Nightmare
The primary motivation for resolvable ambiguity lies in the difficulty of modular language design. When two unambiguous DSLs are merged, the resulting language is frequently ambiguous. Forcing a designer to manually resolve every potential conflict between merged grammars is a massive barrier to extensibility.
Furthermore, standard precedence rules often fail to capture user intent in complex scenarios. Instead of the compiler silently picking a "correct" interpretation that might surprise the developer, a system supporting resolvable ambiguity can identify the conflict and ask the user for clarification.
Technical Framework
The authors formalize resolvable ambiguity through several key technical innovations:
- Abstract Parsers and Marks: Syntax is defined using EBNF where "marks" prevent certain productions from being direct children of others, effectively encoding precedence without eliminating ambiguity entirely.
- The "Unparen" Function: Parentheses are treated as first-class information carriers. An ambiguity is considered "resolvable" if there exists a parenthesized version of the code that uniquely maps to each possible parse tree.
- Visibly Pushdown Automata (VPDA): By recognizing that the language of all possible parenthesized versions of a parse tree is "visibly pushdown," the authors utilize the closure properties of VPDAs to build robust decision procedures for both static and dynamic analysis.
Case Study: Component Modeling DSL
To evaluate their framework, the authors applied it to a DSL for hardware/software component composition. In this language, components can be linked in series (--) or parallel (||).
Without strict precedence rules, a simple expression can yield multiple structural interpretations, as shown in the figure above. Under the resolvable ambiguity framework, the system can generate a "minimal witness"—the shortest set of parentheses required—to help the user disambiguate their code.
Key Results and Insights
- Decidability: The authors proved that the dynamic resolvable ambiguity problem is decidable for languages with balanced parentheses.
- OCaml Analysis: Testing against a substantial subset of OCaml revealed that the official reference manual is under-specified. The tool identified real-world cases, such as nested
matchexpressions, where the compiler's silent choice could be replaced by a helpful disambiguation prompt. - Parentheses as Tools: This approach reframes parentheses from "noise" to be stripped away into essential tools for user-directed parsing.
Conclusion and Future Work
Resolvable ambiguity offers a promising alternative to the rigid constraints of traditional grammar design. While current limitations include handling "deep" precedence and "longest match" rules (like the dangling else problem), the framework provides a solid foundation for more flexible, modular, and user-friendly programming languages. Future work aims to expand the static analysis capabilities to cover a broader range of complex grammars.
Summary updated