├── .gitignore
├── CSProlog
├── PG
│ ├── go.bat
│ ├── jgo.bat
│ ├── pg4main.exe
│ ├── Parser.tpl
│ ├── JSON.grm
│ ├── JsonParser.cs
│ ├── JsonParserEx.cs
│ └── JSON.cs
├── BaseTerm.cs
├── Builtins.cs
├── Miscellaneous.cs
├── Internet.cs
├── TermSet.cs
├── CSProlog.csproj
├── CSProlog.exe.config
├── TermArray.cs
├── CrossRefTable.cs
├── TermNodeList.cs
├── IO.cs
├── ExternalUsage.cs
└── PredDescr.cs
├── README (2007-2014).doc
├── README (2007-2014).pdf
├── Docu
├── HistoryOfProlog.pdf
├── prolog-digital.pdf
├── Covington-NL-book.zip
├── Edinburgh-style IO.doc
├── Standard Operators.doc
├── KdeBosschere-parser.zip
└── KdeBosschere-prolog.pdf
├── README.txt
├── appveyor.yml
├── PLw
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── app.manifest
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Program.cs
├── PLw.sln
├── PLw.csproj
└── MainForm.cs
├── PL.NETcore
├── PL.NETcore.csproj
└── Main.cs
├── CSProlog.Core.Test
├── CSProlog.Core.Test.csproj
└── PrologEngine.cs
├── PLx
├── Properties
│ └── AssemblyInfo.cs
├── PLx.csproj
└── Program.cs
├── PLd
├── Properties
│ └── AssemblyInfo.cs
├── PLd.csproj
└── Main.cs
├── README.md
├── CSProlog.sln
├── LICENSE
└── .editorconfig
/.gitignore:
--------------------------------------------------------------------------------
1 | *.user
2 | *.suo
3 | bin/
4 | obj/
5 | packages/
6 | .vs/
7 | Dist/
--------------------------------------------------------------------------------
/CSProlog/PG/go.bat:
--------------------------------------------------------------------------------
1 | cls
2 |
3 | for %%f in (*.grm) do (PG4main %%~nf)
4 |
5 | PAUSE
6 |
--------------------------------------------------------------------------------
/CSProlog/PG/jgo.bat:
--------------------------------------------------------------------------------
1 | cls
2 |
3 | PG4main JSON
4 |
5 | REM copy Json.cs ..
6 |
7 | PAUSE
8 |
--------------------------------------------------------------------------------
/CSProlog/BaseTerm.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/CSProlog/BaseTerm.cs
--------------------------------------------------------------------------------
/CSProlog/Builtins.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/CSProlog/Builtins.cs
--------------------------------------------------------------------------------
/README (2007-2014).doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/README (2007-2014).doc
--------------------------------------------------------------------------------
/README (2007-2014).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/README (2007-2014).pdf
--------------------------------------------------------------------------------
/CSProlog/Miscellaneous.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/CSProlog/Miscellaneous.cs
--------------------------------------------------------------------------------
/CSProlog/PG/pg4main.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/CSProlog/PG/pg4main.exe
--------------------------------------------------------------------------------
/Docu/HistoryOfProlog.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/HistoryOfProlog.pdf
--------------------------------------------------------------------------------
/Docu/prolog-digital.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/prolog-digital.pdf
--------------------------------------------------------------------------------
/Docu/Covington-NL-book.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/Covington-NL-book.zip
--------------------------------------------------------------------------------
/Docu/Edinburgh-style IO.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/Edinburgh-style IO.doc
--------------------------------------------------------------------------------
/Docu/Standard Operators.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/Standard Operators.doc
--------------------------------------------------------------------------------
/Docu/KdeBosschere-parser.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/KdeBosschere-parser.zip
--------------------------------------------------------------------------------
/Docu/KdeBosschere-prolog.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsakamoto/CSharpProlog/HEAD/Docu/KdeBosschere-prolog.pdf
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | Version 4.1 -- September 2015
2 |
3 | Licensing scheme changed into LGPL.
4 |
5 | Only a few bugfixes (bug in weekno/1/2) and two new predicates (bw_transform/3, combination/3).
6 |
7 | John Pool
8 | Amersfoort
9 | Netherlands
10 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 | image: Visual Studio 2019
3 | configuration: Debug
4 | before_build:
5 | - cmd: dotnet restore CSProlog.sln
6 | build:
7 | project: CSProlog.sln
8 | test_script:
9 | - cmd: >-
10 | cd .\CSProlog.Core.Test
11 |
12 | dotnet test
--------------------------------------------------------------------------------
/PLw/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/PL.NETcore/PL.NETcore.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/CSProlog.Core.Test/CSProlog.Core.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PLw/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace Prolog
6 | {
7 | static class Program
8 | {
9 | ///
10 | /// The main entry point for the application.
11 | ///
12 | [STAThread]
13 | static void Main(string[] args)
14 | {
15 | if (args.Length > 0) // batch processing assumed if arguments supplied
16 | {
17 | Prolog.MainForm.BatIO batIO = null;
18 |
19 | try
20 | {
21 | PrologEngine e = new PrologEngine(batIO = new Prolog.MainForm.BatIO());
22 | e.ProcessArgs(args, true);
23 | Application.Exit();
24 |
25 | return;
26 | }
27 | finally
28 | {
29 | if (batIO != null) batIO.Close();
30 | }
31 | }
32 |
33 | Application.EnableVisualStyles();
34 | Application.SetCompatibleTextRenderingDefault(false);
35 | Application.Run(new MainForm());
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/PLw/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Prolog.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/PLw/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle ("MyNameSpace")]
9 | [assembly: AssemblyDescription ("")]
10 | [assembly: AssemblyConfiguration ("")]
11 | [assembly: AssemblyCompany ("Omnext bv")]
12 | [assembly: AssemblyProduct ("MyNameSpace")]
13 | [assembly: AssemblyCopyright ("Copyright © Omnext bv 2009")]
14 | [assembly: AssemblyTrademark ("")]
15 | [assembly: AssemblyCulture ("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible (false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid ("12ce91b6-4e9a-48a9-a4d2-d30a24cfdf6c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | [assembly: AssemblyVersion ("1.0.0.0")]
33 | [assembly: AssemblyFileVersion ("1.0.0.0")]
34 |
--------------------------------------------------------------------------------
/PLw/PLw.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 10.00
2 | # Visual Studio 2008
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PLw", "PLw.csproj", "{BB06ADF9-92C3-4F92-8397-5ACC92208528}"
4 | EndProject
5 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSProlog0", "..\CSProlog0\CSProlog0.csproj", "{FAFEC859-6218-4C55-99EC-5948B5295047}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|Any CPU = Debug|Any CPU
10 | Release|Any CPU = Release|Any CPU
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {BB06ADF9-92C3-4F92-8397-5ACC92208528}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14 | {BB06ADF9-92C3-4F92-8397-5ACC92208528}.Debug|Any CPU.Build.0 = Debug|Any CPU
15 | {BB06ADF9-92C3-4F92-8397-5ACC92208528}.Release|Any CPU.ActiveCfg = Release|Any CPU
16 | {BB06ADF9-92C3-4F92-8397-5ACC92208528}.Release|Any CPU.Build.0 = Release|Any CPU
17 | {FAFEC859-6218-4C55-99EC-5948B5295047}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {FAFEC859-6218-4C55-99EC-5948B5295047}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {FAFEC859-6218-4C55-99EC-5948B5295047}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {FAFEC859-6218-4C55-99EC-5948B5295047}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(SolutionProperties) = preSolution
23 | HideSolutionNode = FALSE
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/PLx/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle ("PLx")]
9 | [assembly: AssemblyDescription ("")]
10 | [assembly: AssemblyConfiguration ("")]
11 | [assembly: AssemblyCompany ("")]
12 | [assembly: AssemblyProduct ("PLx")]
13 | [assembly: AssemblyCopyright ("Copyright © 2013")]
14 | [assembly: AssemblyTrademark ("")]
15 | [assembly: AssemblyCulture ("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible (false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid ("7702f6aa-1360-4be3-9c4a-8bb6bbc92870")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion ("1.0.0.0")]
36 | [assembly: AssemblyFileVersion ("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/PLw/Properties/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/PLd/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle ("DosBox")]
9 | [assembly: AssemblyDescription ("")]
10 | [assembly: AssemblyConfiguration ("")]
11 | [assembly: AssemblyCompany ("Omnext bv")]
12 | [assembly: AssemblyProduct ("DosBox")]
13 | [assembly: AssemblyCopyright ("Copyright © Omnext bv 2011")]
14 | [assembly: AssemblyTrademark ("")]
15 | [assembly: AssemblyCulture ("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible (false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid ("3cebd261-0173-453c-825a-ade52212c8c7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion ("1.0.0.0")]
36 | [assembly: AssemblyFileVersion ("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CSProlog/Internet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Net.Mail;
4 | using System.Security.Cryptography.X509Certificates;
5 |
6 | namespace Prolog
7 | {
8 | public partial class PrologEngine
9 | {
10 | #region engine-mail
11 | static bool SendMail(string smtpHost, int port, string toAddr, string subject, string body)
12 | {
13 | try
14 | {
15 | SmtpClient client = new SmtpClient(smtpHost, port);
16 | MailAddress from = new MailAddress("xxxxxx@xxxxxx.xx");
17 | MailAddress to = new MailAddress(toAddr);
18 | MailMessage msg = new MailMessage();
19 | msg.From = from;
20 | msg.To.Add(to);
21 | msg.Subject = subject;
22 | msg.Body = body;
23 | //client.EnableSsl = true;
24 | //ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy ();
25 | client.Send(msg);
26 | //client.SendAsync (msg, userState);
27 |
28 | //Attachment attachment = new Attachment ("you attachment file");
29 | //msg.Attachments.Add (attachment);
30 |
31 | return true;
32 | }
33 | catch (Exception x)
34 | {
35 | IO.Warning("Unable to send message. Reason was:\r\n{0}", x.Message);
36 |
37 | return false;
38 | }
39 | }
40 |
41 |
42 | class AcceptAllCertificatePolicy : ICertificatePolicy
43 | {
44 | public AcceptAllCertificatePolicy()
45 | {
46 | }
47 |
48 | public bool CheckValidationResult(ServicePoint sPoint,
49 | X509Certificate cert, WebRequest wRequest, int certProb)
50 | {
51 | // Always accept
52 | return true;
53 | }
54 | }
55 | #endregion engine-mail
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CSharpProlog [](https://www.nuget.org/packages/CSProlog/) [](https://ci.appveyor.com/project/jsakamoto/csharpprolog)
2 | A C# implementation of Prolog
3 |
4 | ```csharp
5 | // PM> Install-Package CSProlog -pre
6 | using System;
7 | using Prolog;
8 |
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | var prolog = new PrologEngine(persistentCommandHistory: false);
14 |
15 | // 'socrates' is human.
16 | prolog.ConsultFromString("human(socrates).");
17 | // human is bound to die.
18 | prolog.ConsultFromString("mortal(X) :- human(X).");
19 |
20 | // Question: Shall 'socrates' die?
21 | var solution = prolog.GetFirstSolution(query: "mortal(socrates).");
22 | Console.WriteLine(solution.Solved); // = "True" (Yes!)
23 | }
24 | }
25 | ```
26 | ## Installation
27 |
28 | Run the following command from the Visual Studio Package Manager Console to install the latest version:
29 |
30 | `Install-Package CSProlog`
31 |
32 | The NuGet page can be found here:\
33 |
34 |
35 | ## Solution Layout
36 | ### CSProlog
37 | Prolog Engine
38 |
39 | ### CSProlog.Core.Test
40 | Unit Tests
41 |
42 | ### PL.NETCore
43 | Dotnet Core Console Interactive Interpreter (tested in linux and windows)
44 |
45 | ### PLd
46 | DOS Console Interactive Interpreter
47 |
48 | ### PLw
49 | Windows Forms Example
50 |
51 | ### PLx
52 | An example of how to use the engine within another Program
53 |
54 |
55 | ## For more documents
56 |
57 | Earlier release documents can be found in [README (2007-2014).pdf](README%20(2007-2014).pdf).
58 |
59 | ## Release Notes
60 |
61 | ### v.6.0.0
62 |
63 | - BREAKING CHANGE: Remove "SAMPLES, TESTING & EXPERIMENTAL" predefined predicates. (including CHAT-80 support)
64 | - Fix: "help" predefined predicate dose not work.
65 | - Enhance: GetAllSolutions can work with null file name.
66 |
67 | ### v.5.0.0.1
68 |
69 | - Support: .NET Standard 1.4 (.NET Core) and UWP
70 |
71 | ### v.5.0.0
72 |
73 | - BREAKING CHANGE: Remove dependency of "System.Windows.Forms".
74 | - NuGet package release
75 |
76 | ### Older versions
77 |
78 | Earlier release notes can be found in [README (2007-2014).pdf](README%20(2007-2014).pdf).
79 |
80 | ## License
81 |
82 | [GNU LGPL v.3](LICENSE)
83 |
--------------------------------------------------------------------------------
/CSProlog/TermSet.cs:
--------------------------------------------------------------------------------
1 | /*-----------------------------------------------------------------------------------------
2 |
3 | C#Prolog -- Copyright (C) 2007-2015 John Pool -- j.pool@ision.nl
4 |
5 | This library is free software; you can redistribute it and/or modify it under the terms of
6 | the GNU Lesser General Public License as published by the Free Software Foundation; either
7 | version 3.0 of the License, or any later version.
8 |
9 | This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 | See the GNU Lesser General Public License (http://www.gnu.org/licenses/lgpl-3.0.html), or
12 | enter 'license' at the command prompt.
13 |
14 | -------------------------------------------------------------------------------------------*/
15 |
16 | using System.Collections.Generic;
17 |
18 | namespace Prolog
19 | {
20 | public enum DupMode { DupIgnore, DupAccept, DupError };
21 |
22 | public partial class PrologEngine
23 | {
24 | public class BaseTermSet : List
25 | {
26 | DupMode dupMode;
27 |
28 | public BaseTermSet()
29 | {
30 | dupMode = DupMode.DupAccept;
31 | }
32 |
33 |
34 | public BaseTermSet(DupMode dm)
35 | {
36 | dupMode = dm;
37 | }
38 |
39 |
40 | public BaseTermSet(BaseTerm list)
41 | {
42 | while (list.Arity == 2)
43 | {
44 | Add(list.Arg(0));
45 | list = list.Arg(1);
46 | }
47 | }
48 |
49 |
50 | public void Insert(BaseTerm termToInsert)
51 | {
52 | int i = BinarySearch(termToInsert);
53 |
54 | if (i >= 0) // found
55 | {
56 | if (dupMode == DupMode.DupAccept) Insert(i, termToInsert);
57 | }
58 | else
59 | Insert(~i, termToInsert);
60 | }
61 |
62 |
63 | public ListTerm ToList()
64 | {
65 | ListTerm t = ListTerm.EMPTYLIST;
66 |
67 | for (int i = Count - 1; i >= 0; i--)
68 | t = new ListTerm(this[i], t); // [a0, a0, ...]
69 |
70 | return t;
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/CSProlog.Core.Test/PrologEngine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 | using Prolog;
4 |
5 | namespace CSProlog.Core.Test
6 | {
7 | public class PrologEngineTest
8 | {
9 | [Fact]
10 | public void ConsultFromString_GetOneSolution()
11 | {
12 | var prolog = new PrologEngine(persistentCommandHistory: false);
13 |
14 | // 'socrates' is human.
15 | prolog.ConsultFromString("human(socrates).");
16 | // 'R2-D2' is droid.
17 | prolog.ConsultFromString("droid(r2d2).");
18 | // human is bound to die.
19 | prolog.ConsultFromString("mortal(X) :- human(X).");
20 |
21 | // Question: Shall 'socrates' die?
22 | var solution1 = prolog.GetFirstSolution(query: "mortal(socrates).");
23 | Assert.True(solution1.Solved); // = "True" (Yes)
24 |
25 | // Question: Shall 'R2-D2' die?
26 | var solution2 = prolog.GetFirstSolution(query: "mortal(r2d2).");
27 | Assert.False(solution2.Solved); // = "False" (No)
28 | }
29 |
30 | [Fact]
31 | public void ConsultFromString_GetAllSolutions_Adhoc()
32 | {
33 | var prolog = new PrologEngine(persistentCommandHistory: false);
34 |
35 | // 'socrates' is human.
36 | prolog.ConsultFromString("human(socrates).");
37 | // 'R2-D2' is droid.
38 | prolog.ConsultFromString("droid(r2d2).");
39 | // human is bound to die.
40 | prolog.ConsultFromString("mortal(X) :- human(X).");
41 |
42 | prolog.GetFirstSolution(query: "listing.");
43 |
44 | SolutionSet solutionset1 = prolog.GetAllSolutions(null, "human(H)");
45 | Console.WriteLine("=====================================");
46 | Console.WriteLine(solutionset1.ErrMsg);
47 | Console.WriteLine("=====================================");
48 | Assert.True(solutionset1.Success);
49 | if (solutionset1.Success)
50 | {
51 | var s = solutionset1[0];
52 | foreach (Variable v in s.NextVariable)
53 | Console.WriteLine(string.Format("{0} ({1}) = {2}", v.Name, v.Type, v.Value));
54 |
55 | }
56 |
57 | }
58 |
59 | [Fact]
60 | public void HelpTest()
61 | {
62 | var prolog = new PrologEngine(persistentCommandHistory: false);
63 | var s1 = prolog.GetFirstSolution("help.");
64 | Assert.True(s1.Solved); // = "True" (Yes) [help atleast ran]
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/PLw/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace Prolog.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Prolog.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/PLd/PLd.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.21022
7 | 2.0
8 | {B7438FBF-6E46-4065-A60B-1B1CA2AC9875}
9 | Exe
10 | Properties
11 | Prolog
12 | PLd
13 | v3.5
14 | 512
15 |
16 |
17 |
18 |
19 | 3.5
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 | x86
30 |
31 |
32 | pdbonly
33 | true
34 | bin\Debug\
35 | TRACE
36 | prompt
37 | 4
38 |
39 |
40 |
41 |
42 | 3.5
43 |
44 |
45 | 3.5
46 |
47 |
48 | 3.5
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {6a947b78-96d1-45f2-bb9f-036586bab544}
60 | CSProlog
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/PLx/PLx.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.21022
7 | 2.0
8 | {E84A59D2-E868-4108-BE9A-55CBB7E85E36}
9 | Exe
10 | Properties
11 | PLx
12 | PLx
13 | v3.5
14 | 512
15 |
16 |
17 |
18 |
19 | 3.5
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 | x86
30 |
31 |
32 | pdbonly
33 | true
34 | bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 |
39 |
40 |
41 |
42 | 3.5
43 |
44 |
45 | 3.5
46 |
47 |
48 | 3.5
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {6a947b78-96d1-45f2-bb9f-036586bab544}
60 | CSProlog
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/CSProlog/PG/Parser.tpl:
--------------------------------------------------------------------------------
1 | //#define LL1_tracing
2 | namespace
3 | {
4 | using System;
5 | using System.IO;
6 | using System.Text;
7 | using System.Xml;
8 | using System.Collections;
9 | using System.Collections.Generic;
10 | using System.Collections.Specialized;
11 | using System.Globalization;
12 | using System.Threading;
13 | using System.Diagnostics;
14 | using System.Security.Principal;
15 |
16 |
17 | public partial class PrologEngine
18 | {
19 | #region Parser
20 | public partial class Parser : BaseParser<>
21 | {
22 | public static readonly string VersionTimeStamp = "";
23 |
24 |
25 | #region Terminal definition
26 |
27 |
28 | #endregion Terminal definition
29 |
30 | #region Constructor
31 |
32 | public Parser (PrologEngine engine)
33 | {
34 | this.engine = engine;
35 | ps = engine.Ps;
36 | terminalTable = engine.terminalTable;
37 | opTable = engine.OpTable;
38 | symbol = new Symbol (this);
39 | streamInPrefix = "";
40 | streamInPreLen = 0;
41 | AddReservedOperators ();
42 | }
43 |
44 |
45 | public Parser ()
46 | {
47 | terminalTable = new BaseTrie (terminalCount, false);
48 | FillTerminalTable (terminalTable);
49 | symbol = new Symbol (this);
50 | streamInPrefix = "";
51 | streamInPreLen = 0;
52 |
53 | AddReservedOperators ();
54 |
55 | }
56 | #endregion constructor
57 |
58 | #region NextSymbol, GetSymbol
59 | protected override bool GetSymbol (TerminalSet followers, bool done, bool genXCPN<;RDPDecl/>)
60 | {
61 | string s;
62 |
63 | if (symbol.IsProcessed) NextSymbol ();
64 |
65 | symbol.SetProcessed (done);
66 | if (parseAnyText || followers.IsEmpty ()) return true;
67 |
68 | if (syntaxErrorStat) return false;
69 |
70 | if (symbol.TerminalId == ANYSYM || followers.Contains (symbol.TerminalId)) return true;
71 |
72 | switch (symbol.TerminalId)
73 | {
74 | case EndOfLine:
75 | if (seeEndOfLine) s = ""; else goto default;
76 | s = "";
77 | break;
78 | case EndOfInput:
79 | s = "";
80 | break;
81 | default:
82 | s = String.Format ("\"{0}\"", symbol.ToString ());
83 | break;
84 | }
85 |
86 | s = String.Format ("*** Unexpected symbol: {0}{1}*** Expected one of: {2}", s,
87 | Environment.NewLine, terminalTable.TerminalImageSet (followers));
88 | if (genXCPN)
89 | SyntaxError = s;
90 | else
91 | errorMessage = s;
92 |
93 | return true;
94 | }
95 | #endregion NextSymbol, GetSymbol
96 |
97 | #region PARSER PROCEDURES
98 | public override void RootCall ()
99 | {
100 |
101 | }
102 |
103 |
104 | public override void Delegates ()
105 | {
106 |
107 | }
108 |
109 |
110 | #endregion PARSER PROCEDURES
111 | }
112 | #endregion Parser
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/CSProlog/CSProlog.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard1.4;net35
5 | $(NoWarn);1591
6 | true
7 | CSProlog
8 | C#Prolog (CSProlog)
9 | $(AssemblyTitle)
10 | CSProlog
11 | 1.6.0
12 | $(PackageTargetFallback);dnxcore50
13 | CSProlog
14 | 6.0.0.0
15 | John Pool,Amersfoort,Netherlands,J.Sakamoto,Josh Ahlstrom
16 | N/A
17 | C#Prolog -- A Prolog interpreter written in C#.
18 | Can easily be integrated in C# programs.
19 | Characteristics: reliable and fairly fast interpreter, command line interface, builtin DCG, XML- and JSON-predicates, SQL-predicates, extendible.
20 | Copyright (C) 2007-2015 John Pool -- j.pool@ision.nl
21 | https://github.com/jsakamoto/CSharpProlog/blob/vnext/master/LICENSE
22 | https://github.com/jsakamoto/CSharpProlog/
23 | Prolog interpreter
24 | v.6.0.0
25 | - BREAKING CHANGE: Remove "SAMPLES, TESTING & EXPERIMENTAL" predefined predicates. (including CHAT-80 support)
26 | - Fix: "help" predefined predicate dose not work.
27 | - Enhance: GetAllSolutions can work with null file name.
28 | v.5.0.0.1
29 | - Support: .NET Standard 1.4 (.NET Core) and UWP
30 | v.5.0.0
31 | - BREAKING CHANGE: Remove dependency of "System.Windows.Forms".
32 | - NuGet package release
33 | true
34 |
35 |
36 |
37 | TRACE;NETSTANDARD;RELEASE;NETSTANDARD1_4;RELEASE;NETSTANDARD1_4
38 |
39 |
40 | TRACE;DEBUG;NETSTANDARD
41 |
42 |
43 | TRACE;RELEASE;mswindows;net35
44 |
45 |
46 | TRACE;DEBUG;mswindows;net35
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/CSProlog/PG/JSON.grm:
--------------------------------------------------------------------------------
1 | /*
2 | Grammar for JSON data, following http://www.json.org/
3 | and compliant with http://www.ietf.org/rfc/rfc4627
4 |
5 | "Start Symbol" =
6 | "Case Sensitive" = True
7 | "Character Mapping" = 'Unicode'
8 |
9 | ! ------------------------------------------------- Sets
10 |
11 | {Unescaped} = {All Valid} - {&1 .. &19} - ["\]
12 | {Hex} = {Digit} + [ABCDEFabcdef]
13 | {Digit9} = {Digit} - [0]
14 |
15 | ! ------------------------------------------------- Terminals
16 |
17 | Number = '-'?('0'|{Digit9}{Digit}*)('.'{Digit}+)?([Ee][+-]?{Digit}+)?
18 | String = '"'({Unescaped}|'\'(["\/bfnrt]|'u'{Hex}{Hex}{Hex}{Hex}))*'"'
19 |
20 | ! ------------------------------------------------- Rules
21 |
22 | ::=