vighnesh153 / spl

SPL (Simple Programming Language), a friendly neighborhood programming language.
https://vighnesh153.dev/projects/spl
4 stars 1 forks source link

Interpreter freeze in infinite while loop #1

Open sahilverma0696 opened 4 years ago

sahilverma0696 commented 4 years ago
let number x be 1
loop while x  <2:
    display 'Hello'

The webpage crashed!!

vighnesh153 commented 4 years ago

That is a mistake that I did a lot of times too. You are not updating x. So, it is always 1 and hence, an infinite loop. In this iteration, I am just letting it go. There is no detection mechanism for an infinite loop.

sahilverma0696 commented 4 years ago

That is a mistake that I did a lot of times too. You are not updating x. So, it is always 1 and hence, an infinite loop.

let number x be 1
loop while x  <2:
    display 'Hello'

The webpage crashed!!

Atleast the editor shoudn't.

vighnesh153 commented 4 years ago

Now that I think about it, it seems that it is very difficult to detect an infinite loop. If the user is printing something, the buffer may get filled with a lot of data and that would hint that something is wrong in the code. But this would only be the best case. What if user doesn't print anything? Well, then we will never know if the code has an infinite loop. A possible solution would be after every iteration in a while loop, we check any of the variables in the scope have changed their values but then it will become very inefficient and also, what if the user changed some value which is not affecting the expression check of the loop? There are a lot many possibilities and cases that would need to be handled and I don't think that is humanely possible to do that.

Anyway, if you got any idea, I am all ears.