Example #1
0
  public final boolean unify(final JIPCons params, Hashtable varsTbl) {
    JIPTerm output = params.getNth(1);
    JIPTerm term = params.getNth(2);

    // check if input is a variable
    if (output instanceof JIPVariable) {
      // try to extract the term
      if (!((JIPVariable) output).isBounded()) {
        throw new JIPInstantiationException(1);
      } else {
        // extracts the term
        output = ((JIPVariable) output).getValue();
      }
    }

    // Get the stream
    StreamInfo sinfo = JIPio.getOutputStreamInfo(output, false);

    //        String mode = sinfo.getProperties().getProperty("mode");
    //        if(!(mode.equals("mode(write)") || mode.equals("mode(append)")))
    //        	throw new JIPPermissionException("output", "stream", sinfo.getAlias());
    //        if(!sinfo.getProperties().getProperty("type").equals("type(text)"))
    //        	throw new JIPPermissionException("output", "binary_stream", sinfo.getAlias());

    OutputStream writer = JIPio.getOutputStream(sinfo.getHandle(), getJIPEngine());

    try {
      writer.write(term.toString(getJIPEngine()).getBytes(getJIPEngine().getEncoding()));
      writer.flush();
    } catch (IOException ex) {
      throw new JIPRuntimeException(JIPio.ERR_IOEXCEPTION, ex.getMessage());
    }

    return true;
  }
Example #2
0
  /**
   * Parses the term passed in the parameter and returns a JIPTerm object that wraps the
   * corresponding prolog term.<br>
   * If the string passed in the parameter doesn't contains a valid prolog term it raises a
   * JIPSyntaxErrorException.
   *
   * @param strTerm Term to be parsed. If the term doesn't end with a "dot" one is appended to it.
   * @return a new JIPTerm object.
   * @exception com.ugos.jiprolog.engine.JIPSyntaxErrorException
   */
  public final JIPTerm parseTerm(String strTerm) throws JIPSyntaxErrorException {
    try {
      final byte[] btTerm = strTerm.getBytes(getEncoding());
      final ByteArrayInputStream is = new ByteArrayInputStream(btTerm);
      PrologParser parser =
          new PrologParser(
              new ParserReader(new PushbackLineNumberInputStream(is)),
              m_opManager,
              m_engine,
              "user");

      m_singletonVars = parser.getSingletonVariables();

      final PrologObject term = parser.parseNext();

      return JIPTerm.getJIPTerm(term);
    } catch (UnsupportedEncodingException ex) {
      throw new JIPRuntimeException(ex.getMessage());
    }
  }
Example #3
0
 private JIPTerm parseNextTerm() throws JIPSyntaxErrorException {
   final PrologObject term = m_parser.parseNext();
   if (term != null) return JIPTerm.getJIPTerm(term);
   else return null;
 }