Skip to content

Implement an error recovery method for predictive parsers #253

Description

@moorara

Context

The synchronization set is implemented for the predictive parsing table. These symbols must be used to implement error recovery during the predictive parsing procedure.

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.
 *
 *   This implementation considers three cases of error handling:
 *
 *     I. If X is a terminal and does not match the next input token:
 *        X is popped from the stack and discarded.
 *
 *     II. If X is a non-terminal and M[X, a] is marked as a synchronization token:
 *         The parser recovers by popping X from the stack and discarding it.
 *
 *     III. If X is a non-terminal and M[X, a] is an error entry:
 *          The parser skips input tokens until a token in FOLLOW(X) or the endmarker $ is reached.
 */

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