布尔和数学防爆pression分析器 [英] Boolean and Math Expression Parser

查看:217
本文介绍了布尔和数学防爆pression分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序,允许用户输入一个布尔EX pression。我需要评估所输入的布尔EX pression在运行时的能力,并正在寻找既解析器和EX pressoin验证。

I am writing an application that allows a user to enter a boolean expression. I need the ability to evaluate the entered boolean expression at runtime and am looking for both a parser and a expressoin validator.

解析器
解析器需要采取一个布尔EX pression为一个字符串,返回真/假。

Parser
The parser needs to take a boolean expression as a string and return true/false.

例:


string expression = "(1 == 1) && (1 > 0)";
Parser parser = new Parser();
boolean result = parser.parse(expression);  // Result should be True.

在除了处理布尔EX pressions我也需要它来处理数学运算。

In addition to handling boolean expressions I also need it to handle Math.


expression = "((1 + 1 * 2) == 1)";
result = parser.parse(expression);  // Result should be False.

验证
所以,我可以告诉用户,如果有被输入我还需要一种方法来验证语法与前pression一个问题。

Validate
So that I can tell the user if there is a problem with the expression being entered I also need a way to validate the syntax.

我的工作中使用.NET Compact Framework的C#,但如果你知道的东西写在另一种语言可能会有所帮助。

I am working in C# using the .NET Compact Framework, but if you know of something written in another language that may be helpful.

感谢您的帮助,您可以提供。 汤姆

Thanks for any help you can provide. Tom

推荐答案

http://www.antlr.org

ANTLR的语法可以被设计为允许既分析和评价。

Antlr grammars can be designed to allow for both parsing and evaluation.

下面是一个例子: HTTP://www.antlr。组织/维基/显示/ ANTLR3 / EX pression +评估

这篇关于布尔和数学防爆pression分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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