Exemple #1
0
  /**
   * Parse and return a structure for a generic URL. Note that non SIP URLs are just stored as a
   * string (not parsed).
   *
   * @return URI is a URL structure for a SIP url.
   * @throws ParsException if there was a problem parsing.
   */
  public GenericURI uriReference() throws ParseException {
    if (debug) dbg_enter("uriReference");
    GenericURI retval = null;
    Vector<?> vect = lexer.peekNextToken(2);
    Token t1 = (Token) vect.elementAt(0);
    Token t2 = (Token) vect.elementAt(1);
    try {

      // System.out.println("token = "  + t1.getTokenValue());
      // System.out.println("tokenval = " + t1.getTokenType());

      if (t1.getTokenType() == TokenTypes.SIP) {
        if (t2.getTokenType() == ':') retval = sipURL();
        else throw createParseException("Expecting \':\'");
      } else if (t1.getTokenType() == TokenTypes.TEL) {
        if (t2.getTokenType() == ':') {
          retval = telURL();
        } else throw createParseException("Expecting \':\'");
      } else {
        String urlString = uricString();
        try {
          retval = new GenericURI(urlString);
        } catch (ParseException ex) {
          throw createParseException(ex.getMessage());
        }
      }
    } finally {
      if (debug) dbg_leave("uriReference");
    }
    return retval;
  }
Exemple #2
0
 private TelephoneNumber local_phone_number() throws ParseException {
   if (debug) dbg_enter("local_phone_number");
   TelephoneNumber tn = new TelephoneNumber();
   tn.setGlobal(false);
   NameValueList nv = null;
   String b = null;
   try {
     b = local_number();
     tn.setPhoneNumber(b);
     if (lexer.hasMoreChars()) {
       Token tok = this.lexer.peekNextToken();
       switch (tok.getTokenType()) {
         case SEMICOLON:
           {
             this.lexer.consume(1);
             nv = tel_parameters();
             tn.setParameters(nv);
             break;
           }
         default:
           {
             break;
           }
       }
     }
   } finally {
     if (debug) dbg_leave("local_phone_number");
   }
   return tn;
 }
Exemple #3
0
  private IFun condClause() throws Exception {
    Token token = tokenizer.nextToken();
    TokenType tokenType = token.getTokenType();
    IFun condition = null;

    if (tokenType == ELSE) {
      condition = PjBoolean.True;
    } else if (tokenType == IF || tokenType == ELIF || tokenType == WHILE) {
      tokenizer.expect(OPEN_PARENTHESIS);
      condition = expression();
      tokenizer.expect(CLOSE_PARENTHESIS);
    } else throw new Exception("unexpected token,  " + token);

    IFun trueBody = braceBody();

    if (token.getTokenType() == WHILE) return new While(condition, trueBody);
    else return new Cond(condition, trueBody, null);
  }
Exemple #4
0
  /**
   * Main function. Takes OQL query string as command line parameter and prints token stream version
   * of that query to stdout.
   *
   * @param args Pass an OQL query string on the command line.
   */
  public static void main(String args[]) {

    Hashtable tokenTypes = new Hashtable();
    tokenTypes.put(new Integer(END_OF_QUERY), "END_OF_QUERY");
    tokenTypes.put(new Integer(KEYWORD_SELECT), "KEYWORD_SELECT");
    tokenTypes.put(new Integer(IDENTIFIER), "IDENTIFIER");
    tokenTypes.put(new Integer(KEYWORD_AS), "KEYWORD_AS");
    tokenTypes.put(new Integer(COLON), "COLON");
    tokenTypes.put(new Integer(KEYWORD_FROM), "KEYWORD_FROM");
    tokenTypes.put(new Integer(KEYWORD_IN), "KEYWORD_IN");
    tokenTypes.put(new Integer(KEYWORD_WHERE), "KEYWORD_WHERE");
    tokenTypes.put(new Integer(KEYWORD_OR), "KEYWORD_OR");
    tokenTypes.put(new Integer(KEYWORD_AND), "KEYWORD_AND");
    tokenTypes.put(new Integer(EQUAL), "EQUAL");
    tokenTypes.put(new Integer(NOT_EQUAL), "NOT_EQUAL");
    tokenTypes.put(new Integer(KEYWORD_LIKE), "KEYWORD_LIKE");
    tokenTypes.put(new Integer(LT), "LT");
    tokenTypes.put(new Integer(LTE), "LTE");
    tokenTypes.put(new Integer(GT), "GT");
    tokenTypes.put(new Integer(GTE), "GTE");
    tokenTypes.put(new Integer(PLUS), "PLUS");
    tokenTypes.put(new Integer(MINUS), "MINUS");
    tokenTypes.put(new Integer(CONCAT), "CONCAT");
    tokenTypes.put(new Integer(TIMES), "TIMES");
    tokenTypes.put(new Integer(DIVIDE), "DIVIDE");
    tokenTypes.put(new Integer(KEYWORD_MOD), "KEYWORD_MOD");
    tokenTypes.put(new Integer(KEYWORD_ABS), "KEYWORD_ABS");
    tokenTypes.put(new Integer(KEYWORD_NOT), "KEYWORD_NOT");
    tokenTypes.put(new Integer(LPAREN), "LPAREN");
    tokenTypes.put(new Integer(RPAREN), "RPAREN");
    tokenTypes.put(new Integer(DOLLAR), "DOLLAR");
    tokenTypes.put(new Integer(KEYWORD_NIL), "KEYWORD_NIL");
    tokenTypes.put(new Integer(KEYWORD_UNDEFINED), "KEYWORD_UNDEFINED");
    tokenTypes.put(new Integer(BOOLEAN_LITERAL), "BOOLEAN_LITERAL");
    tokenTypes.put(new Integer(LONG_LITERAL), "LONG_LITERAL");
    tokenTypes.put(new Integer(DOUBLE_LITERAL), "DOUBLE_LITERAL");
    tokenTypes.put(new Integer(CHAR_LITERAL), "CHAR_LITERAL");
    tokenTypes.put(new Integer(STRING_LITERAL), "STRING_LITERAL");
    tokenTypes.put(new Integer(DATE_LITERAL), "DATE_LITERAL");
    tokenTypes.put(new Integer(TIME_LITERAL), "TIME_LITERAL");
    tokenTypes.put(new Integer(TIMESTAMP_LITERAL), "TIMESTAMP_LITERAL");
    tokenTypes.put(new Integer(KEYWORD_BETWEEN), "KEYWORD_BETWEEN");

    Lexer lexer = new Lexer(args[0]);
    while (lexer.hasMoreTokens()) {
      try {
        Token theToken = lexer.nextToken();
        String tokenType = (String) tokenTypes.get(new Integer(theToken.getTokenType()));
        System.out.println(tokenType + " : " + theToken.getTokenValue());
      } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace(System.out);
        break;
      }
    }
  }
  /**
   * Returns a string representation of the tree using lisp tree notation. (A, B, C, D) means a root
   * a with children B, C, and D. (A, (B, C, D), E) means A with a child B who has children C and D,
   * and another child E (of A).
   *
   * @param theTree the Tree to convert to a string
   * @param printWhat should be one of the static members NODE_TYPES or NODE_VALUES to tell the
   *     method what to write in the string.
   * @return a string as described above.
   */
  public String treeToString(final ParseTreeNode theTree, final int printWhat) {
    String retVal = "";

    Token curToken = theTree.getToken();

    if (printWhat == NODE_TYPES) {
      retVal = _tokenTypes.get(new Integer(curToken.getTokenType()));
    } else {
      retVal = curToken.getTokenValue();
    }

    if (!theTree.isLeaf()) {
      retVal = "( " + retVal;
      for (Iterator<ParseTreeNode> iter = theTree.children(); iter.hasNext(); ) {
        retVal = retVal + " , " + treeToString(iter.next(), printWhat);
      }
      retVal = retVal + " )";
    }

    return retVal;
  }