# AST Visitor Designs

**URL:** <https://discuss.ocaml.org/t/ast-visitor-designs/2015>\
**Category:** Learning\
**Created:** [May 17, 2018, 7:28pm UTC](https://discuss.ocaml.org/t/ast-visitor-designs/2015 "2018-05-17T19:28:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [May 17, 2018, 7:28pm UTC](https://discuss.ocaml.org/t/ast-visitor-designs/2015/1 "2018-05-17T19:28:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ivg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ivg/32/103_2.png) [@ivg](https://discuss.ocaml.org/u/ivg)\
**Post date:** [May 17, 2018, 8:30pm UTC](https://discuss.ocaml.org/t/ast-visitor-designs/2015/2 "2018-05-17T20:30:19Z")

</div>

We are using OOP visitors in BAP as they facilitate code reuse for complex recursive data types. Here is [an example](http://binaryanalysisplatform.github.io/bap/api/master/Bap.Std.Exp.visitor-c.html), a [blog post](http://binaryanalysisplatform.github.io/bil-visitor-mappers), and the [implementation](https://github.com/BinaryAnalysisPlatform/bap/blob/master/lib/bap_types/bap_visitor.ml) (if needed). We even [re-implemented](https://pythonhosted.org/bap/bap.adt.Visitor-class.html) the same concept in Python.

---

<div class="post-metadata">

**Author:** ![Armael](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/armael/32/1223_2.png) [@Armael](https://discuss.ocaml.org/u/Armael)\
**Post date:** [May 17, 2018, 10:07pm UTC](https://discuss.ocaml.org/t/ast-visitor-designs/2015/3 "2018-05-17T22:07:19Z")

</div>

The [manual of the visitors library](http://gallium.inria.fr/~fpottier/visitors/manual.pdf) is also a good read, I think.
