项目作者: luciangreen

项目描述 :
Converts List Prolog code to Prolog code.
高级语言: Prolog
项目地址: git://github.com/luciangreen/List-Prolog-to-Prolog-Converter.git
创建时间: 2019-11-10T05:08:03Z
项目社区:https://github.com/luciangreen/List-Prolog-to-Prolog-Converter

开源协议:BSD 3-Clause "New" or "Revised" License

下载


List-Prolog-to-Prolog-Converter

Converts List Prolog code to Prolog code.

List Prolog (LP) Interpreter (available here) is an interpreter for a different version of Prolog that is in list format, making it easier to generate List Prolog programs. The LP interpreter is an algorithm that parses and runs List Prolog code. The converter helps convert List Prolog programs to Prolog programs. The interpreter and converter are written in SWI-Prolog.

Prerequisites

  • Use a search engine to find the Homebrew (or other) Terminal install command for your platform and install it, and search for the Terminal command to install swipl using Homebrew and install it or download and install SWI-Prolog for your machine at SWI-Prolog.

Mac, Linux and Windows (with Linux commands installed): Prepare to run swipl

  • In Terminal settings (Mac), make Bash the default shell:
  1. /bin/bash
  • In Terminal, edit the text file ~/.bashrc using the text editor Nano:
  1. nano ~/.bashrc
  • Add the following to the file ~/.bashrc:
  1. export PATH="$PATH:/opt/homebrew/bin/"
  • Link to swipl in Terminal:
  1. sudo ln -s /opt/homebrew/bin/swipl /usr/local/bin/swipl

1. Install manually

Download this repository, the List Prolog Interpreter Repository and the Text to Breasonings Repository.

2. Or Install from List Prolog Package Manager (LPPM)

  1. mkdir GitHub
  2. cd GitHub/
  3. git clone https://github.com/luciangreen/List-Prolog-Package-Manager.git
  4. cd List-Prolog-Package-Manager
  5. swipl
  6. ['lppm'].
  7. lppm_install("luciangreen","List-Prolog-to-Prolog-Converter").
  8. ../
  9. halt.

Running

  • In Shell:
    cd List-Prolog-to-Prolog-Converter
    swipl
    ['../listprologinterpreter/listprolog'].

  • Load the List Prolog to Prolog Converter by typing:
    ['lp2pconverter'].

  • The converter is called in the form:
    test(Number,_,Algorithm1,_),lp2p1(Algorithm1,Algorithm2),write(Algorithm2).

Where:
Number - Test number of algorithm to convert (taken from “lpiverify4.pl”).
Algorithm1 - is the List Prolog algorithm to convert.
Algorithm2 - is the Prolog algorithm produced.

  • For example:
    1. test(1,_,A,_),lp2p1(A,B),write(B).
    2. function(A,B,C):-+(A,B,C).
  1. test(2,_,A,_),lp2p1(A,B),write(B).
  2. function(A,B,C):-+(A,B,D),+(D,1,C).
  1. test(3,_,A,_),lp2p1(A,B),write(B).
  2. function(A,B,C):-function2(D,F),+(A,B,E),+(E,F,G),+(G,D,C).
  3. function2(A,F):-is(A,2),is(F,1).
  1. test(4,_,A,_),lp2p1(A,B),write(B).
  2. append1(A):-b(B),c(C),append(B,C,A).
  3. b(["b"]).
  4. c(["c"]).
  1. test(15,_,A,_),lp2p1(A,B),write(B).
  2. grammar1(U,T):-compound(U,"",[],T).
  3. compound213(U,U,T,T).
  4. compound(T,U)->"[","]",compound213(T,U).
  5. compound(T,U)->"[",compound21(T,V),"]",compound213(V,U).
  6. compound212(U,U,T,T).
  7. compound21(T,U)->item(I),lookahead("]"),{wrap(I,Itemname1),append(T,Itemname1,V)},compound212(V,U).
  8. compound21(T,U)->item(I),",",compound21([],Compound1name),{wrap(I,Itemname1),append(T,Itemname1,V),append(V,Compound1name,U)}.
  9. item(T)->"\"",word21("",T),"\"".
  10. item(T)->number21("",U),{stringtonumber(U,T)}.
  11. item(T)->word21_atom("",T1),{atom_string(T,T1)}.
  12. item(T)->compound([],T).
  13. number212(U,U,T,T).
  14. number21(T,U)->A,commaorrightbracketnext,{((stringtonumber(A,A1),number(A1))->(true);((equals4(A,".")->(true);(equals4(A,"-"))))),stringconcat(T,A,V)},number212(V,U).
  15. number21(T,U)->A,{((stringtonumber(A,A1),number(A1))->(true);((equals4(A,".")->(true);(equals4(A,"-"))))),stringconcat(T,A,V)},number21("",Numberstring),{stringconcat(V,Numberstring,U)}.
  16. word212(U,U,T,T).
  17. word21(T,U)->A,quote_next,{not((=(A,"\""))),stringconcat(T,A,V)},word212(V,U).
  18. word21(T,U)->A,{not((=(A,"\""))),stringconcat(T,A,V)},word21("",Wordstring),{stringconcat(V,Wordstring,U)}.
  19. word212_atom(U,U,T,T).
  20. word21_atom(T,U)->A,commaorrightbracketnext,{not((=(A,"\""))),not((=(A,"["))),not((=(A,"]"))),stringconcat(T,A,V)},word212_atom(V,U).
  21. word21_atom(T,U)->A,{not((=(A,"\""))),not((=(A,"["))),not((=(A,"]"))),stringconcat(T,A,V)},word21_atom("",Wordstring),{stringconcat(V,Wordstring,U)}.
  22. commaorrightbracketnext->lookahead(",").
  23. commaorrightbracketnext->lookahead("]").
  24. quote_next->lookahead("\"").
  25. lookahead(A,A,B):-stringconcat(B,D,A).

Tests

Authors

Lucian Green - Initial programmer - Lucian Academy

License

I licensed this project under the BSD3 License - see the LICENSE.md file for details