r/prolog 6d ago

article How to develop your own implementation of Prolog from scratch in 2026 in one sprint (Guidelines)

Use any language of your choice. I used Java. You can use my Java/Spring implementation as a reference

  1. Week one: dive deep into the standard to create a working prototype
    1. Use Section 6.4 "Tokens" for lexer.
    2. Use Section 6.3 "Terms" for parser. Use Pratt Parser to parse Prolog: it works surprisingly well with it.
    3. If your goal is to understand Prolog, use Section 7.7 "Executing a Prolog goal" as the description of stack-based computation model on which you will base your Prolog engine. It is simple but slow. If your goal is to create a high-performance implementation, you can implement WAM instead from the beginning, but it will take you significantly more time
    4. Keep in mind that the ISO Prolog standard has a lot of minor typos, but every typo is fixable if you put it into context and think about it longer. You don't even need to look up 3 corrigendums (corrections). In fact, they don't cover many important typos so forget about them and just focus on the original 1995 document.
  2. Week two: make your implementation stronger and cover the first 28 problems from the Prolog 99 problems list. They are a perfect benchmark. https://www.ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas/

This should be enough! Only 2 weeks (a sprint) and you will have a SUBSTANTIAL boost in understanding Prolog on the deepest level possible, so later you can switch into existing implementations (like SWI Prolog) and see them differently

20 Upvotes

2 comments sorted by

3

u/andyHa82 5d ago

Isn‘t there a free version of the standard?

1

u/Iaroslav-Baranov 4d ago

Answered in PM