首页 > 写一个解析函数:SQL布尔表达式的求值

写一个解析函数:SQL布尔表达式的求值

编写条件语句解析方法:

已知一个单条件判断方式:boolean compareItem(String fieldName, String operation, String operValue);

实现一个SQL解析函数,要求:
支持and、or;
支持括号;
支持引号;
字段名使用前缀$标识。
输入语句如:($size >= 500 and ($type != "类 型 12 3" or 0 <= $checked)) 其中 size type checked为字段名

public class ParseCondition {
    public static void main(String[] args) throws ParseException {
        System.out.println(parse("($size >= 500 and ($type != \\"类 型 12 3\\" or 0 <= $checked))"));
    }
    public static boolean parse(String conditionStr) {
        //请编写

    }
    private static boolean compareItem(String fieldName, String operation, String operValue) {
        System.out.println(fieldName + " " + operation +  " " + operValue);
        return !operation.equals("!=");
    }
}

没学过java,请教各位大神。写出文法、伪代码都可以的。

【热门文章】
【热门文章】