Skip to content

Getting Stack Overflow error when using chumsky #58

Answered by zesterer
FussballAndy asked this question in Q&A
Discussion options

You must be logged in to vote

I've not fully looked into the code, but this sounds very typical of left-recursion. Chumsky is, underneath, a PEG parser and left recursion will cause infinite recursion.

You can resolve this by restating your grammar in a way that avoids left recursion.

For example, the left-recursive pattern

expr = (expr + "+" + atom) | atom

can be restated as

expr = atom + ("+" + atom)*

This section in the tutorial about binary operators demonstrates using this technique to properly parse binary operators with precedence in this way.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@FussballAndy
Comment options

Answer selected by FussballAndy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants