Skip to content

Iteratively parse nested parentheses in Pratt parser - #1509

Merged
dmitriplotnikov merged 1 commit into
masterfrom
pratt-parser-nested-parens
Sep 24, 2026
Merged

dmitriplotnikov merged 1 commit into
masterfrom
pratt-parser-nested-parens

Conversation

@dmitriplotnikov

@dmitriplotnikov dmitriplotnikov commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Replace the lookahead-based grouping parentheses counter (countGroupingParentheses) with a bottom-up iterative approach in parsePrimary() to eliminate quadratic O(N^2) lookahead scans while keeping O(1) call-stack frames on deeply nested parenthesized expressions. Also track recursion depth across iterative operator, selector, and unary chains and stop parsing immediately when the recursion limit is exceeded.

Replace the lookahead-based grouping parentheses counter (countGroupingParentheses) with a bottom-up iterative approach in parsePrimary() to eliminate quadratic O(N^2) lookahead scans while keeping O(1) call-stack frames on deeply nested parenthesized expressions. Also track recursion depth across iterative operator, selector, and unary chains and stop parsing immediately when the recursion limit is exceeded.
@dmitriplotnikov
dmitriplotnikov merged commit 61155a1 into master Sep 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants