Skip to content

brunokim/prol

Repository files navigation

Prol: WAM demo

This is a simplified Warren Abstract Machine (WAM) implementation for Prolog, that showcases the main instructions, compiling, register allocation and machine functions.

Documentation

🇧🇷 🇵🇹 Veja a documentação em Português! 🇦🇴 🇲🇿

  1. About Prolog: a hurried primer if you don't know what it is about.
  2. Resolution strategy: how a query is actually solved in Prolog.
  3. Warren Abstract Machine: details about the implementation attempted here.
  4. Indexing: indexing implementation to fast-track some call patterns.
  5. Parsing: explaining basic structures for parsing
  6. Grammar: documentation for the sample application of grammar parsing.
  7. Stuff left out: what this implementation has simplified from the WAM, and references.

Code organization

  • model.py: Data objects representing terms, programs, and machine entities.
  • compiler.py: Compiling of a list of rules into a list of instructions.
  • interpreter.py: Interpreter that execute the instruction listing for a given query.
  • grammar.py: Sample application of interpreter, with a grammar that can parse itself. Try it out with python -m grammar and compare with the text in the file!

Debug viewer

After creating a Machine() object, you may set its debug_filename attribute with the name of a file where it writes the machine's internal state as a JSON for each iteration. You may visualize the execution by running an HTTP server within the debug/ folder, e.g. with python -m http.server, and loading the JSONL file.

Screenshot of debug view, showcasing instructions, register values and controls

As a sample, debugtest/interpreter.jsonl contains the execution for interpreter.py. If you wish to dump execution for some grammar tests, run pytest --debug_grammar. Warning: debug dumping is slooow.

About

Demo of a WAM Prolog implementation in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published