Esempio n. 1
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());
    }
  }
Esempio n. 2
0
    public JIPList getSingletonVariables() {
      Hashtable<String, Variable> svar = m_parser.getSingletonVariables();

      JIPList singletonVars = null;

      //        	Hashtable<String, JIPVariable> sjvar = new Hashtable<String, JIPVariable>();

      for (String key : svar.keySet()) {
        Variable var = svar.get(key);
        if (!var.isAnonymous())
          singletonVars =
              JIPList.create(
                  JIPFunctor.create(
                      "=",
                      JIPCons.create(
                          JIPAtom.create(var.getName()),
                          JIPCons.create(new JIPVariable(var), null))),
                  singletonVars);

        //        		sjvar.put(key, new JIPVariable(var));
      }
      if (singletonVars == null) return JIPList.NIL;
      else return singletonVars; // .reverse();
    }
Esempio n. 3
0
 public int getLineNumber() {
   return m_parser.getLineNumber();
 }
Esempio n. 4
0
 private JIPTerm parseNextTerm() throws JIPSyntaxErrorException {
   final PrologObject term = m_parser.parseNext();
   if (term != null) return JIPTerm.getJIPTerm(term);
   else return null;
 }