sxdxfz 2016-05-26 06:06 采纳率: 0%
浏览 1359

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

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-10-04 18:35
    关注

    语句解析方法:
    已知一个单条件判断方式: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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序