Skip to main content
QUICK REVIEW

[Paper Review] Don't Panic! Better, Fewer, Syntax Errors for LR Parsers

Lukas Diekmann, Laurence Tratt|arXiv (Cornell University)|Apr 19, 2018
Software Engineering ResearchComputer Science3 citations
TL;DR

This paper introduces CPCT+, a novel error recovery algorithm for LR parsers that reports the complete set of minimum-cost repair sequences for syntax errors, significantly reducing cascading errors. Evaluated on 200,000 real-world Java files, CPCT+ repaired 98.37% of errors within 0.5 seconds and reduced reported error locations from 981,628 (panic mode) to 435,812, offering developers actionable, intention-aware repair options.

ABSTRACT

Syntax errors are generally easy to fix for humans, but not for parsers in general nor LR parsers in particular. Traditional 'panic mode' error recovery, though easy to implement and applicable to any grammar, often leads to a cascading chain of errors that drown out the original. More advanced error recovery techniques suffer less from this problem but have seen little practical use because their typical performance was seen as poor, their worst case unbounded, and the repairs they reported arbitrary. In this paper we introduce the CPCT+ algorithm, and an implementation of that algorithm, that address these issues. First, CPCT+ reports the complete set of minimum cost repair sequences for a given location, allowing programmers to select the one that best fits their intention. Second, on a corpus of 200,000 real-world syntactically invalid Java programs, CPCT+ is able to repair 98.37% of files within a timeout of 0.5s. Finally, CPCT+ uses the complete set of minimum cost repair sequences to reduce the cascading error problem, where incorrect error recovery causes further spurious syntax errors to be identified. Across the test corpus, CPCT+ reports 435,812 error locations to the user, reducing the cascading error problem substantially relative to the 981,628 error locations reported by panic mode.

Motivation & Objective

  • To address the cascading error problem in LR parsers, where initial error recovery triggers multiple spurious errors.
  • To provide developers with all minimum-cost repair sequences for a given error location, rather than a single arbitrary repair.
  • To improve practical usability of advanced error recovery by combining high performance with grammar-neutral, deterministic repair suggestions.
  • To reduce the reliance on heuristic or ad-hoc error recovery mechanisms in compilers and IDEs.

Proposed method

  • CPCT+ extends the Fischer et al. family of error recovery algorithms by computing the complete set of minimum-cost repair sequences using dynamic programming and grammar-aware token insertion/deletion operations.
  • It uses a modified LR parsing engine that tracks multiple parse states and repairs in parallel, guided by a cost model favoring minimal changes.
  • The algorithm leverages the full grammar to explore all possible minimal-cost repairs (insertions, deletions) at each error location, avoiding arbitrary or suboptimal choices.
  • It integrates a timeout mechanism to ensure practical performance, with heuristics to prioritize likely repairs and prune the search space.
  • The implementation is integrated into the grmtools parser framework and exposed via the nimbleparse tool for practical use.
  • It supports multiple languages (Java, Lua, PHP) by being grammar-agnostic and relying only on the input grammar and input stream.

Experimental results

Research questions

  • RQ1Can a grammar-agnostic error recovery algorithm report all minimum-cost repair sequences for a given error location, enabling developers to choose the most semantically appropriate fix?
  • RQ2Does reporting multiple repair options significantly reduce the number of cascading errors compared to traditional panic-mode recovery?
  • RQ3Can such an algorithm achieve high performance (sub-0.5s per file) on real-world, complex programs while maintaining correctness and completeness?
  • RQ4Is the complete set of minimal repairs computationally feasible to compute and return in practice, especially for large programs?

Key findings

  • CPCT+ successfully repaired 98.37% ± 0.017% of 200,000 real-world syntactically invalid Java programs within a 0.5-second timeout.
  • The algorithm reduced the number of reported error locations from 981,628 (using panic mode) to 435,812, significantly mitigating the cascading error problem.
  • For each error, CPCT+ reports all minimum-cost repair sequences—such as deleting a token, inserting a comma, or inserting an assignment operator—allowing developers to select the most semantically appropriate fix.
  • The approach is practical and scalable, with a performance profile suitable for integration into compilers and IDEs.
  • The algorithm is grammar-agnostic and works across multiple languages (Java, Lua, PHP), demonstrating broad applicability.
  • In cases of high ambiguity or excessive repair cost, CPCT+ correctly times out and reports no repair sequences, avoiding misleading suggestions.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.