Beispiel #1
1
        public static void Main(string [] args)
        {
            PrologEngine e = null;

              try
              {
            e = new PrologEngine (new DosIO ());

            // ProcessArgs -- for batch processing. Can be left out if not used
            if (e.ProcessArgs (args, false)) return;

            SetPreferredConsoleProperties (e);
            Console.Title = "C#Prolog command window";
            Console.WriteLine (PrologEngine.IntroText);
            Console.WriteLine ("\r\n--- Enter !! for command history, help for a list of all commands");

            //if (Engine.ConfigSettings.InitialConsultFile != null)   // set in CSProlog.exe.config
            //  e.Consult (Engine.ConfigSettings.InitialConsultFile); // any additional initialisations

            while (!e.Halted)
            {
              Console.Write (e.Prompt);
              e.Query = ReadQuery ();

              // Use e.GetFirstSolution instead of the loop below if you want the first solution only.
              //Console.Write (e.GetFirstSolution (e.Query));

              foreach (PrologEngine.ISolution s in e.SolutionIterator)
              {
            // In order to get the individual variables:
            //foreach (Engine.IVarValue varValue in s.VarValuesIterator)
            // { Console.WriteLine (varValue.Value.To<int> ()); } // or ToString () etc.
            Console.Write (s);

            if (s.IsLast || !UserWantsMore ()) break;
              }

              Console.WriteLine ();
            }
              }
              catch (Exception x)
              {
            Console.WriteLine ("Error while initializing Prolog Engine. Message was:\r\n{0}",
              x.GetBaseException ().Message + Environment.NewLine + x.StackTrace);
            Console.ReadLine ();
              }
              finally
              {
            if (e != null) e.PersistCommandHistory (); // cf. CSProlog.exe.config
              }
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            PrologEngine e = new PrologEngine();
            // Example 1 -- the age/2 predicate is a builtin example; defined in Bootstrap.cs

            Console.WriteLine("Example 1");
            Console.WriteLine();

            SolutionSet ss = e.GetAllSolutions(@"..\..\..\..\Prolog_Predicats.pl", "test_predicate(P,N)");

            if (ss.Success)
            {
                for (int i = 0; i < ss.Count; i++) // or: foreach (Solution s in ss.NextSolution)
                {
                    Solution s = ss[i];
                    Console.WriteLine("Solution {0}", i + 1);

                    foreach (Variable v in s.NextVariable)
                        Console.WriteLine(string.Format("{0} ({1}) = {2}", v.Name, v.Type, v.Value));
                }
            }
            else
                Console.WriteLine("Failure");
        }
Beispiel #3
0
 public PredicateTable(PrologEngine engine)
 {
     this.engine         = engine;
     predTable           = new Dictionary <string, PredicateDescr> ();
     crossRefTable       = new CrossRefTable();
     crossRefInvalid     = true;
     predefineds         = new Hashtable();
     moduleName          = new Hashtable();
     definedInCurrFile   = new Hashtable();
     isDiscontiguous     = new Hashtable();
     actionWhenUndefined = new Dictionary <string, UndefAction> ();
     consultFileStack    = new Stack <string> ();
     consultParserStack  = new Stack <PrologParser> ();
 }
Beispiel #4
0
 static void SetPreferredConsoleProperties(PrologEngine e)
 {
     Console.ForegroundColor = ConsoleColor.DarkBlue;
     Console.BackgroundColor = ConsoleColor.White;
     Console.Clear(); // applies the background color to the *entire* window background
     Console.WindowWidth  = 140;
     Console.WindowHeight = 60;
     Console.BufferWidth  = 140;
     Console.BufferHeight = 3000;
     Console.WindowTop    = 0;
     Console.WindowLeft   = 0;
     // The following line prevents ^C from exiting the application
     Console.CancelKeyPress += new ConsoleCancelEventHandler(e.Console_CancelKeyPress);
 }
Beispiel #5
0
            public override void TreePrint(int level, PrologEngine engine)
            {
                string margin = Spaces(2 * level);

                engine.WriteLine("{0}{1}", margin, PrologParser.LISTPATOPEN);

                BaseTerm t = ChainEnd();

                foreach (ListPatternElem e in args)
                {
                    engine.WriteLine("  {0}{1}", margin, e);
                }

                engine.WriteLine("{0}{1}", margin, PrologParser.LISTPATCLOSE);
            }
Beispiel #6
0
        // Get all solutions of the input query
        List <Solution> GetSolutions(PrologEngine plEngine, string query)
        {
            List <Solution> solutions = new List <Solution>();
            Solution        solution  = new Solution();

            // If string is in the query, convert to list
            query       = StringToList(query);
            Label2.Text = query;

            // Set Query
            if (SyntaxCheck(query))
            {
                plEngine.Query = query;
            }
            else
            {
                solution.Note = "ERROR";
                solutions.Add(solution);
                return(solutions);
            }


            // Get All Solutions
            foreach (PrologEngine.ISolution s in plEngine.SolutionIterator)
            {
                // The No of Solutions is ZERO, the solution is True or False
                if (s.VarValuesIterator.Count() == 0)
                {
                    solution.Note = "ZERO";
                    solution.Name = s.Solved.ToString();
                    solutions.Add(solution);
                    break;
                }

                foreach (PrologEngine.IVarValue v in s.VarValuesIterator)
                {
                    solutions.Add(new Solution()
                    {
                        Name  = v.Name,
                        Type  = v.DataType,
                        Value = v.Value.ToString(),
                        Note  = ""
                    });
                }
                //if (s.IsLast) break;
            }
            return(solutions);
        }
Beispiel #7
0
            public virtual void TreePrint(int level, PrologEngine e)
            {
                e.Write(Spaces(2 * level));

                if (this is Variable)
                {
                    e.WriteLine(this.ToString());
                }
                else
                {
                    e.WriteLine(FunctorToString);

                    if (arity > 0)
                    {
                        foreach (BaseTerm a in args)
                        {
                            a.ChainEnd().TreePrint(level + 1, e);
                        }
                    }
                }
            }
Beispiel #8
0
        // Set Clause to the prolog engine
        bool SetClause(PrologEngine plEngine, string code, bool reset = true,
                       string codeTitle = null)
        {
            bool error = false;

            if (reset)
            {
                plEngine.Reset();
            }

            // If no syntax error, consult the code to the prolog engine
            if (SyntaxCheck(code))
            {
                plEngine.ConsultFromString(code, codeTitle);
            }

            else
            {
                error = true;
            }

            return(!error);
        }
        static void Main(string [] args)
        {
            if (args.Length > 0) // batch processing assumed if arguments supplied
              {
            Prolog.MainForm.BatIO batIO = null;

            try
            {
              PrologEngine e = new PrologEngine (batIO = new Prolog.MainForm.BatIO ());
              e.ProcessArgs (args, true);
              Application.Exit ();

              return;
            }
            finally
            {
              if (batIO != null) batIO.Close ();
            }
              }

              Application.EnableVisualStyles ();
              Application.SetCompatibleTextRenderingDefault (false);
              Application.Run (new MainForm ());
        }
Beispiel #10
0
 public override void TreePrint(int level, PrologEngine e)
 {
     e.WriteLine("0}{1}", Spaces(2 * level), this);
 }
 public MainForm()
 {
     InitializeComponent ();
       Text = "C# Prolog -- basic Windows version";
       persistentSettings = new PrologEngine.ApplicationStorage ();
       stop = null;
       semaGetInput = new ManualResetEvent (false);
       charBuffer = new Queue<int> ();
       winIO = new WinIO (bgwExecuteQuery, semaGetInput, tbInput, charBuffer);
       bgwExecuteQuery.DoGuiAction (GuiAction.BtnsOff);
       pe = new PrologEngine (winIO);
       readMode = GuiAction.None;
 }
      public override void TreePrint (int level, PrologEngine engine)
      {
        string margin = Spaces (2 * level);

        engine.WriteLine ("{0}{1}", margin, PrologParser.LISTPATOPEN);

        BaseTerm t = ChainEnd ();

        foreach (ListPatternElem e in args)
          engine.WriteLine ("  {0}{1}", margin, e);

        engine.WriteLine ("{0}{1}", margin, PrologParser.LISTPATCLOSE);
      }
        static void Main(string [] args)
        {
            PrologEngine e = new PrologEngine ();
              // Example 1 -- the age/2 predicate is a builtin example; defined in Bootstrap.cs

              Console.WriteLine ("Example 1");
              Console.WriteLine ();

              SolutionSet ss = e.GetAllSolutions (null, "age(P,N)");

              if (ss.Success)
              {
            for (int i = 0; i < ss.Count; i++ ) // or: foreach (Solution s in ss.NextSolution)
            {
              Solution s = ss [i];
              Console.WriteLine ("Solution {0}", i+1);

              foreach (Variable v in s.NextVariable)
            Console.WriteLine (string.Format ("{0} ({1}) = {2}", v.Name, v.Type, v.Value));
            }
              }
              else
            Console.WriteLine ("Failure");

              // Example 2 -- xml generation

              Console.WriteLine ("Example 2");
              Console.WriteLine ();

              string result = e.GetAllSolutionsXml (null, null, "age(P,N)");
              Console.WriteLine (result);
              Console.WriteLine ();

              // Example 3 -- error

              Console.WriteLine ("Example 3");
              Console.WriteLine ();

              ss = e.GetAllSolutions (null, "age(P,))))))))))");

              if (ss.HasError)
            Console.WriteLine ("An error occurred: {0}", ss.ErrMsg);

              Console.WriteLine ("Press any key to exit");
              Console.ReadKey ();
        }
Beispiel #14
0
 static void SetPreferredConsoleProperties(PrologEngine e)
 {
     Console.ForegroundColor = ConsoleColor.DarkBlue;
       Console.BackgroundColor = ConsoleColor.White;
       Console.Clear (); // applies the background color to the *entire* window background
       Console.WindowWidth = 140;
       Console.WindowHeight = 60;
       Console.BufferWidth = 140;
       Console.BufferHeight = 3000;
       Console.WindowTop = 0;
       Console.WindowLeft = 0;
       // The following line prevents ^C from exiting the application
       Console.CancelKeyPress += new ConsoleCancelEventHandler (e.Console_CancelKeyPress);
 }
 public override void TreePrint(int level, PrologEngine e)
 {
     e.WriteLine("{0}{1}..{2}", Spaces(2 * level), lowBound.To <int> (), hiBound.To <int> ());
 }
Beispiel #16
0
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadXml();

            engine = new PrologEngine();
            execProlog("\"PROLOG ENGINE INITIALIZED!\".");
        }
 public override void TreePrint (int level, PrologEngine e)
 {
   e.WriteLine ("0}{1}", Spaces (2 * level), this);
 }