java - 写一个解析函数:SQL布尔表达式的求值
阿神
阿神 2017-04-17 18:01:13
[Java讨论组]

编写条件语句解析方法:

已知一个单条件判断方式: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,请教各位大神。写出文法、伪代码都可以的。

阿神
阿神

闭关修行中......

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号