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
Might not be that big of an issue but running InterpLwhile().interp(prog) on a program that has nested loops seems to cause a RecursionLimit exception rather quickly.
class InterpLwhile(InterpLif):
def interp_stmt(self, s, env, cont):
match s:
case While(test, body, []):
if self.interp_exp(test, env):
self.interp_stmts(body + [s] + cont, env)
else:
return self.interp_stmts(cont, env)
case _:
return super().interp_stmt(s, env, cont)
if __name__ == '__main__':
prog="""
x = 50
while x > 0:
y = 2
while y != 0:
y = y - 1
x = x - 1
print(x)
"""
InterpLwhile().interp(parse(prog))
The above example does not work without using sys.setrecursionlimit(...).
Activity
taimoon commentedon Sep 10, 2023
To avoid recursion limit, this particular block has to be rewrite using python iterative construct, or enable tail-call optimization.