mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正运算符优先级别处理不当的问题
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@156 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -650,14 +650,14 @@ public class SQLExprParser extends SQLParser {
|
||||
SQLExpr rightExp;
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
rightExp = or();
|
||||
rightExp = relational();
|
||||
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp);
|
||||
} else if (lexer.token() == Token.BANGEQ) {
|
||||
lexer.nextToken();
|
||||
rightExp = or();
|
||||
rightExp = relational();
|
||||
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
@@ -731,13 +731,13 @@ public class SQLExprParser extends SQLParser {
|
||||
public SQLExpr shiftRest(SQLExpr expr) throws ParserException {
|
||||
if (lexer.token() == Token.LTLT) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = multiplicative();
|
||||
SQLExpr rightExp = additive();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.LeftShift, rightExp);
|
||||
expr = shiftRest(expr);
|
||||
} else if (lexer.token() == Token.GTGT) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = multiplicative();
|
||||
SQLExpr rightExp = additive();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.RightShift, rightExp);
|
||||
expr = shiftRest(expr);
|
||||
@@ -747,42 +747,47 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
public final SQLExpr and() throws ParserException {
|
||||
SQLExpr expr = equality();
|
||||
SQLExpr expr = relational();
|
||||
return andRest(expr);
|
||||
}
|
||||
|
||||
public final SQLExpr andRest(SQLExpr expr) throws ParserException {
|
||||
while (lexer.token() == Token.AND || lexer.token() == Token.AMPAMP) {
|
||||
if (lexer.token() == Token.AND || lexer.token() == Token.AMPAMP) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = equality();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanAnd, rightExp);
|
||||
expr = andRest(expr);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
public final SQLExpr xor() throws ParserException {
|
||||
SQLExpr expr = and();
|
||||
SQLExpr expr = relational();
|
||||
return xorRest(expr);
|
||||
}
|
||||
|
||||
public final SQLExpr xorRest(SQLExpr expr) throws ParserException {
|
||||
while (lexer.token() == Token.XOR) {
|
||||
if (lexer.token() == Token.XOR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = and();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanXor, rightExp);
|
||||
SQLExpr rightExp = equality();
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanAnd, rightExp);
|
||||
expr = xorRest(expr);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
public final SQLExpr or() throws ParserException {
|
||||
SQLExpr expr = xor();
|
||||
SQLExpr expr = and();
|
||||
return orRest(expr);
|
||||
}
|
||||
|
||||
public final SQLExpr orRest(SQLExpr expr) throws ParserException {
|
||||
while (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
SQLExpr rightExp = xor();
|
||||
SQLExpr rightExp = and();
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.BooleanOr, rightExp);
|
||||
}
|
||||
return expr;
|
||||
@@ -796,6 +801,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
public SQLExpr relationalRest(SQLExpr expr) throws ParserException {
|
||||
SQLExpr rightExp;
|
||||
|
||||
if (lexer.token() == Token.LT) {
|
||||
lexer.nextToken();
|
||||
rightExp = bitOr();
|
||||
|
||||
Reference in New Issue
Block a user