布尔查询/表达式到Concrete语法树 [英] Boolean Query / Expression to a Concrete syntax tree

查看:140
本文介绍了布尔查询/表达式到Concrete语法树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个允许布尔表达式的搜索表单,例如:foo AND bar或foo AND NOT bar。

I'm creating a search form that allows boolean expressions, like: "foo AND bar" or "foo AND NOT bar".

是否有可以将布尔表达式转换为具体语法树的PHP,Ruby或Java库?

Is there a library for PHP, Ruby or Java that can transform boolean expressions to a concrete syntax tree?

(我可以编写自己的词法分析器/解析器,但我宁愿使用经过试验和测试的东西)

(I could write my own lexer/parser, but I rather use something tried and tested)

编辑:为了澄清,我没有解析心律失常的表达。它将用于解析允许布尔运算符的全文查询。

To clarify, I'm not parsing arrhythmic expressions. It's going to be used for parsing full text queries that allow boolean operators.

推荐答案

我建议 Treetop 。这是一种为您的PEG生成解析器的minilanguage(解析表达式语法)。它比LALR语法更容易使用,并且比递归下降解析器更强大(即它可以做一些超过一个符号的前瞻)。

I recommend Treetop. It's a minilanguage that generates a parser for your PEG (Parsing Expression Grammar). It's easier to work with than a LALR grammar and more powerful than a recursive descent parser (i.e. it can do some lookaheads more than one symbol).

虽然Treetop不是这个复杂的,开始时有一些简单的例子是有帮助的。您可以在 threedaymonk的treetop示例中找到它们。

Although Treetop isn't that complex, it helps to have some simple examples to to start with. You will find them at threedaymonk's treetop examples.

这篇关于布尔查询/表达式到Concrete语法树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆