You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i am implementing a parser for my own programming language. i am currently definining expressions as:
exp := lit | variable
this works but when i add binary expressions:
exp := lit | variable | binaryOperationExpression
i get a stack overflow for whatever i am trying to parse even when it does not contain an expression. here some more rules that could be relevant but it is kinda weird since i implemented the same grammar in scala and it worked:
Please provide a minimal reproducible example (MRE).
An MRE is intended to reproduce an error using the smallest amount of code. It saves package developers time trying to reproduce the problem; and wading through code that is not relevant to the bug. Ultimately it helps you to get your problem solved quicker.
The MRE should include:
Packages to be imported.
The shortest amount of code needed to reproduce the problem.
A main function that calls your code and demonstrates the problem, i.e. with a failing assertion.
Your grammar has left-recursive productions expression -> binaryOperationExpression, which leads to infinite recursion at runtime. Have a look look at the tutorial Writing a More Complicated Grammar and Using the Expression Builder, that demonstrate how to build expression grammars.
The simplest way to avoid the recursion is to rewrite the grammar as:
i am implementing a parser for my own programming language. i am currently definining expressions as:
exp := lit | variable
this works but when i add binary expressions:
exp := lit | variable | binaryOperationExpression
i get a stack overflow for whatever i am trying to parse even when it does not contain an expression. here some more rules that could be relevant but it is kinda weird since i implemented the same grammar in scala and it worked:
statement := classDeclaration | ifStatement | whileStatement | methodCall | functionCall | expression
lit := floatLit | intLit | boolLit | stringLit | tupleLit | listLit2 | listLit1
binaryOperationExpression := expression & operator & expression
The text was updated successfully, but these errors were encountered: