0

I'm using boost.spirit.x3 to parse a simple script-like context to an ast(Abstract Syntax Tree). and as a complete novice in this parser & compiler area, i am starting from a boost's example which called calc9, this example demonstrate how context be parsed and compiled to a vector of byte code, and it also has a vitual machine that can excute the byte codes.
But i am wondering how to excute the compiled byte codes in line step mode, just like pressing the F10 key when debugging a program in visual studio.
I can think of a dumb solution which is marking the line index of each operation when compling stage, and the byte codes of each operation will have an extra argument which imply its line number in the source context. And during execution stage compare the current line index to the operation that is about to excute. this maybe workable but I want to know if there are some more standardized practices to achieve this line step mode execution?

Alfred Li
  • 25
  • 1
  • 4
  • 1
    What makes that a dumb solution? I think it's the best you can do (for grammars that donot inherently force an instruction-per-line like assembly). Execution is conceptually separate from semantics, and semantics separate from syntax. If you want to link the extreme ends you'll need the mapping. This is how most (all?) source-level debuggers work. – sehe Oct 08 '22 at 10:45

0 Answers0