コード例 #1
0
            public int Consult(string fileName)
            {
                // string as ISO-style charcode lists or as C# strings
                consultFileStack.Push(fileName);
                consultParserStack.Push(Globals.CurrentParser);
                PrologParser parser = Globals.CurrentParser = new PrologParser(engine);

                allDiscontiguous = false;

                try
                {
                    prevIndex = null;
                    definedInCurrFile.Clear();
                    isDiscontiguous.Clear();
                    Uncacheall();
                    //Globals.ConsultModuleName = null;
                    parser.Prefix = "&program\r\n";
                    IO.Write("--- Consulting {0} ... ", fileName);
                    parser.LoadFromFile(fileName);
                    IO.WriteLine("{0} lines read", parser.LineCount);
                    InvalidateCrossRef();
                }
                finally
                {
                    Globals.CurrentParser = consultParserStack.Pop();;
                    //Globals.ConsultModuleName = null; // Currently not used
                }

                return(parser.LineCount);
            }
コード例 #2
0
            public int Consult(string fileName)
            {
                bool csharpStringsSave = engine.csharpStrings;
                // string as ISO-style charcode lists or as C# strings
                PrologParser saveCurrentParser = Globals.CurrentParser;
                PrologParser parser            = Globals.CurrentParser = new PrologParser(engine);

                allDiscontiguous = false;

                try
                {
                    prevIndex = null;
                    definedInCurrFile.Clear();
                    isDiscontiguous.Clear();
                    actionWhenUndefined.Clear();
                    Uncacheall();
                    Globals.ConsultFileName   = fileName.ToLower();
                    Globals.ConsultModuleName = null;
                    parser.Prefix             = "&program\r\n";
                    IO.Write("--- Consulting {0} ... ", fileName);
                    parser.LoadFromFile(fileName);
                    IO.WriteLine("{0} lines read", parser.LineCount);
                    InvalidateCrossRef();
                }
                finally
                {
                    Globals.ConsultFileName   = null;
                    Globals.ConsultModuleName = null;
                    Globals.CurrentParser     = saveCurrentParser;
                    engine.csharpStrings      = csharpStringsSave;
                }

                return(parser.LineCount);
            }
コード例 #3
0
            public void HandleSimpleDirective(PrologParser p, string directive, string argument, int arity)
            {
                //IO.WriteLine ("HandleSimpleDirective ({0}, {1}, {2})", directive, argument, arity);

                switch (directive)
                {
                case "workingdir":
                    ConfigSettings.SetWorkingDirectory(argument);
                    break;

                case "fail_if_undefined":
                    SetActionWhenUndefined(argument, arity, UndefAction.Fail);
                    break;

                case "cache":
                    SetCaching(argument, arity, true);
                    break;

                case "nocache":
                    SetCaching(argument, arity, false);
                    break;

                case "cacheall":
                    SetCaching(null, 0, true);
                    break;

                case "nocacheall":
                    SetCaching(null, 0, false);
                    break;

                case "stacktrace":
                    if (argument == "on")
                    {
                        engine.userSetShowStackTrace = true;
                    }
                    else if (argument == "off")
                    {
                        engine.userSetShowStackTrace = false;
                    }
                    else
                    {
                        IO.Error(":- stacktrace: illegal argument '{0}'; use 'on' or 'off' instead", argument);
                    }
                    break;

                case "initialization":
                    IO.Warning("':- initialization' directive not implemented -- ignored");
                    break;

                default:
                    IO.Error("Unknown directive ':- {0}'", directive);
                    break;
                }
            }
コード例 #4
0
ファイル: IO.cs プロジェクト: tMaxx/SpaceGuess
        BaseTerm BaseReadTermCurrentInput()
        {
            if (currentFileReader == null)
            {
                StringBuilder query = new StringBuilder();
                string        line;
                PrologParser  p = new PrologParser(this);

                bool first = true;

                while (true)
                {
                    IO.Write("|: ");

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        query.AppendLine();
                    }

                    if ((line = IO.ReadLine()) == null)
                    {
                        return(FileTerm.END_OF_FILE);
                    }

                    query.Append(line = line.Trim());

                    if (line.EndsWith("."))
                    {
                        break;
                    }
                }

                p.StreamIn = "&reading\r\n" + query.ToString(); // equal to parser ReadingSym
                BaseTerm result = p.ReadTerm;

                return((result == null) ? FileTerm.END_OF_FILE : result);
            }

            return(currentFileReader.ReadTerm());
        }
コード例 #5
0
ファイル: IO.cs プロジェクト: Thermophyl/Wissensverarbeitung
        BaseTerm BaseReadTermCurrentInput()
        {
            if (currentFileReader == null)
              {
            StringBuilder query = new StringBuilder ();
            string line;
            PrologParser p = new PrologParser (this);

            bool first = true;

            while (true)
            {
              IO.Write ("|: ");

              if (first) first = false; else query.AppendLine ();

              if ((line = IO.ReadLine ()) == null) return FileTerm.END_OF_FILE;

              query.Append (line = line.Trim ());

              if (line.EndsWith (".")) break;
            }

            p.StreamIn = "&reading\r\n" + query.ToString (); // equal to parser ReadingSym
            BaseTerm result = p.ReadTerm;

            return (result == null) ? FileTerm.END_OF_FILE : result;
              }

              return currentFileReader.ReadTerm ();
        }