PacktPublishing / Build-Your-Own-Programming-Language

Build Your Own Programming Language, published by Packt
MIT License
200 stars 49 forks source link

Chapter 3 Java Issue #3

Closed EDKarlsson closed 2 years ago

EDKarlsson commented 2 years ago

@cjeffery The method deEscape in the ch3 token.java class that we implement causes an infinite loop and the jvm runs out of memory. The issue is that the while loop checks sin.length but never updates it unless it goes into the if(c=='\\'). You may have been thinking that you would use the int i variable as a counter because it's never used.

I think there should be a sin = sin.substring(1); after the sout.append(c);.

That's what I put it and it fixed the issue.

Also which version of java are you using that has a static String.substring method? I am assuming it's meant to call sin.substring(...).

cjeffery commented 2 years ago

Thank you for the bug report, and for the fix. I have added this to the book's errata page at www.cs.nmt.edu/~jeffery/byopl.