private ExprKraken parseSimpleTerm ( ) { Token token = scanToken ( ) ; switch ( token ) { case MINUS : return new UnaryExpr ( UnaryOp . MINUS , parseSimpleTerm ( ) ) ; case LPAREN : { ExprKraken expr = parseExpr ( ) ; if ( ( token = scanToken ( ) ) != Token . RPAREN ) { throw error ( "Expected ')' at '{0}'" , token ) ; } return expr ; } case IDENTIFIER : { String name = _lexeme ; if ( ( token = peekToken ( ) ) == Token . DOT ) { return parsePath ( name ) ; } else if ( token == Token . LPAREN ) { FunExpr fun = null ; /* if (name.equalsIgnoreCase("max")) fun = new MaxExpr(); else if (name.equalsIgnoreCase("min")) fun = new MinExpr(); else if (name.equalsIgnoreCase("sum")) fun = new SumExpr(); else if (name.equalsIgnoreCase("avg")) fun = new AvgExpr(); else if (name.equalsIgnoreCase("count")) { fun = new CountExpr(); token = scanToken(); if (token == '*') { fun.addArg(new UnboundStarExpr()); } else _token = token; } else */ { String funName = ( Character . toUpperCase ( name . charAt ( 0 ) ) + name . substring ( 1 ) . toLowerCase ( Locale . ENGLISH ) ) ; funName = "com.caucho.v5.kraken.fun." + funName + "Expr" ; try { ClassLoader loader = Thread . currentThread ( ) . getContextClassLoader ( ) ; Class < ? > cl = Class . forName ( funName , false , loader ) ; fun = ( FunExpr ) cl . newInstance ( ) ; } catch ( ClassNotFoundException e ) { log . finer ( e . toString ( ) ) ; } catch ( Exception e ) { log . log ( Level . FINER , e . toString ( ) , e ) ; throw error ( e . toString ( ) ) ; } if ( fun == null ) { throw error ( L . l ( "'{0}' is an unknown function." , name ) ) ; } } scanToken ( ) ; token = peekToken ( ) ; while ( token != null && token != Token . RPAREN ) { ExprKraken arg = parseExpr ( ) ; fun . addArg ( arg ) ; token = peekToken ( ) ; if ( token == Token . COMMA ) { scanToken ( ) ; token = peekToken ( ) ; } } scanToken ( ) ; return fun ; } else { return new IdExprBuilder ( name ) ; } } case STRING : return new LiteralExpr ( _lexeme ) ; case DOUBLE : return new LiteralExpr ( Double . parseDouble ( _lexeme ) ) ; case INTEGER : return new LiteralExpr ( Long . parseLong ( _lexeme ) ) ; case LONG : return new LiteralExpr ( Long . parseLong ( _lexeme ) ) ; case NULL : return new NullExpr ( ) ; case TRUE : return new LiteralExpr ( true ) ; case FALSE : return new LiteralExpr ( false ) ; case QUESTION_MARK : ParamExpr param = new ParamExpr ( _params . size ( ) ) ; _params . add ( param ) ; return param ; default : throw error ( "unexpected term {0}" , token ) ; } }
Parses a simple term .