
Prolog.c: a simple Prolog interpreter written in 200 LOC of C++ (2000) - adamnemecek
http://www.cl.cam.ac.uk/~am21/research/funnel/prolog.c
======
fspeech
I found Paul Tarau's work the easiest to follow on making a functional Prolog
without WAM, for example: [https://code.google.com/archive/p/kernel-
prolog/](https://code.google.com/archive/p/kernel-prolog/)

He also has theory papers explaining the architecture. For example:
[http://logic.cse.unt.edu/tarau/research/NewJinniPapers/fluen...](http://logic.cse.unt.edu/tarau/research/NewJinniPapers/fluents.html)

~~~
B1FF_PSUVM
WAM: "an abstract machine for the execution of Prolog"
[https://en.wikipedia.org/wiki/Warren_Abstract_Machine](https://en.wikipedia.org/wiki/Warren_Abstract_Machine)

(a couple of others in the Wikipedia disambiguation page are worrisome ...)

------
dbcurtis
Is there a good reason to still be using Prolog? I used Prolog back in the
day, but is it still the tool of choice for some projects?

~~~
justusw
Using DCGs
([https://en.wikipedia.org/wiki/Definite_clause_grammar](https://en.wikipedia.org/wiki/Definite_clause_grammar)),
you can easily create grammars for automated document parsing and generation.

You could even write a compiler
([http://comjnl.oxfordjournals.org/content/34/1/64.full.pdf](http://comjnl.oxfordjournals.org/content/34/1/64.full.pdf))
or disassembler
([http://www.dtic.mil/dtic/tr/fulltext/u2/a242987.pdf](http://www.dtic.mil/dtic/tr/fulltext/u2/a242987.pdf))
in Prolog fairly easy. All thanks to the really smooth support of tree-like
structures.

I do wonder why all this seems to be a little forgotten. Granted, the syntax
and semantics are a bit unusual, but the expressive power can hardly be
matched.

~~~
agumonkey
Thanks for these links. Another DCG tutorial
[http://www.pathwayslms.com/swipltuts/dcg/index.html](http://www.pathwayslms.com/swipltuts/dcg/index.html)

~~~
dbcurtis
Your link lightly addresses one of my questions about using DCGs for parsing.
How hard is it to get a sensible error message out of a DCG parser? I've
basically written off LALR parsers because getting a reasonable error message
out of them is about as much fun as repeatedly poking yourself in the eye with
a sharp stick. Good old recursive decent using precedence climbing for
expressions seems to be more maintainable in the long run for production
parsers.

------
stirner
Pedantic: C++ code should generally have a .cpp extension.

~~~
kchoudhu
You're right: that is pedantic -- in the worst sense of the word.

~~~
stirner
Actually, worse: there are actually lots of C++ file extensions and .cpp
doesn't even seem to be the most popular. I was mistaken, apologies.

------
vowelless
Would love to see it in C++11 or later.

~~~
hellofunk
It wouldn't necessary be much different if using C++11. Maybe using unique_ptr
instead of new, etc.

It certainly _could_ be a lot different, using a more functional approach, but
it likely wouldn't be, and would remain a basic OO program dressed in new
syntax.

------
timmytokyo
It leaks memory all over the place. Is it intended for tiny, short-lived
programs that don't generate a lot of garbage?

~~~
sitkack
program termination is a valid reclamation strategy

