orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.84k stars 392 forks source link

Reverse Polish notation expressions #138

Open GeriatricJacob opened 4 years ago

GeriatricJacob commented 4 years ago

How could I have reverse polish notation expressions in my language? expr : <number> | <expr>+ <operator> ; Results in error: Maximum recursion depth exceeded!

kumachan-mis commented 4 years ago

You forget ‘(‘ and ‘)’ at the beginning and the end of expr, don’t you? Since your regex contains left-recursion (https://en.m.wikipedia.org/wiki/Left_recursion), the parser goes into infinite-loop! :(