3 ms·
The bytecode interpreter in the second half of the book doesn't use the visitor pattern.
by kevthecoder 9mo ago
The bytecode interpreter in the second half of the book doesn't use the visitor pattern.
- jokoon 9mo agothe parser does
- tonyedgecombe 9mo agoI’ve only glanced at the second part but I don’t remember that being the case.
- ceronman 9mo agoThe parsers in crafting interpreters do not use the visitor pattern. The visitor pattern is used when you already have a tree structure or similar. The parser is what gives you such tree structure, the AST. When you have this structure, you typically use the visitor pattern to process it for semantic analysis, code generation, etc.
- HarHarVeryFunny 9mo agoNo, but his first "Tree-walk Interpreter" does - he builds an AST then uses the visitor pattern to interpret it. https://craftinginterpreters.com/representing-code.html#working-with-trees https://craftinginterpreters.com/representing-code.html#work...
- etyp 9mo agoTo quote the very first paragraph of the bytecode interpreter section[1]: > The style of interpretation it uses—walking the AST directly—is good enough for some real-world uses, but leaves a lot to be desired for a general-purpose scripting language. Sometimes it's useful to teach progressively, using techniques that were used more often and aren't as much anymore, rather than firehosing a low-level bytecode at people. [1] https://craftinginterpreters.com/a-bytecode-virtual-machine.html https://craftinginterpreters.com/a-bytecode-virtual-machine....
- HarHarVeryFunny 9mo agoSure, I'm not criticizing it. He's doesn't actually build on this though, but rather goes back to a single pass compiler (no AST, no visitor) for his bytecode compiler.