Skip to content

Lwhile interpreter exceeds RecursionLimit #22

Open
@waynee95

Description

@waynee95

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(...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions