[Paper Review] Memoization of Top Down Parsing
This paper presents a continuation-passing style (CPS) functional formalization of top-down parsing that enables memoization to terminate on left-recursive grammars—previously a known failure point—by incrementally enumerating string positions rather than returning sets. The key contribution is a novel memoization technique that emulates chart parsing behavior, ensuring termination and polynomial time complexity even with left recursion.
This paper discusses the relationship between memoized top-down recognizers and chart parsers. It presents a version of memoization suitable for continuation-passing style programs. When applied to a simple formalization of a top-down recognizer it yields a terminating parser.
Motivation & Objective
- To resolve the non-termination problem of memoized top-down parsers on left-recursive grammars.
- To formalize top-down parsing in a functional, continuation-passing style that supports incremental result enumeration.
- To demonstrate that memoization in this CPS framework achieves behavior equivalent to chart parsing.
- To enable the construction of efficient, terminating parsers for context-free grammars, including left-recursive ones.
- To lay the foundation for extending the approach to full parse tree construction and semantic value propagation.
Proposed method
- Uses continuation-passing style (CPS) to represent parsing as a stream of string position results rather than returning sets.
- Introduces a memoization mechanism that caches results per input position and category, preventing redundant computation.
- Employs a table-based memoization structure with 'entry' cells storing continuations and results, using mutation for efficiency.
- Defines higher-order combinators like 'seq', 'alt', 'opt', and 'k*' to build grammars compositionally from terminal and non-terminal functions.
- Applies memoization to CPS-transformed parsing functions, ensuring each function is called at most once per argument pair (category, position).
- Uses destructive assignment (set-car!, set-cdr!) to efficiently update memo tables, improving performance in Scheme.
Experimental results
Research questions
- RQ1Can memoized top-down parsing be made to terminate on left-recursive grammars using functional programming techniques?
- RQ2How can continuation-passing style enable a more efficient and terminating form of memoization in top-down parsing?
- RQ3To what extent does CPS-based memoization emulate the behavior of chart parsers in terms of prediction and completion steps?
- RQ4Can the same memoization technique be extended to construct full parse trees or semantic values without sacrificing termination?
- RQ5Is it possible to achieve chart-like efficiency and completeness in a purely functional, memoized top-down framework?
Key findings
- The CPS-based memoized parser terminates on left-recursive grammars, such as the NP rule in (35), which previously caused non-termination in standard memoized top-down parsing.
- The memoization mechanism ensures that each parsing function is called at most once per input position and category, preventing infinite recursion.
- The parser’s behavior closely mirrors that of a predictive chart parser, with memo table entries corresponding to predicted and completed edges.
- The approach supports efficient recognition in polynomial time for context-free grammars, even with left recursion.
- The method enables the construction of efficient, working recognizers in Scheme, with potential for optimization via integer positions and vector-based memoization.
- The framework can be extended to parse tree construction and semantic value propagation by adding extra continuation arguments.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.