写一个解析函数: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,请教各位大神。写出文法、伪代码都可以的。

阅读 2.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题