public ArrayVariable(string name, TermArray ta, ListTerm subscripts)
            {
                this.ta = ta;
                this.name = ta.Name;
                this.subscripts = subscripts.ArgumentsToArrayList ();

                if (this.subscripts.Count != ta.Rank)
                  IO.Error ("Wrong number of subscripts for '{0}': expected {1}, got {2}",
                name, ta.Rank, this.subscripts.Count);
            }
Esempio n. 2
0
 private void List(TerminalSet _TS, out Term term)
 {
     Term beforeBar;
       Term afterBar = null;
       ArrayList elements = null;
       terminalTable[DOT] = Atom;
       terminalTable[OP] = Atom;
       GetSymbol(new TerminalSet(LSqBracket), true, true);
       GetSymbol(new TerminalSet(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                           CutSym, LSqBracket, RSqBracket, LCuBracket, PrologString), false, true);
       if (symbol.IsMemberOf(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                      LSqBracket, LCuBracket, PrologString))
       {
     PrologTerm(new TerminalSet(RSqBracket, VBar), out beforeBar);
     elements = beforeBar.ArgumentsToArrayList(false);
     GetSymbol(new TerminalSet(RSqBracket, VBar), false, true);
     if (symbol.Terminal == VBar)
     {
       symbol.SetProcessed();
       PrologTerm(new TerminalSet(RSqBracket), out afterBar);
     }
       }
       terminalTable[DOT] = Dot;
       terminalTable[OP] = OpSym;
       GetSymbol(new TerminalSet(RSqBracket), true, true);
       if (afterBar == null) term = Term.NULLLIST; else term = afterBar;
       if (elements != null)
     for (int i = elements.Count - 1; i >= 0; i--) term = new ListTerm((Term)elements[i], term);
 }
      void AppendToRangeList (ref ListTerm RangeList, BaseTerm rangeSpecVar, BaseTerm t, ref BaseTerm tail) // append t to RangeList
      {
        if (rangeSpecVar == null) return; // no point in constructing a range last if it won't be bound later

        if (RangeList == null)
        {
          RangeList = new ListTerm (t);
          tail = RangeList;
        }
        else
        {
          tail.SetArg (1, new ListTerm (t));
          tail = tail.Arg (1);
        }
      }
      // try to bind the range specification variable (if present) to the range last.
      // if the minimun or the maximum range length was a variable, then bind it to the actual length just found
      bool TryBindingRangeRelatedVars (ListPatternElem g, int rangeLength, ListTerm RangeList, VarStack varStack)
      {
        if (g.MinLenTerm.IsVar)
          g.MinLenTerm.Unify (new DecimalTerm (rangeLength), varStack);

        if (g.MaxLenTerm.IsVar)
          g.MaxLenTerm.Unify (new DecimalTerm (rangeLength), varStack);

        if (g.RangeBindVar != null)
        {
          if (RangeList == null) RangeList = ListTerm.EMPTYLIST;

          if (!g.RangeBindVar.Unify (RangeList, varStack))
            return false; // alas, the same range var was apparently used & bound earlier in the pattern
        }

        return true;
      }
      private AltLoopStatus TryOneAlternative (int ip, VarStack varStack, ListPatternElem e, int k,
        int marker, ListTerm RangeList, int i, BaseTerm t, ref bool negSearchSucceeded, BaseTerm searchTerm)
      {
        bool unified = searchTerm.Unify (t, varStack);

        if (e.IsNegSearch) // none of the terms in the inner loop may match. ~(a | b | c) = ~a & ~b & ~c
        {
          if (unified) // ... no point in investigating the other alternatives if one does
          {
            negSearchSucceeded = false;

            return AltLoopStatus.Break; // don't try the other alternatives
          }

          return AltLoopStatus.TryNextDown; // non of the downranges matches may lead to a success
        }
        else
        {
          if (unified &&                                                 // we found a match. Unify, and
              TryBindingAltListVarToMatch (e.AltListBindVar, t, varStack) && // bind the AltListBindVar to the match
              TryBindingRangeRelatedVars (e, i, RangeList, varStack))        // bind the range to the range variables
          {
            if (ip == pattern.Length - 1) // this was the last pattern element
            {
              if (k == target.Count - 1) // both pattern and target exhausted
                return AltLoopStatus.MatchFound;
            }
            else if (UnifyTailEx (ip + 1, k + 1, varStack)) // now deal with the rest
              return AltLoopStatus.MatchFound;
          }

          // if we arrive here, it was not possible to ...
          // (1) ... unify the range's SearchTerm with the target element, or
          // (2) ... unify the range variable with the range last, or
          // (3) ... successfully process the rest of the pattern and target
          // Now unbind and try matching with the next target element
          BaseTerm.UnbindToMarker (varStack, marker);

          return AltLoopStatus.TryNextDown; // try the next downrange match
        }
      }
            // ToTerm results in term xml( Pre, Element, Post), where Pre and Post are lists with comments
            // and/or processing instructions that come before/after the top-level XML element.
            public BaseTerm ToTerm()
            {
                BaseTerm pre = ListTerm.EMPTYLIST;
                BaseTerm post = ListTerm.EMPTYLIST;
                BaseTerm t = null;
                Node topEl = null;

                foreach (Node n in childNodes) // array was constructed in reverse order, so top-level XML-element is entry 0.
                {
                  switch (n.type)
                  {
                case XmlNodeType.Element:
                  topEl = n;
                  break;
                case XmlNodeType.Comment:
                  t = new CompoundTerm (COMMENT, new StringTerm (n.Text));

                  if (topEl == null)
                post = new ListTerm (t, post);
                  else
                pre = new ListTerm (t, pre);

                  break;
                case XmlNodeType.ProcessingInstruction:
                  t = new CompoundTerm (INSTRUCTIONS, new AtomTerm (n.name.ToAtom ()),
                    new AtomTerm (n.text.Trim ()));
                  if (topEl == null)
                post = new ListTerm (t, post);
                  else
                pre = new ListTerm (t, pre);

                  break;
                  }
                }

                BaseTerm xmlDecl = ListTerm.EMPTYLIST;

                foreach (KeyValuePair<string, string> kv in Attributes) // XML Declaration (acually a PI) was stored in Attributes
                {
                  BaseTerm pair = new OperatorTerm (EqualOpDescr, new AtomTerm (kv.Key), new AtomTerm (kv.Value));
                  xmlDecl = new ListTerm (pair, xmlDecl); // [pre, arg2, ...]
                }

                if (!xmlDecl.IsEmptyList) // enhance term with XML Declaration
                {
                  xmlDecl = new CompoundTerm (XMLDECL, xmlDecl);
                  pre = new ListTerm (xmlDecl, pre);
                }

                BaseTerm content = ToTermEx (topEl); // Now process top-level Element

                return new CompoundTerm (XMLDOCUMENT, new BaseTerm [] { pre, content, post });
            }
            static BaseTerm ToTermEx(Node root)
            {
                BaseTerm [] args = new BaseTerm [3];
                #if fullyTagged
                args [0] = new AtomTerm (root.TagName.ToAtom ());
                #else
                string tagName = root.TagName.ToAtom ();
                #endif
                args [1] = ListTerm.EMPTYLIST;
                Decimal d;

                foreach (KeyValuePair<string, string> kv in root.Attributes) // XML Declaration
                {
                  BaseTerm pair;

                  if (Decimal.TryParse (kv.Value, styleAllowDecPnt, Utils.CIC, out d))
                pair =  new OperatorTerm (EqualOpDescr, new AtomTerm (kv.Key), new DecimalTerm (d));
                  else
                pair =  new OperatorTerm (EqualOpDescr, new AtomTerm (kv.Key), new StringTerm (kv.Value));

                  args [1] = new ListTerm (pair, args [1]);
                }

                args [2] = ListTerm.EMPTYLIST;

                if (root.ChildNodes.Count > 0)
                {
                  foreach (Node n in root.ChildNodes)
                  {
                BaseTerm e;
                e = null;
                switch (n.type)
                {
                  case XmlNodeType.Element:
                e = ToTermEx (n);
                break;
                  case XmlNodeType.Comment:
                e = new CompoundTerm (COMMENT, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ()));
                break;
                  case XmlNodeType.Text:
                if (Decimal.TryParse (n.text, styleAllowDecPnt, Utils.CIC, out d))
                #if fullyTagged
                  e = new CompoundTerm (TEXT, new DecimalTerm (d));
                else
                  e = new CompoundTerm (TEXT, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ()));
                #else
                  e = new DecimalTerm (d);
                else
                  e = new StringTerm (n.text.Trim ().EscapeDoubleQuotes ());
                #endif
                break;
                  case XmlNodeType.CDATA:
                e = new CompoundTerm (CDATA, new StringTerm (n.text.Trim ().EscapeDoubleQuotes ()));
                break;
                  case XmlNodeType.ProcessingInstruction:
                e = new CompoundTerm ("processing_instruction", new AtomTerm (n.name.ToAtom ()),
                              new StringTerm (n.text.Trim ().EscapeDoubleQuotes ()));
                break;
                  case XmlNodeType.SignificantWhitespace:
                  case XmlNodeType.Whitespace:
                break;
Esempio n. 8
0
        public override Term ToTerm()
        {
            // list is constructed in reverse order -- nullable first, name last
              Term result = new ListTerm (new Term ("nullable", new Term (isNullable?"yes":"no"), OType.noop, 0));
              result = new ListTerm (DatatypeTerm (), result);

              return new ListTerm (new Term (Utils.MakeAtom (name)) , result); // columm name
        }
Esempio n. 9
0
        public override Term ToTerm()
        {
            Term result = new ListTerm (new Term ("direction", new Term (direction.ToString ()), OType.noop, 0));
              result = new ListTerm (DatatypeTerm (), result);

              return new ListTerm (new Term (Utils.MakeAtom (name)) , result);
        }
Esempio n. 10
0
    public Term PersistentInfo ()
    {
      Term result = Term.NULLLIST;

      for (int i = MetaDataCollection.Count - 1; i >= 0; i--)
      {
        DbDataItem di = MetaDataCollection [i];
        result = new ListTerm (di.ToTerm (), result);
      }
      return PersistentInfo (result); // wraps "table" or "procedure" around result
    }
Esempio n. 11
0
        private static Term ToTermEx(Node root)
        {
            Term[] args = new Term[3];

              if (root.Text == null || root.Text == "")
            args[0] = new Term(Utils.MakeAtom(root.TagName));
              else
            args[0] = new Term(":",
                             new Term(Utils.MakeAtomic(root.Text)),
                             new Term(Utils.MakeAtomic(root.TagName)),
                             FType.comp, OType.xfy, 600);
              args[1] = Term.NULLLIST;

              foreach (DictionaryEntry de in root.Attributes) // XML Declaration
              {
            Term pair = new Term(Parser.EQ, new Term((string)de.Key), new Term((string)de.Value, FType.text), FType.comp, OType.xfx, 700);
            args[1] = new ListTerm(pair, args[1]);
              }

              args[2] = Term.NULLLIST; // []

              if (root.ChildNodes.Count > 0)
              {
            foreach (Node n in root.ChildNodes)
            {
              Term e;
              e = null;
              switch (n.type)
              {
            case XmlNodeType.Element:
              e = ToTermEx(n);
              break;
            case XmlNodeType.Comment:
              e = new Term("comment", new Term(n.text.Trim(), FType.text), OType.noop, 0);
              break;
            case XmlNodeType.Text:
              e = new Term("text", new Term(n.text.Trim(), FType.text), OType.noop, 0);
              break;
            case XmlNodeType.CDATA:
              e = new Term("cdata", new Term(n.text.Trim(), FType.text), OType.noop, 0);
              break;
            case XmlNodeType.ProcessingInstruction:
              e = new Term("instructions", new Term(Utils.MakeAtomic(n.name)),
                                            new Term(n.text.Trim(), FType.text), FType.comp, OType.noop, 0);
              break;
            case XmlNodeType.SignificantWhitespace:
            case XmlNodeType.Whitespace:
              break;
            default:
              break;
              }
              if (e != null) args[2] = new ListTerm(e, args[2]);
            }
              }
              return new Term("element", args);
        }
Esempio n. 12
0
        // ToTerm results in term xml( Pre, Element, Post), where Pre and Post are lists with comments
        // and/or processing instructions that come before/after the top-level XML element.
        public Term ToTerm()
        {
            Term pre = Term.NULLLIST;
              Term post = Term.NULLLIST;
              Term t = null;
              Node topEl = null;

              foreach (Node n in childNodes) // array was constructed in reverse order, so top-level XML-element is entry 0.
              {
            switch (n.type)
            {
              case XmlNodeType.Element:
            topEl = n;
            break;
              case XmlNodeType.Comment:
            t = new Term("comment", new Term(n.Text, FType.text), OType.noop, 0);
            if (topEl == null) post = new ListTerm(t, post); else pre = new ListTerm(t, pre);
            break;
              case XmlNodeType.ProcessingInstruction:
            t = new Term("instructions", new Term(Utils.MakeAtomic(n.name)),
                                            new Term(n.text.Trim(), FType.text), FType.comp, OType.noop, 0);
            if (topEl == null) post = new ListTerm(t, post); else pre = new ListTerm(t, pre);
            break;
            }
              }

              Term xmlDecl = Term.NULLLIST;

              foreach (DictionaryEntry de in Attributes) // XML Declaration (acually a PI) was stored in Attributes
              {
            Term pair = new Term(Parser.EQ, new Term((string)de.Key), new Term((string)de.Value, FType.text), FType.comp, OType.xfx, 700);
            xmlDecl = new ListTerm(pair, xmlDecl); // [pre, arg2, ...]
              }

              if (xmlDecl != Term.NULLLIST) // enhance list with XML Declaration
              {
            xmlDecl = new Term("xmldecl", xmlDecl, OType.noop, 0);
            pre = new ListTerm(xmlDecl, pre);
              }

              Term content = ToTermEx(topEl); // Now process top-level Element

              return new Term("xml", new Term[] { pre, content, post }, FType.comp, OType.noop, 0);
        }