source-academy/js-slang

CSE Machine: cannot handle binary search with loop

Closed this issue · 2 comments

https://share.sourceacademy.nus.edu.sg/0buyr

gives no response.

This variant gives a strange error in the REPL:
https://share.sourceacademy.nus.edu.sg/0buyr
Screenshot 2023-10-18 at 10 46 45 AM

The problem lies in the "else if" construct. Putting a block around the nested "if" will lead to success: https://share.sourceacademy.nus.edu.sg/emmdc

The cause is in the functions hasContinueStatement, hasReturnStatement and hasBreakStatement. These functions expect a block statement and recurse into if statements, which fails on else if constructs since they nest an if statement inside an if statement.

A modification to these functions to handle this case should do.