AST Visitor Designs

I’ve noticed that several parsers associated with the OCaml universe seem to generate ASTs that are then walked using an object-oriented visitor interface. Is there a good introduction to this paradigm of AST-walker somewhere that explains the principles of the visitor design? Failing that, is there a really good example of it I can study to see what the ideas behind this sort of design are? (Sorry if this sounds kind of vague, I struggled to come up with a better way of phrasing it. Perhaps I can edit this for posterity if some good answers come in.)

We are using OOP visitors in BAP as they facilitate code reuse for complex recursive data types. Here is an example, a blog post, and the implementation (if needed). We even re-implemented the same concept in Python.

5 Likes

The manual of the visitors library is also a good read, I think.

4 Likes