How to correctly implement jump statements such as break/continue in the tree traversal interpreter? [closed]

I am a newcomer who is beginning to learn the principles of compilation. I am trying to implement a simple C-like scripting language interpreter using C++17.

I have completed lexical analysis and parser, and can convert code text into AST representation.The next step is to execute the code by traversing the AST.

I understand the execution process of loops, conditional branches, etc.But for the break/continue statement, I feel very confused.How should I execute them correctly during tree traversal?

In some tutorials that can be found, it seems that break can be achieved by throwing/caught exceptions. I have also tried to do this and I can indeed do it.But if continue is also taken into consideration, the entire execution code will become very messy.

So I want to know, for the tree traversal interpreter, is there any better practice to implement break/continue?

I think it seems very strange to use exceptions in normal logic to complete content that is just a jump.

I know that mainstream scripting languages such as Python are all executed in a bytecode virtual machine, but I haven’t learned this part yet. At present, I want to clarify many questions about tree traversal execution.

Thank you for your answers.

Source: Windows Questions C++

LEAVE A COMMENT