# I did a thing: minimal 'Prolog' interpreter and parser in Python

**URL:** <https://swi-prolog.discourse.group/t/i-did-a-thing-minimal-prolog-interpreter-and-parser-in-python/451>\
**Category:** General\
**Created:** [March 27, 2019, 3:12am UTC](https://swi-prolog.discourse.group/t/i-did-a-thing-minimal-prolog-interpreter-and-parser-in-python/451 "2019-03-27T03:12:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunokim](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/brunokim/32/3915_2.png) [@brunokim](https://swi-prolog.discourse.group/u/brunokim)\
**Post date:** [March 27, 2019, 3:12am UTC](https://swi-prolog.discourse.group/t/i-did-a-thing-minimal-prolog-interpreter-and-parser-in-python/451/1 "2019-03-27T03:12:23Z")

</div>

I wished to understand better how unification and backtracking work, and managed to implement a simple and inefficient solver in Python:

> <https://gist.github.com/brunokim/0a737a8642b756a5d0dcc3a07ec1ef81>

I got to admit that I’m now even more impressed with logic programming, as it was surprising to me how much can be done with this little capability. I implemented a limited Prolog parser in the same Gist, and plan to follow through until I get a REPL.

I hope this can be useful to others learning Prolog, because at least I am not content until I grasp the innards of a system. If there’s any easy way to also implement choicepoints and cuts, I’d be glad to learn.

---

<div class="post-metadata">

**Author:** ![abaljeu](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/abaljeu/32/136_2.png) [@abaljeu](https://swi-prolog.discourse.group/u/abaljeu)\
**Post date:** [March 27, 2019, 12:46pm UTC](https://swi-prolog.discourse.group/t/i-did-a-thing-minimal-prolog-interpreter-and-parser-in-python/451/2 "2019-03-27T12:46:09Z")

</div>

Nice work! Next step in your understanding is probably to read about the Warren Abstract Machine, a technology that is (was?) underlying efficient implementations of Prolog.

---

<div class="post-metadata">

**Author:** ![brunokim](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/brunokim/32/3915_2.png) [@brunokim](https://swi-prolog.discourse.group/u/brunokim)\
**Post date:** [October 1, 2021, 3:17am UTC](https://swi-prolog.discourse.group/t/i-did-a-thing-minimal-prolog-interpreter-and-parser-in-python/451/3 "2021-10-01T03:17:40Z")

</div>

Here I am, a pandemic later, having written a WAM interpreter in Python!

> **[GitHub - brunokim/prol: Demo of a WAM Prolog implementation in Python](https://github.com/brunokim/prol)**
>
> Demo of a WAM Prolog implementation in Python. Contribute to brunokim/prol development by creating an account on GitHub.

As I’m self-taught I’ve probably messed up somewhere, but I hope it’s useful to other people learning about compilers. I’d love some book/papers/online courses recommendations, that can give me both a solid ground, and also is up-to-date into logic programming developments from the last 30 years. I feel I’m missing on so much!

Special thanks to Markus Triska for his [personal page](http://metalevel.at) and to everyone that colaborated to the SWI-Prolog [glossary](https://www.swi-prolog.org/pldoc/man?section=glossary), they have been my companions for a while!
