Skip to content

Implement an error-recovery method for LR parsers #310

Description

@moorara

Context

A basic error-recovery method is required for the LR parsing algorithm. This helps with continuing the parsing and detecting more errors.

Use Case

Proposed Solution

/*
 * ERROR RECOVERY METHOD:
 *
 *   An effective error recovery strategy is a crucial aspect of compiler design, with the parser playing a key role in handling errors.
 *   The goal is to recover from errors as quickly as possible, allowing parsing to continue and detect additional errors.
 *   This implementation follows a basic panic-mode recovery approach.
 *
 *   In panic-mode recovery, when an error is encountered, the parser discards input symbols one at a time
 *   until a designated synchronizing token is found, enabling parsing to resume in a meaningful state.
 *
 *   In LR parsing, panic-mode error recovery works as follows:
 *
 *   The parser scans down the stack to find a state s with a valid GOTO entry for a specific non-terminal A.
 *   It then discards input symbols until encountering a symbol a that can validly follow A.
 *   At this point, the parser pushes the state GOTO[s,A] onto the stack and resumes normal parsing.
 *
 *   Multiple choices for the non-terminal A may exist, typically representing key constructs such as expressions, statements, or blocks.
 *   This recovery strategy aims to remove the erroneous phrase and continue parsing effectively.
 */

Alternative Solutions

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or capability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions